flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - handle some tricky RegExp literals
Date Thu, 09 Mar 2017 19:28:53 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop dad773a21 -> 628d3ca65


handle some tricky RegExp 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/628d3ca6
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/628d3ca6
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/628d3ca6

Branch: refs/heads/develop
Commit: 628d3ca65391645c52d76098c6e9a2155b5c77b2
Parents: dad773a
Author: Alex Harui <aharui@apache.org>
Authored: Thu Mar 9 11:28:48 2017 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Thu Mar 9 11:28:48 2017 -0800

----------------------------------------------------------------------
 .../internal/codegen/js/jx/LiteralEmitter.java  |  9 +++++
 .../js/flexjs/TestFlexJSGlobalClasses.java      | 41 ++++++++++++++++++++
 2 files changed, 50 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/628d3ca6/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 84e883a..22129d4 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
@@ -172,6 +172,15 @@ public class LiteralEmitter extends JSSubEmitter implements
             }
 
         }
+        else
+        {
+            s = s.replaceAll("\n", "\\\\u000a");
+            s = s.replaceAll("\r", "\\\\u000d");
+            s = s.replaceAll("\t", "\\\\u0009");        	
+            s = s.replaceAll(" ", "\\\\u0020");
+            s = s.replace("\u2028", "\\u2028");
+            s = s.replace("\u2029", "\\u2029");
+        }
 
         if (!isWritten)
         {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/628d3ca6/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 74b9d1e..05b318b 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
@@ -915,4 +915,45 @@ public class TestFlexJSGlobalClasses extends TestGoogGlobalClasses
         assertOut("var foreachiter0_target = a;\nfor (var foreachiter0 in foreachiter0_target.propertyNames())
\n{\nvar p = foreachiter0_target.getProperty(foreachiter0);\n\n  var /** @type {number} */
i = p.length;}\n");
     }
     
+    @Test
+    public void testRegExp_LiteralUnicode()
+    {
+        IVariableNode node = getVariable("var a:RegExp = /[\\u0065\\u0066\\u0067]/g;");
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {RegExp} */ a = /[efg]/g");
+    }
+
+    @Test
+    public void testRegExp_LiteralComplex1()
+    {
+        IVariableNode node = getVariable("var a:RegExp = /[\\u0009\\u000a\\u000d]/g;");
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {RegExp} */ a = /[\\u0009\\u000a\\u000d]/g");
+    }
+
+    @Test
+    public void testRegExp_LiteralComplex2()
+    {
+        IVariableNode node = getVariable("var a:RegExp = /\\u2028/;");
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {RegExp} */ a = /\\u2028/");
+    }
+
+    @Test
+    public void testRegExp_LiteralComplex3()
+    {
+        IVariableNode node = getVariable("var a:RegExp = /\\u000A|\\u000D\\u000A?/g;");
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {RegExp} */ a = /\\u000a|\\u000d\\u000a?/g");
+    }
+
+    @Test
+    public void testRegExp_LiteralComplex4()
+    {
+        IVariableNode node = getVariable("var a:RegExp = /[^\\u0009\\u000a\\u000d\\u0020]/g;");
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {RegExp} */ a = /[^\\u0009\\u000a\\u000d\\u0020]/g");
+    }
+
+    
 }


Mime
View raw message