You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2021/09/09 17:27:16 UTC

[royale-compiler] branch develop updated: JSRoyaleEmitter: don't emit the namespace for namespace access expressions because the identifier emitter will handle that

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 6ef095b  JSRoyaleEmitter: don't emit the namespace for namespace access expressions because the identifier emitter will handle that
6ef095b is described below

commit 6ef095b1354bc0de26b4cc50cfa5790191783e22
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Sep 9 10:27:01 2021 -0700

    JSRoyaleEmitter: don't emit the namespace for namespace access expressions because the identifier emitter will handle that
    
    It was emitting weird code like ns.this.ns_identifier instead of this.ns_identifier
---
 .../codegen/js/royale/JSRoyaleEmitter.java         |  8 ++++++
 .../codegen/js/royale/TestRoyaleExpressions.java   | 29 ++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java
index 8906935..49bdf23 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/royale/JSRoyaleEmitter.java
@@ -1591,6 +1591,14 @@ public class JSRoyaleEmitter extends JSGoogEmitter implements IJSRoyaleEmitter
         }
 
     }
+
+    @Override
+    public void emitNamespaceAccessExpression(
+            INamespaceAccessExpressionNode node)
+    {
+        // the namespace will be handled by the emitter for the right operand
+        getWalker().walk(node.getRightOperandNode());
+    }
     
 	boolean isGoogProvided(String className)
 	{
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java
index 1744619..8f7ba31 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/js/royale/TestRoyaleExpressions.java
@@ -37,6 +37,7 @@ import org.apache.royale.compiler.tree.as.IFileNode;
 import org.apache.royale.compiler.tree.as.IFunctionCallNode;
 import org.apache.royale.compiler.tree.as.IFunctionNode;
 import org.apache.royale.compiler.tree.as.IMemberAccessExpressionNode;
+import org.apache.royale.compiler.tree.as.INamespaceAccessExpressionNode;
 import org.apache.royale.compiler.tree.as.IReturnNode;
 import org.apache.royale.compiler.tree.as.IVariableNode;
 import org.junit.Ignore;
@@ -2162,6 +2163,34 @@ public class TestRoyaleExpressions extends TestGoogExpressions
         assertOut("a(b.getMonth())");
     }
 
+    @Override
+    @Test
+    public void testVisitBinaryOperator_NamespaceAccess_1()
+    {
+        INamespaceAccessExpressionNode node = getNamespaceAccessExpressionNode("a::b");
+        asBlockWalker.visitNamespaceAccessExpression(node);
+        //skips the namespace because that is handled by the identifier emitter
+        assertOut("b");
+    }
+
+    @Override
+    @Test
+    public void testVisitBinaryOperator_NamespaceAccess_2()
+    {
+        INamespaceAccessExpressionNode node = getNamespaceAccessExpressionNode("a::b::c");
+        asBlockWalker.visitNamespaceAccessExpression(node);
+        //skips the namespaces because that is handled by the identifier emitter
+        assertOut("c");
+    }
+
+    @Test
+    public void testVisitBinaryOperator_NamespaceAccess_3()
+    {
+        IFunctionNode node = getMethodWithPackage("import custom.custom_namespace;custom_namespace var b:String;function foo(){custom_namespace::b;}");
+        asBlockWalker.visitFunction(node);
+        assertOut("foo.bar.RoyaleTest_A.prototype.foo = function() {\n  this.http_$$ns_apache_org$2017$custom$namespace__b;\n}");
+    }
+
     protected IBackend createBackend()
     {
         return new RoyaleBackend();