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 2013/05/01 21:03:47 UTC

[1/3] git commit: [flex-falcon] - Fix casts of getters, and newlines in string literals

Updated Branches:
  refs/heads/develop 444371793 -> d80c98572


Fix casts of getters, and newlines in string 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/14a3e9aa
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/14a3e9aa
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/14a3e9aa

Branch: refs/heads/develop
Commit: 14a3e9aaac6f7963bd2a7552c13c60b1f19906bd
Parents: 4443717
Author: Alex Harui <ah...@apache.org>
Authored: Tue Apr 30 15:29:49 2013 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Tue Apr 30 15:29:49 2013 -0700

----------------------------------------------------------------------
 .../codegen/js/flexjs/TestFlexJSExpressions.java   |    8 +++++
 .../codegen/js/flexjs/TestFlexJSStatements.java    |   10 ++++++
 .../flexjs/files/FlexJSTest_again_result.js        |    1 +
 .../flexjs/files/MyInitialView_result.js           |    5 ++-
 .../flexjs/files/wildcard_import_result.js         |    1 +
 .../codegen/js/flexjs/JSFlexJSEmitter.java         |   24 ++++++++++++++-
 6 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/14a3e9aa/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
index 33c5e99..bf89f94 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java
@@ -558,6 +558,14 @@ public class TestFlexJSExpressions extends TestGoogExpressions
     }
 
     @Test
+    public void testClassCastOfGetter()
+    {
+        IFunctionNode node = getMethod("function foo(){var foo:Object = FalconTest_A(bar).bar = '';}; public function get bar():Object { return this; };");
+        asBlockWalker.visitFunction(node);
+        assertOut("FalconTest_A.prototype.foo = function() {\n\tvar /** @type {Object} */ foo = this.get_bar()/** Cast to FalconTest_A */.set_bar('');\n}");
+    }
+
+    @Test
     public void testFunctionCall()
     {
         IFunctionNode node = getMethod("function foo(){bar(b).text = '';}");

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/14a3e9aa/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
index c78fa77..b919436 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
@@ -26,6 +26,7 @@ import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.tree.as.LabeledStatementNode;
 import org.apache.flex.compiler.tree.as.IFileNode;
 import org.apache.flex.compiler.tree.as.IForLoopNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.junit.Test;
 
 /**
@@ -40,6 +41,15 @@ public class TestFlexJSStatements extends TestGoogStatements
         super.setUp();
     }
     
+    @Test
+    public void testVarDeclaration_withTypeAssignedStringWithNewLine()
+    {
+        IVariableNode node = (IVariableNode) getNode("var a:String = \"\\n\"",
+                IVariableNode.class);
+        asBlockWalker.visitVariable(node);
+        assertOut("var /** @type {string} */ a = \"\\n\"");
+    }
+
     @Override
     @Test
     public void testVisitForEach_1()

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/14a3e9aa/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js b/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
index f7e4e47..0e9dc85 100644
--- a/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
@@ -9,6 +9,7 @@ goog.require('org.apache.flex.net.HTTPService');
 goog.require('org.apache.flex.net.dataConverters.LazyCollection');
 goog.require('org.apache.flex.net.JSONInputParser');
 goog.require('StockDataJSONItemConverter');
