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 c947b9b0b EmitterUtils: fix E4X filter emitted to JS with wrong member 
access expression for variable or function with PACKAGE_MEMBER, FILE_MEMBER, or 
LOCAL classification
c947b9b0b is described below

commit c947b9b0bc93d80168a557370caf958a1f450707
Author: Josh Tynjala <[email protected]>
AuthorDate: Wed Jul 29 15:40:14 2026 -0700

    EmitterUtils: fix E4X filter emitted to JS with wrong member access 
expression for variable or function with PACKAGE_MEMBER, FILE_MEMBER, or LOCAL 
classification
    
    Previously, local variables were actually detected, but in kind of a 
convoluted way. After adding support for PACKAGE_MEMBER and FILE_MEMBER 
classifications, it was easy to switch to a simple comparison for LOCAL 
classification that applied to both functions and variables.
    
    Was previously emitted with a "node." prefix, like "node.localName", 
"node.packageMemberName" or "node.fileMemberName", when it should have been 
simply "localName", "packageMemberName", or "fileMemberName". The "node." 
prefix is only needed for XML members.
    
    I also tweaked some of the instanceof usage in this method to prefer 
interfaces over classes for definitions.
---
 RELEASE_NOTES.md                                   |  1 +
 .../internal/codegen/js/utils/EmitterUtils.java    | 33 +++++++++++++------
 .../codegen/js/royale/TestRoyaleExpressions.java   | 37 ++++++++++++++++++++++
 3 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 21dc79a41..183be0f6d 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -95,6 +95,7 @@ Apache Royale Compiler 1.0.0
 - compiler: Fixed race condition in populating metadata on definitions.
 - compiler: Fixed dot character in MXML namespace prefixes not being 
recognized, like `xmlns:com.example="com.example.*"`.
 - compiler: Fixed incorrect duplicate class definition error when using 
`Embed` metadata and there are no duplicates.
+- compiler: Fixed E4X filter emitted to JS with wrong member access expression 
for local, package-level, or file-level variable or function.
 - debugger: Added missing isolate ID to SWF load and unload events.
 - debugger: Fixed debugger targeting the current JDK version instead of the 
intended minimum JDK version.
 - debugger: Fixed localized messages appearing as unprocessed tokens.
diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/utils/EmitterUtils.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/utils/EmitterUtils.java
index 6f0058460..ab0cecccb 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/utils/EmitterUtils.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/utils/EmitterUtils.java
@@ -28,7 +28,10 @@ import 
org.apache.royale.compiler.constants.INamespaceConstants;
 import org.apache.royale.compiler.definitions.IClassDefinition;
 import org.apache.royale.compiler.definitions.IDefinition;
 import org.apache.royale.compiler.definitions.IFunctionDefinition;
+import org.apache.royale.compiler.definitions.IInterfaceDefinition;
+import org.apache.royale.compiler.definitions.IParameterDefinition;
 import 
org.apache.royale.compiler.definitions.IFunctionDefinition.FunctionClassification;
+import 
org.apache.royale.compiler.definitions.IVariableDefinition.VariableClassification;
 import org.apache.royale.compiler.definitions.ITypeDefinition;
 import org.apache.royale.compiler.definitions.IVariableDefinition;
 import org.apache.royale.compiler.internal.codegen.js.JSEmitterTokens;
@@ -485,19 +488,31 @@ public class EmitterUtils
 
         if (parentNode instanceof IUnaryOperatorNode)
                return false;
-        if (nodeDef instanceof ParameterDefinition)
+        else if (nodeDef instanceof IParameterDefinition)
             return false;
-        if (nodeDef instanceof InterfaceDefinition)
+        else if (nodeDef instanceof IInterfaceDefinition)
             return false;
-        if (nodeDef instanceof ClassDefinition)
+        else if (nodeDef instanceof IClassDefinition)
             return false;
-        if (nodeDef instanceof VariableDefinition)
+        else if (nodeDef instanceof IFunctionDefinition)
         {
-                       List<IVariableNode> list = model.getVars();
-                       for (IVariableNode element : list) {
-                           
if(element.getQualifiedName().equals(((IIdentifierNode)node).getName()))
-                                       return false;
-                       }
+            IFunctionDefinition funcDef = (IFunctionDefinition) nodeDef;
+            if 
(FunctionClassification.PACKAGE_MEMBER.equals(funcDef.getFunctionClassification())
+                    || 
FunctionClassification.FILE_MEMBER.equals(funcDef.getFunctionClassification())
+                    || 
FunctionClassification.LOCAL.equals(funcDef.getFunctionClassification()))
+            {
+                return false;
+            }
+        }
+        else if (nodeDef instanceof IVariableDefinition)
+        {
+            IVariableDefinition varDef = (IVariableDefinition) nodeDef;
+            if 
(VariableClassification.PACKAGE_MEMBER.equals(varDef.getVariableClassification())
+                    || 
VariableClassification.FILE_MEMBER.equals(varDef.getVariableClassification())
+                    || 
VariableClassification.LOCAL.equals(varDef.getVariableClassification()))
+            {
+                return false;
+            }
         }
         
         if (node == firstChild) 
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 4735b2008..b2eb9f25d 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
@@ -2255,6 +2255,43 @@ public class TestRoyaleExpressions extends 
TestExpressions
          asBlockWalker.visitVariable(node);
          assertOut("var /** @type {number} */ n = 
(-(p.getProperty('something'))) >> 0");
      }
+    
+    @Test
+    public void testE4XFilterWithLocalVariable()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public function foo() { var x:XML; var a:String; x.(@type == 
a); }",
+                IFunctionNode.class, WRAP_LEVEL_CLASS);
+        asBlockWalker.visitFunction(node);
+
+        assertOut("/**\n */\n" +
+                "RoyaleTest_A.prototype.foo = function() {\n" +
+                "  var /** @type {XML} */ x = null;\n" +
+                "  var /** @type {string} */ a = null;\n" +
+                "  //var /** @type {XML} */ x = null;\n" +
+                "  //var /** @type {string} */ a = null;\n" +
+                "  x.filter(function(/** @type {XML} */ node){return 
(node.attribute('type') == a)});\n" +
+                "}");
+    }
+    
+    @Test
+    public void testE4XFilterWithLocalFunction()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public function foo() { var x:XML; function a():String {}; 
x.(@type == a()); }",
+                IFunctionNode.class, WRAP_LEVEL_CLASS);
+        asBlockWalker.visitFunction(node);
+
+        assertOut("/**\n */\n" +
+                "RoyaleTest_A.prototype.foo = function() {\n" +
+                "  var self = this;\n" +
+                "  function a() {\n" +
+                "  };\n" +
+                "  var /** @type {XML} */ x = null;\n" +
+                "  //var /** @type {XML} */ x = null;\n" +
+                "  x.filter(function(/** @type {XML} */ node){return 
(node.attribute('type') == a())});\n" +
+                "}");
+    }
 
     protected IBackend createBackend()
     {

Reply via email to