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 2019/12/20 17:43:25 UTC

[royale-compiler] branch develop updated: handle bracket setting of Proxy. Should fix apache/royale-asjs#636

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


The following commit(s) were added to refs/heads/develop by this push:
     new 672282f  handle bracket setting of Proxy.  Should fix apache/royale-asjs#636
672282f is described below

commit 672282f602b613af40afe6e8ddf8ef1deb4abb0f
Author: Alex Harui <ah...@apache.org>
AuthorDate: Fri Dec 20 09:16:08 2019 -0800

    handle bracket setting of Proxy.  Should fix apache/royale-asjs#636
---
 .../codegen/js/jx/BinaryOperatorEmitter.java       | 11 ++++++++
 .../codegen/js/royale/TestRoyaleGlobalClasses.java | 30 ++++++++++++++++++++++
 2 files changed, 41 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 511c13c..ef15003 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
@@ -426,6 +426,17 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
                 	}
 
     			}
+            	else if (((JSRoyaleEmitter)getEmitter()).isProxy(dynLeft))
+            	{
+                    getWalker().walk(dynLeft);
+                    IExpressionNode rightSide = dyn.getRightOperandNode();
+                    write(".setProperty(");
+                    getWalker().walk(rightSide);
+                    write(", ");
+                    getWalker().walk(node.getRightOperandNode());
+                    write(ASEmitterTokens.PAREN_CLOSE);
+                    return;            		
+            	}
             }
             
 			if (id == ASTNodeID.Op_EqualID) {
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
index 0c95da6..054a067 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleGlobalClasses.java
@@ -1451,6 +1451,36 @@ public class TestRoyaleGlobalClasses extends TestGoogGlobalClasses
     }
     
     @Test
+    public void testProxySetBrackets()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "import custom.TestProxy; public class B {public function b() { var a:TestProxy = new TestProxy();a['foo'] = 'bar'; }}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n  var /** @type {custom.TestProxy} */ a = new custom.TestProxy();\n  a.setProperty('foo', 'bar');\n}");
+    }
+    
+    @Test
+    public void testProxySetBracketsStringVar()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "import custom.TestProxy; public class B {public function b() { var a:TestProxy = new TestProxy();var foo:String;a[foo] = 'bar'; }}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n  var /** @type {string} */ foo = null;\n  var /** @type {custom.TestProxy} */ a = new custom.TestProxy();\n  //var /** @type {string} */ foo = null;\n  a.setProperty(foo, 'bar');\n}");
+    }
+    
+    @Test
+    public void testProxySetBracketsUintVar()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "import custom.TestProxy; public class B {public function b() { var a:TestProxy = new TestProxy();var foo:uint = 0;a[foo] = 'bar'; }}",
+                IFunctionNode.class, WRAP_LEVEL_PACKAGE, true);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\nfoo.bar.B.prototype.b = function() {\n  var /** @type {custom.TestProxy} */ a = new custom.TestProxy();\n  var /** @type {number} */ foo = 0;\n  a.setProperty(foo, 'bar');\n}");
+    }
+    
+    @Test
     public void testProxyGet()
     {
         IFunctionNode node = (IFunctionNode) getNode(