flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joshtynj...@apache.org
Subject [2/4] git commit: [flex-falcon] [refs/heads/develop] - compiler-jx: better parsing of JSX whitespace in LiteralEmitter
Date Fri, 11 Nov 2016 15:25:27 GMT
compiler-jx: better parsing of JSX whitespace in LiteralEmitter


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

Branch: refs/heads/develop
Commit: 8672a9ec71db6cfa9251a21563d2f563b2bd30c9
Parents: e9a2c6a
Author: Josh Tynjala <joshtynjala@gmail.com>
Authored: Thu Nov 10 18:23:07 2016 -0800
Committer: Josh Tynjala <joshtynjala@gmail.com>
Committed: Thu Nov 10 18:23:07 2016 -0800

----------------------------------------------------------------------
 .../internal/codegen/js/jx/LiteralEmitter.java  | 13 +++++++++--
 .../codegen/js/flexjs/TestFlexJSJSX.java        | 24 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8672a9ec/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 95acce1..5892874 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
@@ -202,7 +202,6 @@ public class LiteralEmitter extends JSSubEmitter implements
                     continue;
                 }
                 String value = literalChild.getValue(true);
-                value = value.replaceAll(ASEmitterTokens.NEW_LINE.getToken(), "");
                 if (!afterOpenTag)
                 {
                     //trim the starting whitespace, unless we're inside an open
@@ -236,7 +235,17 @@ public class LiteralEmitter extends JSSubEmitter implements
                             //literal ends with an attribute that uses {} syntax
                             endNameIndex = value.length() - 1;
                         }
-                        int attributeIndex = value.indexOf(" ");
+                        int attributeIndex = -1;
+                        for (int j = 0, count = value.length(); j < count; j++)
+                        {
+                            int charAt = value.charAt(j);
+                            if (charAt == ' ' || charAt == '\t'
+                                    || charAt == '\r' || charAt == '\n')
+                            {
+                                attributeIndex = j;
+                                break;
+                            }
+                        }
                         if (attributeIndex > 0 && attributeIndex < endNameIndex)
                         {
                             //if there are attributes, the name does not end at

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/8672a9ec/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSJSX.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSJSX.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSJSX.java
index 00933ae..1ba71df 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSJSX.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSJSX.java
@@ -61,6 +61,30 @@ public class TestFlexJSJSX extends ASTestBase
     }
 
     @Test
+    public void testSelfClosingHTMLTagWithAttributeAfterNewLine()
+    {
+        IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div\nid=\"foo\"/>}");
+        asBlockWalker.visitFunction(node);
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 'foo' });\n}");
+    }
+
+    @Test
+    public void testSelfClosingHTMLTagWithAttributeAfterCarriageReturnNewLine()
+    {
+        IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div\r\nid=\"foo\"/>}");
+        asBlockWalker.visitFunction(node);
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 'foo' });\n}");
+    }
+
+    @Test
+    public void testSelfClosingHTMLTagWithAttributeAfterTab()
+    {
+        IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div\tid=\"foo\"/>}");
+        asBlockWalker.visitFunction(node);
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 'foo' });\n}");
+    }
+
+    @Test
     public void testSelfClosingHTMLTagWithMultipleAttributes()
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id=\"foo\"
className=\"bar\"/>}");


Mime
View raw message