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/04/26 21:19:32 UTC

[royale-compiler] branch develop updated: MemberAccessEmitter: fix issue where accessing (getting) a member variable from a superclass with super would fail in JS (closes #162)

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 9acc79a  MemberAccessEmitter: fix issue where accessing (getting) a member variable from a superclass with super would fail in JS (closes #162)
9acc79a is described below

commit 9acc79aa5639ae0960bf0154fb233bfb80de91da
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Apr 26 14:17:52 2021 -0700

    MemberAccessEmitter: fix issue where accessing (getting) a member variable from a superclass with super would fail in JS (closes #162)
    
    In the generated JS, super is replaced by this when accessing a variable. This fixes the error and brings parity with SWF output.
---
 .../codegen/js/jx/MemberAccessEmitter.java         | 70 ++++++++++++----------
 1 file changed, 39 insertions(+), 31 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/MemberAccessEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
index 1a18c26..fdb18a3 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/MemberAccessEmitter.java
@@ -575,37 +575,45 @@ public class MemberAccessEmitter extends JSSubEmitter implements
             {
                 getWalker().walk(node.getLeftOperandNode());
             }
-            else if (leftNode.getNodeID() == ASTNodeID.SuperID
-                    && (rightNode.getNodeID() == ASTNodeID.GetterID || (rightDef != null && rightDef instanceof AccessorDefinition)))
-            {
-                write(getEmitter().formatQualifiedName(
-                        getEmitter().getModel().getCurrentClass().getQualifiedName()));
-                write(ASEmitterTokens.MEMBER_ACCESS);
-                write(JSGoogEmitterTokens.SUPERCLASS);
-                write(ASEmitterTokens.MEMBER_ACCESS);
-                write(JSRoyaleEmitterTokens.GETTER_PREFIX);
-                if (rightDef != null)
-                    write(rightDef.getBaseName());
-                else
-                    write(((GetterNode) rightNode).getName());
-                write(ASEmitterTokens.MEMBER_ACCESS);
-                write(JSEmitterTokens.APPLY);
-                write(ASEmitterTokens.PAREN_OPEN);
-                write(ASEmitterTokens.THIS);
-                write(ASEmitterTokens.PAREN_CLOSE);
-                return false;
-            }
-            else if (leftNode.getNodeID() == ASTNodeID.SuperID
-                    && (rightDef != null && rightDef instanceof FunctionDefinition))
-            {
-                write(getEmitter().formatQualifiedName(
-                        getEmitter().getModel().getCurrentClass().getQualifiedName()));
-                write(ASEmitterTokens.MEMBER_ACCESS);
-                write(JSGoogEmitterTokens.SUPERCLASS);
-                write(ASEmitterTokens.MEMBER_ACCESS);
-                write(rightDef.getBaseName());
-                return false;
-            }
+            else
+			{
+				if (rightNode.getNodeID() == ASTNodeID.GetterID || (rightDef != null && rightDef instanceof AccessorDefinition))
+				{
+					write(getEmitter().formatQualifiedName(
+							getEmitter().getModel().getCurrentClass().getQualifiedName()));
+					write(ASEmitterTokens.MEMBER_ACCESS);
+					write(JSGoogEmitterTokens.SUPERCLASS);
+					write(ASEmitterTokens.MEMBER_ACCESS);
+					write(JSRoyaleEmitterTokens.GETTER_PREFIX);
+					if (rightDef != null)
+						write(rightDef.getBaseName());
+					else
+						write(((GetterNode) rightNode).getName());
+					write(ASEmitterTokens.MEMBER_ACCESS);
+					write(JSEmitterTokens.APPLY);
+					write(ASEmitterTokens.PAREN_OPEN);
+					write(ASEmitterTokens.THIS);
+					write(ASEmitterTokens.PAREN_CLOSE);
+					return false;
+				}
+				else if (rightDef != null && rightDef instanceof FunctionDefinition)
+				{
+					write(getEmitter().formatQualifiedName(
+							getEmitter().getModel().getCurrentClass().getQualifiedName()));
+					write(ASEmitterTokens.MEMBER_ACCESS);
+					write(JSGoogEmitterTokens.SUPERCLASS);
+					write(ASEmitterTokens.MEMBER_ACCESS);
+					write(rightDef.getBaseName());
+					return false;
+				}
+				else if (rightDef != null && rightDef instanceof VariableDefinition)
+				{
+					//for variables, replace super with this
+					startMapping(leftNode);
+					write(ASEmitterTokens.THIS);
+					endMapping(leftNode);
+				}
+			}
         }
         else
         {