flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - FLEX-34987 fix parens for ternary
Date Tue, 22 Dec 2015 06:14:26 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 34160e46f -> 3ee42de4b


FLEX-34987 fix parens for ternary


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/3ee42de4
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/3ee42de4
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/3ee42de4

Branch: refs/heads/develop
Commit: 3ee42de4bc8ffefcc8df5a09bf2739ed33db6194
Parents: 34160e4
Author: Alex Harui <aharui@apache.org>
Authored: Mon Dec 21 22:14:19 2015 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Mon Dec 21 22:14:19 2015 -0800

----------------------------------------------------------------------
 .../internal/codegen/as/TestParenthesis.java        | 11 +++++++++++
 .../compiler/internal/codegen/as/ASEmitter.java     | 16 ++++++----------
 2 files changed, 17 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3ee42de4/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/as/TestParenthesis.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/as/TestParenthesis.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/as/TestParenthesis.java
index dd6f2e5..5674dd9 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/as/TestParenthesis.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/as/TestParenthesis.java
@@ -21,6 +21,7 @@ package org.apache.flex.compiler.internal.codegen.as;
 
 import org.apache.flex.compiler.internal.test.ASTestBase;
 import org.apache.flex.compiler.tree.as.IBinaryOperatorNode;
+import org.apache.flex.compiler.tree.as.IReturnNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.junit.Test;
 
@@ -84,4 +85,14 @@ public class TestParenthesis extends ASTestBase
         asBlockWalker.visitBinaryOperator(node);
         assertOut("a = '' + 2 + '' + '' * 4");
     }
+    
+    @Test
+    public void testParentheses_Ternary()
+    {
+        IReturnNode node = (IReturnNode) getNode(
+        		"return \"a \" + (a < b ? \"<\" : \">=\") + \" b\";", IReturnNode.class);
+        asBlockWalker.visitReturn(node);
+        assertOut("return \"a \" + (a < b ? \"<\" : \">=\") + \" b\"");
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/3ee42de4/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
index 5150917..8223ee9 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/as/ASEmitter.java
@@ -74,6 +74,7 @@ import org.apache.flex.compiler.tree.as.INamespaceAccessExpressionNode;
 import org.apache.flex.compiler.tree.as.INamespaceNode;
 import org.apache.flex.compiler.tree.as.INumericLiteralNode;
 import org.apache.flex.compiler.tree.as.IObjectLiteralValuePairNode;
+import org.apache.flex.compiler.tree.as.IOperatorNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.IReturnNode;
@@ -1352,6 +1353,8 @@ public class ASEmitter implements IASEmitter, IEmitter
     @Override
     public void emitTernaryOperator(ITernaryOperatorNode node)
     {
+    	if (ASNodeUtils.hasParenOpen((IOperatorNode) node))
+    		write(ASEmitterTokens.PAREN_OPEN);
         getWalker().walk(node.getConditionalNode());
         write(ASEmitterTokens.SPACE);
         writeToken(ASEmitterTokens.TERNARY);
@@ -1359,6 +1362,8 @@ public class ASEmitter implements IASEmitter, IEmitter
         write(ASEmitterTokens.SPACE);
         writeToken(ASEmitterTokens.COLON);
         getWalker().walk(node.getRightOperandNode());
+        if (ASNodeUtils.hasParenClose((IOperatorNode) node))
+            write(ASEmitterTokens.PAREN_CLOSE);
     }
 
     @Override
@@ -1401,16 +1406,7 @@ public class ASEmitter implements IASEmitter, IEmitter
         {
             write(node.getOperator().getOperatorText());
             IExpressionNode opNode = node.getOperandNode();
-            if (opNode instanceof TernaryOperatorNode)
-            {
-                write(ASEmitterTokens.PAREN_OPEN);
-                getWalker().walk(node.getOperandNode());
-                write(ASEmitterTokens.PAREN_CLOSE);
-            }
-            else
-            {
-                getWalker().walk(node.getOperandNode());
-            }
+            getWalker().walk(node.getOperandNode());
         }
 
         else if (node.getNodeID() == ASTNodeID.Op_PostIncrID


Mime
View raw message