Fix associativity of generated comma operator in JS BE
This commit is contained in:
@@ -19,23 +19,6 @@ public final class AstUtil {
|
||||
private AstUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a sequence of expressions (using the binary sequence operator).
|
||||
*
|
||||
* @param exprs - expressions to add to sequence
|
||||
* @return a sequence of expressions.
|
||||
*/
|
||||
public static JsBinaryOperation newSequence(JsExpression... exprs) {
|
||||
if (exprs.length < 2) {
|
||||
throw new RuntimeException("newSequence expects at least two arguments");
|
||||
}
|
||||
JsExpression result = exprs[exprs.length - 1];
|
||||
for (int i = exprs.length - 2; i >= 0; i--) {
|
||||
result = new JsBinaryOperation(JsBinaryOperator.COMMA, exprs[i], result);
|
||||
}
|
||||
return (JsBinaryOperation) result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T extends JsNode> T deepCopy(@Nullable T node) {
|
||||
if (node == null) return null;
|
||||
@@ -46,9 +29,9 @@ public final class AstUtil {
|
||||
|
||||
@NotNull
|
||||
public static <T extends JsNode> List<T> deepCopy(@Nullable List<T> nodes) {
|
||||
if (nodes == null) return new SmartList<T>();
|
||||
if (nodes == null) return new SmartList<>();
|
||||
|
||||
List<T> nodesCopy = new ArrayList<T>(nodes.size());
|
||||
List<T> nodesCopy = new ArrayList<>(nodes.size());
|
||||
for (T node : nodes) {
|
||||
nodesCopy.add(deepCopy(node));
|
||||
}
|
||||
|
||||
+6
-5
@@ -16,15 +16,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.translate.operation;
|
||||
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsBlock;
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsExpression;
|
||||
import org.jetbrains.kotlin.js.backend.ast.metadata.MetadataProperties;
|
||||
import org.jetbrains.kotlin.js.util.AstUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.kotlin.js.translate.context.TemporaryVariable;
|
||||
import org.jetbrains.kotlin.js.translate.context.TranslationContext;
|
||||
import org.jetbrains.kotlin.js.translate.general.AbstractTranslator;
|
||||
@@ -35,6 +34,8 @@ import org.jetbrains.kotlin.psi.KtUnaryExpression;
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.DynamicCallsKt;
|
||||
import org.jetbrains.kotlin.types.expressions.OperatorConventions;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.jetbrains.kotlin.js.translate.reference.AccessTranslationUtils.getAccessTranslator;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.BindingUtils.getCallableDescriptorForOperationExpression;
|
||||
import static org.jetbrains.kotlin.js.translate.utils.PsiUtils.getBaseExpression;
|
||||
@@ -121,7 +122,7 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
||||
|
||||
JsExpression result;
|
||||
if (accessBlock.getStatements().size() == 2) {
|
||||
result = AstUtil.newSequence(t1.assignmentExpression(), variableReassignment, t1.reference());
|
||||
result = JsAstUtils.newSequence(Arrays.asList(t1.assignmentExpression(), variableReassignment, t1.reference()));
|
||||
}
|
||||
else {
|
||||
context().getCurrentBlock().getStatements().addAll(accessBlock.getStatements());
|
||||
|
||||
@@ -433,9 +433,9 @@ public final class JsAstUtils {
|
||||
if (expressions.size() == 1) {
|
||||
return expressions.get(0);
|
||||
}
|
||||
JsExpression result = expressions.get(expressions.size() - 1);
|
||||
for (int i = expressions.size() - 2; i >= 0; i--) {
|
||||
result = new JsBinaryOperation(JsBinaryOperator.COMMA, expressions.get(i), result);
|
||||
JsExpression result = expressions.get(0);
|
||||
for (int i = 1; i < expressions.size(); i++) {
|
||||
result = new JsBinaryOperation(JsBinaryOperator.COMMA, result, expressions.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user