This is an automated email from the ASF dual-hosted git repository. joshtynjala pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push: new 4cc6e59 BinaryOperatorEmitter: fix missing parentheses in generated JS when using Date properties that are automatically converted to function calls (closes #179) 4cc6e59 is described below commit 4cc6e59b2d4c624408027305ce2fc411875a81c8 Author: Josh Tynjala <joshtynj...@apache.org> AuthorDate: Mon Apr 26 13:45:10 2021 -0700 BinaryOperatorEmitter: fix missing parentheses in generated JS when using Date properties that are automatically converted to function calls (closes #179) --- .../compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java | 6 ++++++ .../internal/codegen/js/royale/TestRoyaleStatements.java | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java index b37e337..02c7f49 100644 --- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java +++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java @@ -702,6 +702,9 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements void specialCaseDate(IBinaryOperatorNode node, MemberAccessExpressionNode leftSide) { + if (ASNodeUtils.hasParenOpen(node)) + write(ASEmitterTokens.PAREN_OPEN); + MemberAccessExpressionNode dateNode = (MemberAccessExpressionNode)leftSide; IIdentifierNode rightSide = (IIdentifierNode)dateNode.getRightOperandNode(); String op = node.getOperator().getOperatorText(); @@ -744,5 +747,8 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements write(ASEmitterTokens.SPACE); getWalker().walk(node.getRightOperandNode()); } + + if (ASNodeUtils.hasParenOpen(node)) + write(ASEmitterTokens.PAREN_CLOSE); } } diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleStatements.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleStatements.java index 0234544..00648d5 100644 --- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleStatements.java +++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleStatements.java @@ -270,6 +270,15 @@ public class TestRoyaleStatements extends TestGoogStatements assertOut("var /** @type {number} */ a = this.b.getFullYear()"); } + @Test + public void testVarDeclaration_withTypeNumberAndAssignedDatePropertyWithRequiredParentheses() + { + IVariableNode node = (IVariableNode) getNode("function royaleTest_a():Object { var a:Number = (b.fullYear + 1) / 2; }var b:Date;", + IVariableNode.class, WRAP_LEVEL_CLASS); + asBlockWalker.visitVariable(node); + assertOut("var /** @type {number} */ a = (this.b.getFullYear() + 1) / 2"); + } + //---------------------------------- // const declaration //----------------------------------