You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ah...@apache.org on 2018/10/14 21:22:38 UTC

[royale-compiler] 02/03: handle two statements in a for loop initializer

This is an automated email from the ASF dual-hosted git repository.

aharui pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 4cbf5d925aad3fa084091cb6036a5ce488725bf8
Author: Alex Harui <ah...@apache.org>
AuthorDate: Sun Oct 14 14:21:08 2018 -0700

    handle two statements in a for loop initializer
---
 .../internal/codegen/js/goog/JSGoogEmitter.java    | 24 ++++++++++++++++++++++
 .../codegen/js/goog/TestGoogStatements.java        |  9 ++++++++
 .../codegen/js/royale/TestRoyaleStatements.java    | 10 +++++++++
 3 files changed, 43 insertions(+)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/goog/JSGoogEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/goog/JSGoogEmitter.java
index 3e7da84..d0d55e9 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/goog/JSGoogEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/goog/JSGoogEmitter.java
@@ -1160,4 +1160,28 @@ public class JSGoogEmitter extends JSEmitter implements IJSGoogEmitter
     {
         write(ASEmitterTokens.PAREN_CLOSE);
     }
+    
+    @Override
+    public void emitContainer(IContainerNode node)
+    {
+    	// saw this in a for loop with multiple initializer statements: for (var i = 0, j = 0; ...
+        int len = node.getChildCount();
+        for (int i = 0; i < len; i++)
+        {
+            IASNode child = node.getChild(i);
+            if (i == 0)
+            	getWalker().walk(child);
+            else
+            {
+            	String s = stringifyNode(child);
+            	if (s.startsWith("var "))
+            	{
+            		s = s.substring(4);
+            		write(s);
+            	}
+            }
+            if (i < len - 1)
+            	write(", ");
+        }    	
+    }
 }
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/goog/TestGoogStatements.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/goog/TestGoogStatements.java
index 4017c5c..4247a29 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/goog/TestGoogStatements.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/goog/TestGoogStatements.java
@@ -149,6 +149,15 @@ public class TestGoogStatements extends TestStatements
         assertOut("for (var /** @type {number} */ i = 0; i < len; i++)\n\tbreak;");
     }
 
+    @Test
+    public void testVisitFor_1c()
+    {
+        IForLoopNode node = (IForLoopNode) getNode(
+                "for (var i:int = 0, len:int = 10; i < len; i++) break;", IForLoopNode.class);
+        asBlockWalker.visitForLoop(node);
+        assertOut("for (var /** @type {number} */ i = 0, /** @type {number} */ len = 10; i < len; i++)\n\tbreak;");
+    }
+    
     @Override
     @Test
     public void testVisitForIn_1()
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 c00af2b..c1c0137 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
@@ -157,6 +157,16 @@ public class TestRoyaleStatements extends TestGoogStatements
 
     @Override
     @Test
+    public void testVisitFor_1c()
+    {
+        IForLoopNode node = (IForLoopNode) getNode(
+                "for (var i:int = 0, len:int = 10; i < len; i++) break;", IForLoopNode.class);
+        asBlockWalker.visitForLoop(node);
+        assertOut("for (var /** @type {number} */ i = 0, /** @type {number} */ len = 10; i < len; i++)\n  break;");
+    }
+    
+    @Override
+    @Test
     public void testVisitForIn_1()
     {
         IForLoopNode node = (IForLoopNode) getNode(