You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2016/09/14 04:41:14 UTC

[2/2] git commit: [flex-falcon] [refs/heads/develop] - FLEX-35131 try to fix xml literals with expressions

FLEX-35131 try to fix xml literals with expressions


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/c26bafd6
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/c26bafd6
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/c26bafd6

Branch: refs/heads/develop
Commit: c26bafd60afdd829bcfd0e84678cba1bc31478d4
Parents: 3ef1ef5
Author: Alex Harui <ah...@apache.org>
Authored: Tue Sep 13 21:38:37 2016 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Sep 13 21:41:07 2016 -0700

----------------------------------------------------------------------
 .../internal/codegen/js/jx/LiteralEmitter.java      | 16 ++++++++++++++--
 .../codegen/js/flexjs/TestFlexJSGlobalClasses.java  | 15 ++++++++++++++-
 2 files changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c26bafd6/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
index 6b7cfb8..1a6c154 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
@@ -30,6 +30,7 @@ import org.apache.flex.compiler.internal.tree.as.XMLLiteralNode;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.ILiteralNode;
 import org.apache.flex.compiler.tree.as.ILiteralNode.LiteralType;
+import org.apache.flex.utils.StringUtils;
 
 public class LiteralEmitter extends JSSubEmitter implements
         ISubEmitter<ILiteralNode>
@@ -64,6 +65,7 @@ public class LiteralEmitter extends JSSubEmitter implements
             	{
         			StringBuilder sb = new StringBuilder();
             		// probably contains {initializers}
+        			boolean inAttribute = false;
             		int n = xmlNode.getContentsNode().getChildCount();
             		for (int i = 0; i < n; i++)
             		{
@@ -78,11 +80,21 @@ public class LiteralEmitter extends JSSubEmitter implements
         	            	else
         	            		sb.append("'" + s + "'");
             			}
-            			else if (child instanceof IdentifierNode)
+            			else
             			{
             				s = getEmitter().stringifyNode(child);
-            				sb.append(s);
+            				if (inAttribute)
+            				{
+            					sb.append("'\"' + ");
+
+            					sb.append(s);
+            					
+            					sb.append(" + '\"'");
+            				}
+            				else
+            					sb.append(s);
             			}
+        				inAttribute = s.equals("=");
             		}
             		s = sb.toString();
             	}

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/c26bafd6/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
index fa17867..291368d 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
@@ -351,7 +351,20 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
         							 "private function test() { var a:XML = <{tagname} {attributename}={attributevalue}>{content}</{tagname}>;}",
         							 VariableNode.class, WRAP_LEVEL_CLASS);
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {XML} */ a = new XML( '<' + this.tagname + ' ' + this.attributename + '=' + this.attributevalue + '>' + this.content + '</' + this.tagname + '>')");
+        assertOut("var /** @type {XML} */ a = new XML( '<' + this.tagname + ' ' + this.attributename + '=' + '\"' + this.attributevalue + '\"' + '>' + this.content + '</' + this.tagname + '>')");
+    }
+    
+    @Test
+    public void testXMLLiteralWithTemplateExpression()
+    {
+        VariableNode node = (VariableNode)getNode("private function get tagname():String { return 'name'; };\n" +
+        							 "private function get attributename():String { return 'id'; };\n" +
+        							 "private function get attributevalue():Number { return 5; };\n" +
+        							 "private function get content():String { return 'Fred'; };\n" +
+        							 "private function test() { var a:XML = <{tagname} {attributename}={attributevalue + \" \" + attributevalue}>{content}</{tagname}>;}",
+        							 VariableNode.class, WRAP_LEVEL_CLASS);
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {XML} */ a = new XML( '<' + this.tagname + ' ' + this.attributename + '=' + '\"' + this.attributevalue + \" \" + this.attributevalue + '\"' + '>' + this.content + '</' + this.tagname + '>')");
     }
     
     @Test