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/10/03 21:12:15 UTC
[royale-compiler] 03/10: fix 2 xml cases: set attribute with a prop
of type '*' and deleting an attribute
This is an automated email from the ASF dual-hosted git repository.
aharui pushed a commit to branch webservice
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit 951824b09bd9f22c56ee526d9651fbb65cc8ade4
Author: Alex Harui <ah...@apache.org>
AuthorDate: Thu Sep 26 15:12:56 2019 -0700
fix 2 xml cases: set attribute with a prop of type '*' and deleting an attribute
---
.../internal/codegen/js/jx/BinaryOperatorEmitter.java | 4 +++-
.../internal/codegen/js/royale/JSRoyaleEmitter.java | 14 +++++++++++---
.../codegen/js/royale/TestRoyaleGlobalClasses.java | 16 ++++++++++++++++
3 files changed, 30 insertions(+), 4 deletions(-)
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 e55ed32..56c4103 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
@@ -21,6 +21,7 @@ package org.apache.royale.compiler.internal.codegen.js.jx;
import org.apache.royale.compiler.codegen.ISubEmitter;
import org.apache.royale.compiler.codegen.js.IJSEmitter;
+import org.apache.royale.compiler.constants.IASLanguageConstants.BuiltinType;
import org.apache.royale.compiler.definitions.IDefinition;
import org.apache.royale.compiler.definitions.IFunctionDefinition;
import org.apache.royale.compiler.definitions.IFunctionDefinition.FunctionClassification;
@@ -246,7 +247,8 @@ public class BinaryOperatorEmitter extends JSSubEmitter implements
{
DynamicAccessNode dyn = (DynamicAccessNode)rnode;
ITypeDefinition type = dyn.getRightOperandNode().resolveType(getProject());
- if (type.isInstanceOf("String", getProject()) || type.isInstanceOf("Object", getProject()))
+ if (type.isInstanceOf("String", getProject()) || type.isInstanceOf("Object", getProject())
+ || type == getProject().getBuiltinType(BuiltinType.ANY_TYPE))
{
String field;
if (node.getNodeID() == ASTNodeID.Op_AssignId)
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 d3a65ab..a4adfcc 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
@@ -1233,12 +1233,20 @@ public class JSRoyaleEmitter extends JSGoogEmitter implements IJSRoyaleEmitter
if (ASNodeUtils.hasParenOpen(node))
write(ASEmitterTokens.PAREN_OPEN);
+ IExpressionNode rightNode = obj.getRightOperandNode();
String s = stringifyNode(obj.getLeftOperandNode());
+ boolean needsQuotes = rightNode.getNodeID() != ASTNodeID.Op_AtID;
write(s);
- write(".removeChild('");
- s = stringifyNode(obj.getRightOperandNode());
+ write(".removeChild(");
+ if (needsQuotes)
+ write("'");
+ else
+ write(s + ".");
+ s = stringifyNode(rightNode);
write(s);
- write("')");
+ if (needsQuotes)
+ write("'");
+ write(")");
if (ASNodeUtils.hasParenClose(node))
write(ASEmitterTokens.PAREN_CLOSE);
return;
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 23d50fa..17b0438 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
@@ -948,6 +948,14 @@ public class TestRoyaleGlobalClasses extends TestGoogGlobalClasses
}
@Test
+ public void testXMLDeleteAttribute()
+ {
+ IUnaryOperatorNode node = getUnaryNode("var a:XML = new XML(\"<top attr1='cat'><child attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");delete a.@attr1;");
+ asBlockWalker.visitUnaryOperator(node);
+ assertOut("a.removeChild(a.attribute('attr1'))");
+ }
+
+ @Test
public void testXMLDeleteChain()
{
IUnaryOperatorNode node = getUnaryNode("var a:XML = new XML(\"<top attr1='cat'><child attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");delete a.child.grandchild;");
@@ -1236,6 +1244,14 @@ public class TestRoyaleGlobalClasses extends TestGoogGlobalClasses
}
@Test
+ public void testXMLSetAttributeBracketPropStar()
+ {
+ IBinaryOperatorNode node = getBinaryNode("var z:* = 'prop';var a:XML = new XML(\"<top attr1='cat'><child attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.@[z] = 'foo'");
+ asBlockWalker.visitBinaryOperator(node);
+ assertOut("a.setAttribute(z, 'foo')");
+ }
+
+ @Test
public void testXMLSetChildAttributeBracketProp()
{
IBinaryOperatorNode node = getBinaryNode("var z:String = 'prop';var a:XML = new XML(\"<top attr1='cat'><child attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\");a.child.@['attr3'] = 'foo'");