Better logic for "invoke" call.
Adapted from https://github.com/develar/kotlin/commit/a9e0a42fb1347fa8e21c86b5a073ef8a7c873da0.
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.translate.reference;
|
package org.jetbrains.k2js.translate.reference;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
import com.google.dart.compiler.backend.js.ast.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -34,7 +33,8 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.k2js.translate.reference.CallParametersResolver.resolveCallParameters;
|
import static org.jetbrains.k2js.translate.reference.CallParametersResolver.resolveCallParameters;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.*;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.assignment;
|
||||||
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.isConstructorDescriptor;
|
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.isConstructorDescriptor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -100,11 +100,14 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JsExpression invokeCall() {
|
private JsExpression invokeCall() {
|
||||||
JsInvocation callMethodInvocation = generateCallMethodInvocation();
|
JsExpression thisExpression = callParameters.getThisObject();
|
||||||
List<JsExpression> parameters = Lists.<JsExpression>newArrayList(JsLiteral.NULL);
|
if (thisExpression == null) {
|
||||||
parameters.addAll(arguments);
|
return new JsInvocation(callParameters.getFunctionReference(), arguments);
|
||||||
setArguments(callMethodInvocation, parameters);
|
}
|
||||||
return callMethodInvocation;
|
JsInvocation call = new JsInvocation(new JsNameRef("call", callParameters.getFunctionReference()));
|
||||||
|
call.getArguments().add(thisExpression);
|
||||||
|
call.getArguments().addAll(arguments);
|
||||||
|
return call;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isExpressionAsFunction() {
|
private boolean isExpressionAsFunction() {
|
||||||
@@ -199,15 +202,6 @@ public final class CallTranslator extends AbstractTranslator {
|
|||||||
return new JsInvocation(new JsNameRef("call", callParameters.getFunctionReference()), callArguments);
|
return new JsInvocation(new JsNameRef("call", callParameters.getFunctionReference()), callArguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private JsInvocation generateCallMethodInvocation() {
|
|
||||||
JsNameRef callMethodNameRef = new JsNameRef("call");
|
|
||||||
JsInvocation callMethodInvocation = new JsInvocation();
|
|
||||||
callMethodInvocation.setQualifier(callMethodNameRef);
|
|
||||||
setQualifier(callMethodInvocation, callParameters.getFunctionReference());
|
|
||||||
return callMethodInvocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("UnnecessaryLocalVariable")
|
@SuppressWarnings("UnnecessaryLocalVariable")
|
||||||
private boolean isExtensionFunction() {
|
private boolean isExtensionFunction() {
|
||||||
boolean hasReceiver = resolvedCall.getReceiverArgument().exists();
|
boolean hasReceiver = resolvedCall.getReceiverArgument().exists();
|
||||||
|
|||||||
Reference in New Issue
Block a user