flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joshtynj...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - compiler-jx: LiteralEmitter quotes all attributes on JSX if element is HTML so that Closure compiler doesn't rename them
Date Fri, 09 Dec 2016 22:32:12 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 02a1ffc55 -> 0be066f5d


compiler-jx: LiteralEmitter quotes all attributes on JSX if element is HTML so that Closure
compiler doesn't rename them


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

Branch: refs/heads/develop
Commit: 0be066f5dd214b46ae496ffe54f71febbd0f98ca
Parents: 02a1ffc
Author: Josh Tynjala <joshtynjala@gmail.com>
Authored: Fri Dec 9 14:31:08 2016 -0800
Committer: Josh Tynjala <joshtynjala@gmail.com>
Committed: Fri Dec 9 14:32:03 2016 -0800

----------------------------------------------------------------------
 .../internal/codegen/js/jx/LiteralEmitter.java  |  7 ++---
 .../codegen/js/flexjs/TestFlexJSJSX.java        | 28 ++++++++++----------
 2 files changed, 18 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0be066f5/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 454f39a..12c0925 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
@@ -331,7 +331,7 @@ public class LiteralEmitter extends JSSubEmitter implements
                     }
                     int attributesEndIndex = (selfClosing && nextTagEndIndex >
0) ? nextTagEndIndex - 1 : nextTagEndIndex;
                     String attributes = value.substring(0, attributesEndIndex);
-                    emitJSXAttributes(attributes, startsWithAttribute, endsWithAttribute);
+                    emitJSXAttributes(attributes, startsWithAttribute, endsWithAttribute,
elementStack.peek().startsWith("'"));
                     if (selfClosing)
                     {
                         //end of open tag, including attributes
@@ -364,7 +364,7 @@ public class LiteralEmitter extends JSSubEmitter implements
         }
     }
 
-    private void emitJSXAttributes(String value, boolean startsWithAttribute, boolean endsWithAttribute)
+    private void emitJSXAttributes(String value, boolean startsWithAttribute, boolean endsWithAttribute,
boolean isHTML)
     {
         int attributeCount = 0;
         while (true)
@@ -385,8 +385,9 @@ public class LiteralEmitter extends JSSubEmitter implements
             {
                 writeToken(ASEmitterTokens.BLOCK_OPEN);
             }
-            if (attributeName.indexOf('-') >= 0)
+            if (isHTML)
             {
+                attributeName = attributeName.trim();
                 emitJSXText(attributeName);
             }
             else

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/0be066f5/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 f11ba83..f3b8720 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
@@ -57,7 +57,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id=\"foo\"/>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 'foo' });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 'foo' });\n}");
     }
 
     @Test
@@ -65,7 +65,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         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}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 'foo' });\n}");
     }
 
     @Test
@@ -73,7 +73,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         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}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 'foo' });\n}");
     }
 
     @Test
@@ -81,7 +81,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         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}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 'foo' });\n}");
     }
 
     @Test
@@ -89,7 +89,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id=\"foo\"
className=\"bar\"/>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 'foo', className: 'bar' });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 'foo', 'className': 'bar' });\n}");
     }
 
     @Test
@@ -97,7 +97,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id=\'foo\'/>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 'foo' });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 'foo' });\n}");
     }
 
     @Test
@@ -105,7 +105,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id=\"'\"/>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: '\\\'' });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': '\\\'' });\n}");
     }
 
     @Test
@@ -121,7 +121,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div className=\"foo
bar\"/>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ className: 'foo bar' });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'className': 'foo bar' });\n}");
     }
 
     @Test
@@ -129,7 +129,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div className=\'foo
bar\'/>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ className: 'foo bar' });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'className': 'foo bar' });\n}");
     }
 
     @Test
@@ -137,7 +137,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id={2}/>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 2 });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 2 });\n}");
     }
 
     @Test
@@ -145,7 +145,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id={2 + 2}/>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 2 + 2 });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 2 + 2 });\n}");
     }
 
     @Test
@@ -255,7 +255,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id=\"foo\"></div>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 'foo' });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 'foo' });\n}");
     }
 
     @Test
@@ -263,7 +263,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id=\"foo\"
className=\"bar\"></div>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 'foo', className: 'bar' });\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 'foo', 'className': 'bar' });\n}");
     }
 
     @Test
@@ -271,7 +271,7 @@ public class TestFlexJSJSX extends ASTestBase
     {
         IFunctionNode node = getMethod("[JSX]\nfunction foo() {return <div id=\"foo\">Foo</div>}");
         asBlockWalker.visitFunction(node);
-        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ id: 'foo' }, 'Foo');\n}");
+        assertOut("FalconTest_A.prototype.foo = function() {\n  return React.createElement('div',
{ 'id': 'foo' }, 'Foo');\n}");
     }
 
     @Test


Mime
View raw message