flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [1/2] git commit: [flex-falcon] [refs/heads/develop] - handle multiline XML literals
Date Tue, 12 Apr 2016 16:51:14 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop b0cd32c79 -> 33821939f


handle multiline XML literals


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

Branch: refs/heads/develop
Commit: 11e53909863d82632c362d67aa37aab3d6631623
Parents: b0cd32c
Author: Alex Harui <aharui@apache.org>
Authored: Tue Apr 12 09:36:25 2016 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Apr 12 09:36:35 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/11e53909/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
index 638f71b..d219506 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSGlobalClasses.java
@@ -321,7 +321,15 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
         IVariableNode node = getVariable("var a:XML = <top attr1='cat'><child attr2='dog'><grandchild
attr3='fish'>text</grandchild></child></top>");
         asBlockWalker.visitVariable(node);
-        assertOut("var /** @type {XML} */ a = new XML( \"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\")
");
+        assertOut("var /** @type {XML} */ a = new XML( \"<top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>\")");
+    }
+    
+    @Test
+    public void testXMLLiteralMultiline()
+    {
+        IVariableNode node = getVariable("var a:XML = <top attr1='cat'>\n<child
attr2='dog'>\n<grandchild attr3='fish'>text</grandchild>\n</child>\n</top>");
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {XML} */ a = new XML( \"<top attr1='cat'>\\\n<child
attr2='dog'>\\\n<grandchild attr3='fish'>text</grandchild>\\\n</child>\\\n</top>\")");
     }
     
     @Test
@@ -334,7 +342,7 @@ 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
@@ -343,7 +351,7 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
         IFunctionCallNode node = (IFunctionCallNode)getNode("var a:XML; a.appendChild(<top
attr1='cat'><child attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>)",
         		IFunctionCallNode.class);
         asBlockWalker.visitFunctionCall(node);
-        assertOut("a.appendChild(new XML( \"<top attr1='cat'><child attr2='dog'><grandchild
attr3='fish'>text</grandchild></child></top>\") )");
+        assertOut("a.appendChild(new XML( \"<top attr1='cat'><child attr2='dog'><grandchild
attr3='fish'>text</grandchild></child></top>\"))");
     }
     
     @Test
@@ -351,7 +359,7 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
     {
     	IBinaryOperatorNode node = getBinaryNode("var a:XML = <foo />; a = <top attr1='cat'><child
attr2='dog'><grandchild attr3='fish'>text</grandchild></child></top>)");
         asBlockWalker.visitBinaryOperator(node);
-        assertOut("a = new XML( \"<top attr1='cat'><child attr2='dog'><grandchild
attr3='fish'>text</grandchild></child></top>\") ");
+        assertOut("a = new XML( \"<top attr1='cat'><child attr2='dog'><grandchild
attr3='fish'>text</grandchild></child></top>\")");
     }
     
     @Test

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/11e53909/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
index 70d2c48..068d870 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/LiteralEmitter.java
@@ -45,48 +45,50 @@ public class LiteralEmitter extends JSSubEmitter implements
     {
         boolean isWritten = false;
 
+        String newlineReplacement = "\\\\n";
         String s = node.getValue(true);
         if (!(node instanceof RegExpLiteralNode))
         {
             if (node.getLiteralType() == LiteralType.XML)
             {
-                write("new XML");
-                writeToken(ASEmitterTokens.PAREN_OPEN);
+            	newlineReplacement = "\\\\\n";
             	XMLLiteralNode xmlNode = (XMLLiteralNode)node;
             	if (xmlNode.getContentsNode().getChildCount() == 1)
             	{
 	            	if (s.contains("'"))
-	            		write("\"" + s + "\"");
+	            		s = "\"" + s + "\"";
 	            	else
-	            		write("'" + s + "'");
-	                isWritten = true;
+	            		s = "'" + s + "'";
+	            	s = "new XML( " + s + ")";
             	}
             	else
             	{
+        			StringBuilder sb = new StringBuilder();
+        			sb.append("new XML( ");
             		// probably contains {initializers}
             		int n = xmlNode.getContentsNode().getChildCount();
             		for (int i = 0; i < n; i++)
             		{
             			if (i > 0)
-            				write(" + ");
+            				sb.append(" + ");
             			IASNode child = xmlNode.getContentsNode().getChild(i);
             			if (child instanceof LiteralNode)
             			{
             				s = ((LiteralNode)child).getValue(true);
         	            	if (s.contains("'"))
-        	            		write("\"" + s + "\"");
+        	            		sb.append("\"" + s + "\"");
         	            	else
-        	            		write("'" + s + "'");
-        	                isWritten = true;
+        	            		sb.append("'" + s + "'");
             			}
             			else if (child instanceof IdentifierNode)
             			{
             				s = getEmitter().stringifyNode(child);
-            				write(s);
+            				sb.append(s);
             			}
             		}
+            		sb.append(")");
+            		s = sb.toString();
             	}
-                writeToken(ASEmitterTokens.PAREN_CLOSE);
             }
             s = s.replaceAll("\n", "__NEWLINE_PLACEHOLDER__");
             s = s.replaceAll("\r", "__CR_PLACEHOLDER__");
@@ -102,7 +104,7 @@ public class LiteralEmitter extends JSSubEmitter implements
             s = s.replaceAll("__FORMFEED_PLACEHOLDER__", "\\\\f");
             s = s.replaceAll("__TAB_PLACEHOLDER__", "\\\\t");
             s = s.replaceAll("__CR_PLACEHOLDER__", "\\\\r");
-            s = s.replaceAll("__NEWLINE_PLACEHOLDER__", "\\\\n");
+            s = s.replaceAll("__NEWLINE_PLACEHOLDER__", newlineReplacement);
             if (node.getLiteralType() == LiteralType.STRING)
             {
             	char c = s.charAt(0);


Mime
View raw message