Pass scope to the call of iifeFun only when it make sense
^KT-40689 fixed
This commit is contained in:
committed by
TeamCityServer
parent
1dbe7d12a2
commit
e98413740b
+27
-20
@@ -166,30 +166,37 @@ fun translateCall(
|
||||
// TODO: Do not create IIFE at all? (Currently there is no reliable way to create temporary variable in current scope)
|
||||
val receiverName = JsName("\$externalVarargReceiverTmp")
|
||||
val receiverRef = receiverName.makeRef()
|
||||
JsInvocation(
|
||||
// Create scope for temporary variable holding dispatch receiver
|
||||
// It is used both during method reference and passing `this` value to `apply` function.
|
||||
JsNameRef(
|
||||
"call",
|
||||
JsFunction(
|
||||
emptyScope,
|
||||
JsBlock(
|
||||
JsVars(JsVars.JsVar(receiverName, jsDispatchReceiver)),
|
||||
JsReturn(
|
||||
JsInvocation(
|
||||
JsNameRef("apply", JsNameRef(symbolName, receiverRef)),
|
||||
listOf(
|
||||
receiverRef,
|
||||
argumentsAsSingleArray
|
||||
)
|
||||
)
|
||||
val iifeFun = JsFunction(
|
||||
emptyScope,
|
||||
JsBlock(
|
||||
JsVars(JsVars.JsVar(receiverName, jsDispatchReceiver)),
|
||||
JsReturn(
|
||||
JsInvocation(
|
||||
JsNameRef("apply", JsNameRef(symbolName, receiverRef)),
|
||||
listOf(
|
||||
receiverRef,
|
||||
argumentsAsSingleArray
|
||||
)
|
||||
),
|
||||
"VarargIIFE"
|
||||
)
|
||||
)
|
||||
),
|
||||
JsThisRef()
|
||||
"VarargIIFE"
|
||||
)
|
||||
|
||||
val iifeFunHasContext = (jsDispatchReceiver as? JsNameRef)?.qualifier is JsThisRef
|
||||
if (iifeFunHasContext) {
|
||||
JsInvocation(
|
||||
// Create scope for temporary variable holding dispatch receiver
|
||||
// It is used both during method reference and passing `this` value to `apply` function.
|
||||
JsNameRef(
|
||||
"call",
|
||||
iifeFun
|
||||
),
|
||||
JsThisRef()
|
||||
)
|
||||
} else {
|
||||
JsInvocation(iifeFun)
|
||||
}
|
||||
} else {
|
||||
JsInvocation(
|
||||
JsNameRef("apply", JsNameRef(symbolName)),
|
||||
|
||||
Reference in New Issue
Block a user