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)
|
// 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 receiverName = JsName("\$externalVarargReceiverTmp")
|
||||||
val receiverRef = receiverName.makeRef()
|
val receiverRef = receiverName.makeRef()
|
||||||
JsInvocation(
|
val iifeFun = JsFunction(
|
||||||
// Create scope for temporary variable holding dispatch receiver
|
emptyScope,
|
||||||
// It is used both during method reference and passing `this` value to `apply` function.
|
JsBlock(
|
||||||
JsNameRef(
|
JsVars(JsVars.JsVar(receiverName, jsDispatchReceiver)),
|
||||||
"call",
|
JsReturn(
|
||||||
JsFunction(
|
JsInvocation(
|
||||||
emptyScope,
|
JsNameRef("apply", JsNameRef(symbolName, receiverRef)),
|
||||||
JsBlock(
|
listOf(
|
||||||
JsVars(JsVars.JsVar(receiverName, jsDispatchReceiver)),
|
receiverRef,
|
||||||
JsReturn(
|
argumentsAsSingleArray
|
||||||
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 {
|
} else {
|
||||||
JsInvocation(
|
JsInvocation(
|
||||||
JsNameRef("apply", JsNameRef(symbolName)),
|
JsNameRef("apply", JsNameRef(symbolName)),
|
||||||
|
|||||||
Reference in New Issue
Block a user