+goog.require('org.apache.flex.events.Event');
 
 /**
  * @constructor

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/14a3e9aa/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js b/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
index 5bcf47d..3e91753 100644
--- a/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
@@ -12,6 +12,9 @@ goog.require('org.apache.flex.html.staticControls.CheckBox');
 goog.require('org.apache.flex.html.staticControls.RadioButton');
 goog.require('org.apache.flex.html.staticControls.DropDownList');
 goog.require('org.apache.flex.html.staticControls.ComboBox');
+goog.require('org.apache.flex.events.CustomEvent');
+goog.require('org.apache.flex.events.Event');
+goog.require('org.apache.flex.utils.Timer');
 
 /**
  * @constructor
@@ -291,7 +294,7 @@ MyInitialView.prototype.$EH5 = function(event)
 /**
  * @this {MyInitialView}
  * @expose
- * @param {flash.events.Event} event
+ * @param {org.apache.flex.events.Event} event
  */
 MyInitialView.prototype.$EH6 = function(event)
 {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/14a3e9aa/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js b/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
index eb17f8a..9c7c4c9 100644
--- a/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
@@ -1,6 +1,7 @@
 goog.provide('wildcard_import');
 
 goog.require('org.apache.flex.core.Application');
+goog.require('org.apache.flex.html.staticControls.Button');
 
 /**
  * @constructor

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/14a3e9aa/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index a60643e..f223e91 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -68,6 +68,7 @@ import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IGetterNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.tree.as.ILanguageIdentifierNode;
+import org.apache.flex.compiler.tree.as.ILiteralNode;
 import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
 import org.apache.flex.compiler.tree.as.ISetterNode;
 import org.apache.flex.compiler.tree.as.ITypedExpressionNode;
@@ -488,7 +489,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
 
                     getWalker().walk(rightSide);
                 }
-                else
+                else if (parentNode instanceof IBinaryOperatorNode)
                 {
                     rightSide = ((IBinaryOperatorNode) parentNode)
                             .getRightOperandNode();
@@ -915,4 +916,25 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         write(JSGoogEmitterTokens.ARRAY);
     }
 
+    @Override
+    public void emitLiteral(ILiteralNode node)
+    {
+        String s = node.getValue();
+        s = s.replaceAll("\n", "__NEWLINE_PLACEHOLDER__");
+        s = s.replaceAll("\r", "__CR_PLACEHOLDER__");
+        s = s.replaceAll("\t", "__TAB_PLACEHOLDER__");
+        s = s.replaceAll("\f", "__FORMFEED_PLACEHOLDER__");
+        s = s.replaceAll("\b", "__BACKSPACE_PLACEHOLDER__");
+        s = s.replaceAll("\\\\\"", "__QUOTE_PLACEHOLDER__");
+        s = s.replaceAll("\\\\", "__ESCAPE_PLACEHOLDER__");
+        s = "\"" + s.replaceAll("\"", "\\\\\"") + "\"";
+        s = s.replaceAll("__ESCAPE_PLACEHOLDER__", "\\\\\\\\");
+        s = s.replaceAll("__QUOTE_PLACEHOLDER__", "\\\\\"");
+        s = s.replaceAll("__BACKSPACE_PLACEHOLDER__", "\\\\b");
+        s = s.replaceAll("__FORMFEED_PLACEHOLDER__", "\\\\f");
+        s = s.replaceAll("__TAB_PLACEHOLDER__", "\\\\t");
+        s = s.replaceAll("__CR_PLACEHOLDER__", "\\\\r");
+        s = s.replaceAll("__NEWLINE_PLACEHOLDER__", "\\\\n");
+        write(s);
+    }
 }


[3/3] git commit: [flex-falcon] - Fix MXMLFlexJSEmitter so it handles top tag properties on all MXML files

Posted by ah...@apache.org.
Fix MXMLFlexJSEmitter so it handles top tag properties on all MXML files


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

Branch: refs/heads/develop
Commit: d80c98572c23adf691a0e6cc35787a8363d9180d
Parents: 7bf1bda
Author: Alex Harui <ah...@apache.org>
Authored: Wed May 1 12:03:31 2013 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Wed May 1 12:03:31 2013 -0700

----------------------------------------------------------------------
 .../flexjs/files/FlexJSTest_again_result.js        |   23 --
 .../test-files/flexjs/files/MyInitialView.mxml     |    2 +-
 .../flexjs/files/MyInitialView_result.js           |   24 +--
 .../flexjs/files/wildcard_import_result.js         |   48 ---
 .../flex/compiler/internal/codegen/Emitter.java    |    3 +-
 .../mxml/flexjs/MXMLDescriptorSpecifier.java       |   22 +--
 .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java     |  224 ++++++++-------
 7 files changed, 128 insertions(+), 218 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js b/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
index 0e9dc85..dc592ed 100644
--- a/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/FlexJSTest_again_result.js
@@ -137,29 +137,6 @@ FlexJSTest_again.prototype.set_collection = function(value)
  * @this {FlexJSTest_again}
  * @return {Array} the Array of UI element descriptors.
  */
-FlexJSTest_again.prototype.get_MXMLDescriptor = function()
-{
-	if (this.mxmldd == undefined)
-	{
-		/** @type {Array} */
-		var arr = goog.base(this, 'get_MXMLDescriptor');
-		/** @type {Array} */
-		var data = [
-];
-	
-		if (arr)
-			this.mxmldd = arr.concat(data);
-		else
-			this.mxmldd = data;
-	}
-	return this.mxmldd;
-};
-
-/**
- * @override
- * @this {FlexJSTest_again}
- * @return {Array} the Array of UI element descriptors.
- */
 FlexJSTest_again.prototype.get_MXMLProperties = function()
 {
 	if (this.mxmldp == undefined)

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml b/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml
index 69fdf71..f2cc9c7 100644
--- a/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml
+++ b/compiler.jx.tests/test-files/flexjs/files/MyInitialView.mxml
@@ -69,7 +69,7 @@ limitations under the License.
 								 destinationPropertyName="text" />
 		</basic:beads>
 	</basic:Label>
-	<basic:TextButton text="Start Timer" x="100" y="75" click="startTimer()" />
+	<basic:TextButton text="Let's Start Timer" x="100" y="75" click="startTimer()" />
 	<basic:TextButton text="Stop Timer" x="100" y="100" click="timer.removeEventListener('timer', timerHandler);timer.stop()" />
 	<basic:Label id="timerLabel" x="100" y="125" />
 	

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js b/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
index 3e91753..7ac5c67 100644
--- a/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/MyInitialView_result.js
@@ -484,7 +484,7 @@ true,
 '$ID1',
 'text',
 true,
-'Start Timer',
+'Let\'s Start Timer',
 'y',
 true,
 75,
@@ -843,26 +843,4 @@ null
 	return this.mxmldd;
 };
 
-/**
- * @override
- * @this {MyInitialView}
- * @return {Array} the Array of UI element descriptors.
- */
-MyInitialView.prototype.get_MXMLProperties = function()
-{
-	if (this.mxmldp == undefined)
-	{
-		/** @type {Array} */
-		var arr = goog.base(this, 'get_MXMLProperties');
-		/** @type {Array} */
-		var data = [
-];
-	
-		if (arr)
-			this.mxmldp = arr.concat(data);
-		else
-			this.mxmldp = data;
-	}
-	return this.mxmldp;
-};
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js b/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
index 9c7c4c9..6923f67 100644
--- a/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/wildcard_import_result.js
@@ -32,52 +32,4 @@ wildcard_import.prototype.tmp = function() {
 	myButton = new org.apache.flex.html.staticControls.Button();
 };
 
-/**
- * @override
- * @this {wildcard_import}
- * @return {Array} the Array of UI element descriptors.
- */
-wildcard_import.prototype.get_MXMLDescriptor = function()
-{
-	if (this.mxmldd == undefined)
-	{
-		/** @type {Array} */
-		var arr = goog.base(this, 'get_MXMLDescriptor');
-		/** @type {Array} */
-		var data = [
-];
-	
-		if (arr)
-			this.mxmldd = arr.concat(data);
-		else
-			this.mxmldd = data;
-	}
-	return this.mxmldd;
-};
-
-/**
- * @override
- * @this {wildcard_import}
- * @return {Array} the Array of UI element descriptors.
- */
-wildcard_import.prototype.get_MXMLProperties = function()
-{
-	if (this.mxmldp == undefined)
-	{
-		/** @type {Array} */
-		var arr = goog.base(this, 'get_MXMLProperties');
-		/** @type {Array} */
-		var data = [
-0,
-0,
-0
-];
-	
-		if (arr)
-			this.mxmldp = arr.concat(data);
-		else
-			this.mxmldp = data;
-	}
-	return this.mxmldp;
-};
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
index 82d7163..c399d73 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/Emitter.java
@@ -154,7 +154,8 @@ public class Emitter implements IEmitter
     @Override
     public void indentPop()
     {
-        currentIndent--;
+        if (currentIndent > 0)
+            currentIndent--;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
index c8fd737..e4c98a5 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLDescriptorSpecifier.java
@@ -76,10 +76,10 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
     public String id;
 
     //---------------------------------
-    //    isTopNodeInMainFile
+    //    isTopNode
     //---------------------------------
 
-    public boolean isTopNodeInMainFile;
+    public boolean isTopNode;
 
     //---------------------------------
     //    isProperty
@@ -88,23 +88,11 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
     public boolean isProperty;
     
     //---------------------------------
-    //    name
-    //---------------------------------
-
-    public String name;
-
-    //---------------------------------
     //    parent
     //---------------------------------
 
     public MXMLDescriptorSpecifier parent;
 
-    //---------------------------------
-    //    value
-    //---------------------------------
-
-    public String value;
-
     //--------------------------------------------------------------------------
     //
     //    Methods
@@ -205,7 +193,7 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
     @Override
     public String output(boolean writeNewline)
     {
-        if (isTopNodeInMainFile)
+        if (isTopNode)
         {
             int count = 0;
             for (MXMLDescriptorSpecifier md : propertySpecifiers)
@@ -257,7 +245,7 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
 
             outputEventSpecifier(writeNewline);
             
-            if (!isTopNodeInMainFile)
+            if (!isTopNode)
             {
                 writeDelimiter(writeNewline);
                 
@@ -270,7 +258,7 @@ public class MXMLDescriptorSpecifier extends MXMLNodeSpecifier
                     && parent.propertySpecifiers.indexOf(this) == parent.propertySpecifiers
                             .size() - 1;
 
-            if (!isLastChild && !isTopNodeInMainFile)
+            if (!isLastChild && !isTopNode)
                 writeDelimiter(writeNewline);
         }
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/d80c9857/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
index 0f10cd8..a2bd7e3 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/MXMLFlexJSEmitter.java
@@ -58,6 +58,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     private ArrayList<MXMLDescriptorSpecifier> currentInstances;
     private ArrayList<MXMLDescriptorSpecifier> currentPropertySpecifiers;
     private ArrayList<MXMLDescriptorSpecifier> descriptorTree;
+    private MXMLDescriptorSpecifier propertiesTree;
     private ArrayList<MXMLEventSpecifier> events;
     private ArrayList<MXMLDescriptorSpecifier> instances;
     private ArrayList<MXMLScriptSpecifier> scripts;
@@ -66,7 +67,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     private int eventCounter;
     private int idCounter;
 
-    private boolean isMainFile;
+    private boolean inMXMLContent;
 
     public MXMLFlexJSEmitter(FilterWriter out)
     {
@@ -79,6 +80,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     public void emitDocument(IMXMLDocumentNode node)
     {
         descriptorTree = new ArrayList<MXMLDescriptorSpecifier>();
+        propertiesTree = new MXMLDescriptorSpecifier();
 
         events = new ArrayList<MXMLEventSpecifier>();
         instances = new ArrayList<MXMLDescriptorSpecifier>();
@@ -88,25 +90,9 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         currentInstances = new ArrayList<MXMLDescriptorSpecifier>();
         currentPropertySpecifiers = new ArrayList<MXMLDescriptorSpecifier>();
 
-        isMainFile = true;
-        IMXMLPropertySpecifierNode[] propertySpecifierNodes = node
-                .getPropertySpecifierNodes();
-        if (propertySpecifierNodes != null && propertySpecifierNodes.length > 0)
-            isMainFile = !isMXMLContentNode((IMXMLPropertySpecifierNode) node
-                    .getPropertySpecifierNodes()[0]);
-
         eventCounter = 0;
         idCounter = 0;
 
-        if (isMainFile)
-        {
-            // fake root node; the main file doesn't have 'mxmlContent' as root 
-            MXMLDescriptorSpecifier fakeRoot = new MXMLDescriptorSpecifier();
-            fakeRoot.name = "mxmlContent";
-            descriptorTree.add(fakeRoot);
-            currentInstances.add(fakeRoot);
-        }
-
         // visit MXML
         IClassDefinition cdef = node.getClassDefinition();
         IASEmitter asEmitter = ((IMXMLBlockWalker) getMXMLWalker())
@@ -124,9 +110,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
         emitHeader(node);
 
-        boolean indent = !isMainFile || propertySpecifierNodes == null;
-
-        emitClassDeclStart(cname, node, indent);
+        emitClassDeclStart(cname, node, false);
 
         emitPropertyDecls();
 
@@ -302,89 +286,94 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     protected void emitMXMLDescriptorFuncs(String cname)
     {
         // top level is 'mxmlContent', skip it...
-        if (descriptorTree.size() == 0)
-            return;
-
-        MXMLDescriptorSpecifier root = descriptorTree.get(0);
-        root.isTopNodeInMainFile = isMainFile;
-
-        writeNewline("/**");
-        writeNewline(" * @override");
-        writeNewline(" * @this {" + cname + "}");
-        writeNewline(" * @return {Array} the Array of UI element descriptors.");
-        writeNewline(" */");
-        writeNewline(cname + ".prototype.get_MXMLDescriptor = function()");
-        indentPush();
-        writeNewline("{");
-        writeNewline("if (this.mxmldd == undefined)");
-        indentPush();
-        writeNewline("{");
-        writeNewline("/** @type {Array} */");
-        writeNewline("var arr = goog.base(this, 'get_MXMLDescriptor');");
-        writeNewline("/** @type {Array} */");
-        indentPop();
-        indentPop();
-        writeNewline("var data = [");
-
-        if (!isMainFile)
+        if (descriptorTree.size() > 0)
+        {
+            MXMLDescriptorSpecifier root = descriptorTree.get(0);
+            root.isTopNode = false;
+    
+            writeNewline("/**");
+            writeNewline(" * @override");
+            writeNewline(" * @this {" + cname + "}");
+            writeNewline(" * @return {Array} the Array of UI element descriptors.");
+            writeNewline(" */");
+            writeNewline(cname + ".prototype.get_MXMLDescriptor = function()");
+            indentPush();
+            writeNewline("{");
+            writeNewline("if (this.mxmldd == undefined)");
+            indentPush();
+            writeNewline("{");
+            writeNewline("/** @type {Array} */");
+            writeNewline("var arr = goog.base(this, 'get_MXMLDescriptor');");
+            writeNewline("/** @type {Array} */");
+            indentPop();
+            indentPop();
+            writeNewline("var data = [");
+    
             writeNewline(root.output(true));
-
-        indentPush();
-        writeNewline("];");
-        indentPush();
-        writeNewline("");
-        indentPush();
-        writeNewline("if (arr)");
-        indentPop();
-        writeNewline("this.mxmldd = arr.concat(data);");
-        indentPush();
-        writeNewline("else");
-        indentPop();
-        indentPop();
-        writeNewline("this.mxmldd = data;");
-        writeNewline("}");
-        indentPop();
-        writeNewline("return this.mxmldd;");
-        writeNewline("};");
-        writeNewline();
-        writeNewline("/**");
-        writeNewline(" * @override");
-        writeNewline(" * @this {" + cname + "}");
-        writeNewline(" * @return {Array} the Array of UI element descriptors.");
-        writeNewline(" */");
-        writeNewline(cname + ".prototype.get_MXMLProperties = function()");
-        indentPush();
-        writeNewline("{");
-        writeNewline("if (this.mxmldp == undefined)");
-        indentPush();
-        writeNewline("{");
-        writeNewline("/** @type {Array} */");
-        writeNewline("var arr = goog.base(this, 'get_MXMLProperties');");
-        writeNewline("/** @type {Array} */");
-        indentPop();
-        indentPop();
-        writeNewline("var data = [");
-
-        if (isMainFile)
+    
+            indentPush();
+            writeNewline("];");
+            indentPush();
+            writeNewline("");
+            indentPush();
+            writeNewline("if (arr)");
+            indentPop();
+            writeNewline("this.mxmldd = arr.concat(data);");
+            indentPush();
+            writeNewline("else");
+            indentPop();
+            indentPop();
+            writeNewline("this.mxmldd = data;");
+            writeNewline("}");
+            indentPop();
+            writeNewline("return this.mxmldd;");
+            writeNewline("};");
+            writeNewline();
+        }
+        
+        if (propertiesTree.propertySpecifiers.size() > 0 ||
+                propertiesTree.eventSpecifiers.size() > 0)
+        {
+            writeNewline("/**");
+            writeNewline(" * @override");
+            writeNewline(" * @this {" + cname + "}");
+            writeNewline(" * @return {Array} the Array of UI element descriptors.");
+            writeNewline(" */");
+            writeNewline(cname + ".prototype.get_MXMLProperties = function()");
+            indentPush();
+            writeNewline("{");
+            writeNewline("if (this.mxmldp == undefined)");
+            indentPush();
+            writeNewline("{");
+            writeNewline("/** @type {Array} */");
+            writeNewline("var arr = goog.base(this, 'get_MXMLProperties');");
+            writeNewline("/** @type {Array} */");
+            indentPop();
+            indentPop();
+            writeNewline("var data = [");
+    
+            MXMLDescriptorSpecifier root = propertiesTree;
+            root.isTopNode = true;
             writeNewline(root.output(true));
-
-        indentPush();
-        writeNewline("];");
-        indentPush();
-        writeNewline("");
-        indentPush();
-        writeNewline("if (arr)");
-        indentPop();
-        writeNewline("this.mxmldp = arr.concat(data);");
-        indentPush();
-        writeNewline("else");
-        indentPop();
-        indentPop();
-        writeNewline("this.mxmldp = data;");
-        writeNewline("}");
-        indentPop();
-        writeNewline("return this.mxmldp;", false);
-        writeNewline("};");
+    
+            indentPush();
+            writeNewline("];");
+            indentPush();
+            writeNewline("");
+            indentPush();
+            writeNewline("if (arr)");
+            indentPop();
+            writeNewline("this.mxmldp = arr.concat(data);");
+            indentPush();
+            writeNewline("else");
+            indentPop();
+            indentPop();
+            writeNewline("this.mxmldp = data;");
+            writeNewline("}");
+            indentPop();
+            writeNewline("return this.mxmldp;", false);
+            writeNewline("};");
+        }
     }
 
     //--------------------------------------------------------------------------    
@@ -426,6 +415,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
         if (currentDescriptor != null)
             currentDescriptor.eventSpecifiers.add(eventSpecifier);
+        else  // in theory, if no currentdescriptor must be top tag event
+            propertiesTree.eventSpecifiers.add(eventSpecifier);
 
         events.add(eventSpecifier);
     }
@@ -451,8 +442,13 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
         if (currentPropertySpecifier != null)
             currentPropertySpecifier.propertySpecifiers.add(currentInstance);
-        else
+        else if (inMXMLContent)
             descriptorTree.add(currentInstance);
+        else
+        {
+            currentInstance.parent = propertiesTree;
+            propertiesTree.propertySpecifiers.add(currentInstance);
+        }
 
         instances.add(currentInstance);
 
@@ -497,10 +493,19 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         currentPropertySpecifier.name = cdef.getQualifiedName();
         currentPropertySpecifier.parent = currentInstance;
 
+        boolean oldInMXMLContent = inMXMLContent;
+        if (currentPropertySpecifier.name.equals("mxmlContent"))
+            inMXMLContent = true;
+        
         if (currentInstance != null)
             currentInstance.propertySpecifiers.add(currentPropertySpecifier);
-        else
+        else if (inMXMLContent)
             descriptorTree.add(currentPropertySpecifier);
+        else
+        {
+            currentPropertySpecifier.parent = propertiesTree;
+            propertiesTree.propertySpecifiers.add(currentPropertySpecifier);
+        }
 
         boolean bypass = cnode != null && cnode instanceof IMXMLArrayNode;
 
@@ -511,6 +516,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         getMXMLWalker().walk(cnode); // Array or Instance
 
         moveUp(bypass, false);
+        
+        inMXMLContent = oldInMXMLContent;
     }
 
     @Override
@@ -593,8 +600,15 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         if (ps.valueNeedsQuotes)
             ps.value += ASEmitterTokens.SINGLE_QUOTE.getToken();
 
-        ps.value += node.getValue().toString();
-
+        String s = node.getValue().toString();
+        if (ps.valueNeedsQuotes)
+        {
+            // escape all single quotes found within the string
+            s = s.replace(ASEmitterTokens.SINGLE_QUOTE.getToken(), 
+                    "\\" + ASEmitterTokens.SINGLE_QUOTE.getToken());
+        }
+        ps.value += s;
+        
         if (ps.valueNeedsQuotes)
             ps.value += ASEmitterTokens.SINGLE_QUOTE.getToken();
     }


[2/3] git commit: [flex-falcon] - don't try to escape regexp

Posted by ah...@apache.org.
don't try to escape regexp


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

Branch: refs/heads/develop
Commit: 7bf1bda8d2f9e9700457c882496758ac22ef8fd2
Parents: 14a3e9a
Author: Alex Harui <ah...@apache.org>
Authored: Wed May 1 12:02:49 2013 -0700
Committer: Alex Harui <ah...@apache.org>
Committed: Wed May 1 12:02:49 2013 -0700

----------------------------------------------------------------------
 .../codegen/js/flexjs/JSFlexJSEmitter.java         |   36 ++++++++-------
 1 files changed, 20 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/7bf1bda8/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index f223e91..0325d44 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -54,6 +54,7 @@ import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
 import org.apache.flex.compiler.internal.tree.as.FunctionCallNode;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.internal.tree.as.ParameterNode;
+import org.apache.flex.compiler.internal.tree.as.RegExpLiteralNode;
 import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
@@ -919,22 +920,25 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     @Override
     public void emitLiteral(ILiteralNode node)
     {
-        String s = node.getValue();
-        s = s.replaceAll("\n", "__NEWLINE_PLACEHOLDER__");
-        s = s.replaceAll("\r", "__CR_PLACEHOLDER__");
-        s = s.replaceAll("\t", "__TAB_PLACEHOLDER__");
-        s = s.replaceAll("\f", "__FORMFEED_PLACEHOLDER__");
-        s = s.replaceAll("\b", "__BACKSPACE_PLACEHOLDER__");
-        s = s.replaceAll("\\\\\"", "__QUOTE_PLACEHOLDER__");
-        s = s.replaceAll("\\\\", "__ESCAPE_PLACEHOLDER__");
-        s = "\"" + s.replaceAll("\"", "\\\\\"") + "\"";
-        s = s.replaceAll("__ESCAPE_PLACEHOLDER__", "\\\\\\\\");
-        s = s.replaceAll("__QUOTE_PLACEHOLDER__", "\\\\\"");
-        s = s.replaceAll("__BACKSPACE_PLACEHOLDER__", "\\\\b");
-        s = s.replaceAll("__FORMFEED_PLACEHOLDER__", "\\\\f");
-        s = s.replaceAll("__TAB_PLACEHOLDER__", "\\\\t");
-        s = s.replaceAll("__CR_PLACEHOLDER__", "\\\\r");
-        s = s.replaceAll("__NEWLINE_PLACEHOLDER__", "\\\\n");
+        String s = node.getValue(true);
+        if (!(node instanceof RegExpLiteralNode))
+        {
+            s = s.replaceAll("\n", "__NEWLINE_PLACEHOLDER__");
+            s = s.replaceAll("\r", "__CR_PLACEHOLDER__");
+            s = s.replaceAll("\t", "__TAB_PLACEHOLDER__");
+            s = s.replaceAll("\f", "__FORMFEED_PLACEHOLDER__");
+            s = s.replaceAll("\b", "__BACKSPACE_PLACEHOLDER__");
+            s = s.replaceAll("\\\\\"", "__QUOTE_PLACEHOLDER__");
+            s = s.replaceAll("\\\\", "__ESCAPE_PLACEHOLDER__");
+            //s = "\'" + s.replaceAll("\'", "\\\\\'") + "\'";
+            s = s.replaceAll("__ESCAPE_PLACEHOLDER__", "\\\\\\\\");
+            s = s.replaceAll("__QUOTE_PLACEHOLDER__", "\\\\\"");
+            s = s.replaceAll("__BACKSPACE_PLACEHOLDER__", "\\\\b");
+            s = s.replaceAll("__FORMFEED_PLACEHOLDER__", "\\\\f");
+            s = s.replaceAll("__TAB_PLACEHOLDER__", "\\\\t");
+            s = s.replaceAll("__CR_PLACEHOLDER__", "\\\\r");
+            s = s.replaceAll("__NEWLINE_PLACEHOLDER__", "\\\\n");
+        }
         write(s);
     }
 }