Pass scope to the call of iifeFun only when it make sense

^KT-40689 fixed
This commit is contained in:
Shagen Ogandzhanian
2021-01-09 03:02:34 +01:00
committed by TeamCityServer
parent 1dbe7d12a2
commit e98413740b
@@ -166,12 +166,7 @@ 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
// It is used both during method reference and passing `this` value to `apply` function.
JsNameRef(
"call",
JsFunction(
emptyScope, emptyScope,
JsBlock( JsBlock(
JsVars(JsVars.JsVar(receiverName, jsDispatchReceiver)), JsVars(JsVars.JsVar(receiverName, jsDispatchReceiver)),
@@ -187,9 +182,21 @@ fun translateCall(
), ),
"VarargIIFE" "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() JsThisRef()
) )
} else {
JsInvocation(iifeFun)
}
} else { } else {
JsInvocation( JsInvocation(
JsNameRef("apply", JsNameRef(symbolName)), JsNameRef("apply", JsNameRef(symbolName)),