flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [2/2] git commit: [flex-falcon] [refs/heads/develop] - emit complex variable initializers in the constructor
Date Wed, 19 Aug 2015 21:51:45 GMT
emit complex variable initializers in the constructor


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

Branch: refs/heads/develop
Commit: 20e0158902b77a35bec8f27cadde4dcc626a46c4
Parents: 57a8074
Author: Alex Harui <aharui@apache.org>
Authored: Wed Aug 19 14:51:18 2015 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Wed Aug 19 14:51:18 2015 -0700

----------------------------------------------------------------------
 .../codegen/js/flexjs/TestFlexJSClass.java      |  2 +-
 .../js/flexjs/TestFlexJSFieldMembers.java       | 51 ++++++++++++++++++--
 .../mxml/flexjs/TestFlexJSMXMLScript.java       | 19 ++++++++
 .../flexjs/files/models/MyModel_result.js       |  8 +--
 .../codegen/js/flexjs/JSFlexJSEmitter.java      |  5 ++
 .../internal/codegen/js/jx/ClassEmitter.java    | 28 +++++++++++
 .../internal/codegen/js/jx/FieldEmitter.java    |  3 +-
 .../internal/codegen/js/jx/MethodEmitter.java   |  4 ++
 .../internal/codegen/js/utils/EmitterUtils.java | 41 ++++++++++++++++
 .../codegen/mxml/flexjs/MXMLFlexJSEmitter.java  | 44 ++++++++++++++++-
 10 files changed, 196 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
index c49ab44..8dacb04 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
@@ -108,7 +108,7 @@ public class TestFlexJSClass extends TestGoogClass
     {
         IClassNode node = getClassNode("public class B {public function B() {}; public var
button:Button = new Button(); public function foo():String {return button.label;};}");
         asBlockWalker.visitClass(node);
-        String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n
* @export\n * @type {spark.components.Button}\n */\norg.apache.flex.B.prototype.button = new
spark.components.Button();\n\n\n/**\n * @export\n * @return {string}\n */\norg.apache.flex.B.prototype.foo
= function() {\n  return this.button.label;\n};";
+        String expected = "/**\n * @constructor\n */\norg.apache.flex.B = function() {\n\nthis.button
= new spark.components.Button();};\n\n\n/**\n * @export\n * @type {spark.components.Button}\n
*/\norg.apache.flex.B.prototype.button;\n\n\n/**\n * @export\n * @return {string}\n */\norg.apache.flex.B.prototype.foo
= function() {\n  return this.button.label;\n};";
         assertOut(expected);
     }
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
index c2a076f..e15eb9c 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSFieldMembers.java
@@ -22,6 +22,7 @@ package org.apache.flex.compiler.internal.codegen.js.flexjs;
 import org.apache.flex.compiler.driver.IBackend;
 import org.apache.flex.compiler.internal.codegen.js.goog.TestGoogFieldMembers;
 import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
+import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.junit.Test;
 
@@ -113,11 +114,39 @@ public class TestFlexJSFieldMembers extends TestGoogFieldMembers
     @Test
     public void testField_withNamespaceTypeValueComplex()
     {
-        IVariableNode node = getField("protected var foo:Foo = new Foo('bar', 42);");
-        asBlockWalker.visitVariable(node);
-        assertOut("/**\n * @protected\n * @type {Foo}\n */\nFalconTest_A.prototype.foo =
new Foo('bar', 42)");
+    	IClassNode node = (IClassNode) getNode("protected var foo:Foo = new Foo('bar', 42);",
+    			IClassNode.class, WRAP_LEVEL_CLASS);
+        asBlockWalker.visitClass(node);
+        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = new
Foo('bar', 42);};\n\n\n/**\n * @protected\n * @type {Foo}\n */\nFalconTest_A.prototype.foo;");
     }
 
+    @Test
+    public void testField_withTypeValueArrayLiteral()
+    {
+    	IClassNode node = (IClassNode) getNode("protected var foo:Array = [ 'foo' ]",
+        		IClassNode.class, WRAP_LEVEL_CLASS);
+        asBlockWalker.visitClass(node);
+        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = ['foo'];};\n\n\n/**\n
* @protected\n * @type {Array}\n */\nFalconTest_A.prototype.foo;");
+    }
+    
+    @Test
+    public void testField_withTypeValueObjectLiteral()
+    {
+    	IClassNode node = (IClassNode) getNode("protected var foo:Object = { 'foo': 'bar' }",
+        		IClassNode.class, WRAP_LEVEL_CLASS);
+        asBlockWalker.visitClass(node);
+        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = {'foo':'bar'};};\n\n\n/**\n
* @protected\n * @type {Object}\n */\nFalconTest_A.prototype.foo;");
+    }
+    
+    @Test
+    public void testField_withTypeValueFunctionCall()
+    {
+    	IClassNode node = (IClassNode) getNode("protected var foo:Number = parseFloat('1E2')",
+        		IClassNode.class, WRAP_LEVEL_CLASS);
+        asBlockWalker.visitClass(node);
+        assertOut("/**\n * @constructor\n */\nFalconTest_A = function() {\n\nthis.foo = parseFloat('1E2');};\n\n\n/**\n
* @protected\n * @type {number}\n */\nFalconTest_A.prototype.foo;");
+    }
+    
     @Override
     @Test
     public void testField_withList()
@@ -175,6 +204,14 @@ public class TestFlexJSFieldMembers extends TestGoogFieldMembers
     }
 
     @Test
+    public void testConstant_withComplexTypeValue()
+    {
+        IVariableNode node = getField("static const foo:Number = parseFloat('1E2');");
+        asBlockWalker.visitVariable(node);
+        assertOut("/**\n * @export\n * @const\n * @type {number}\n */\nFalconTest_A.foo =
parseFloat('1E2')");
+    }
+
+    @Test
     public void testConstant_withTypeValue_nonStatic()
     {
         IVariableNode node = getField("const foo:int = 420;");
@@ -182,6 +219,14 @@ public class TestFlexJSFieldMembers extends TestGoogFieldMembers
         assertOut("/**\n * @export\n * @const\n * @type {number}\n */\nFalconTest_A.prototype.foo
= 420");
     }
 
+    @Test
+    public void testConstant_withComplexTypeValue_nonStatic()
+    {
+        IVariableNode node = getField("const foo:Number = parseFloat('1E2');");
+        asBlockWalker.visitVariable(node);
+        assertOut("/**\n * @export\n * @const\n * @type {number}\n */\nFalconTest_A.prototype.foo
= parseFloat('1E2')");
+    }
+
     @Override
     @Test
     public void testConstant_withNamespaceTypeValue()

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
index 4a82abd..a0d6c5d 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/mxml/flexjs/TestFlexJSMXMLScript.java
@@ -48,4 +48,23 @@ public class TestFlexJSMXMLScript extends FlexJSTestBase
         assertOut(outTemplate.replaceAll("AppName", appName));
     }
 
+    @Test
+    public void testComplexInitializersInScript()
+    {
+        String code = "" + "<fx:Script><![CDATA["
+                + "    public var foo:Array = ['foo'];"
+                + "]]></fx:Script>";
+
+        IMXMLScriptNode node = (IMXMLScriptNode) getNode(code,
+                IMXMLScriptNode.class, FlexJSTestBase.WRAP_LEVEL_DOCUMENT);
+
+        IMXMLDocumentNode dnode = (IMXMLDocumentNode) node
+        	.getAncestorOfType(IMXMLDocumentNode.class);
+        ((JSFlexJSEmitter)(mxmlBlockWalker.getASEmitter())).getModel().setCurrentClass(dnode.getDefinition());
+        mxmlBlockWalker.visitDocument(dnode);
+        String appName = dnode.getQualifiedName();
+        String outTemplate = "/**\n * AppName\n *\n * @fileoverview\n *\n * @suppress {checkTypes}\n
*/\n\ngoog.provide('AppName');\n\ngoog.require('org.apache.flex.core.Application');\n\n\n\n\n/**\n
* @constructor\n * @extends {org.apache.flex.core.Application}\n */\nAppName = function()
{\n  AppName.base(this, 'constructor');\n  \n  this.foo = ['foo'];\n  /**\n   * @private\n
  * @type {Array}\n   */\n  this.mxmldd;\n  \n  /**\n   * @private\n   * @type {Array}\n 
 */\n  this.mxmldp;\n};\ngoog.inherits(AppName, org.apache.flex.core.Application);\n\n\n/**\n
* Metadata\n *\n * @type {Object.<string, Array.<Object>>}\n */\nAppName.prototype.FLEXJS_CLASS_INFO
= { names: [{ name: 'AppName', qName: 'AppName' }] };\n\n\n/**\n * @export\n * @type {Array}\n
*/\nAppName.prototype.foo;\n\n\n";
+        	
+        assertOut(outTemplate.replaceAll("AppName", appName));
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js b/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js
index 78f6309..79b8c5d 100644
--- a/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js
+++ b/compiler.jx.tests/test-files/flexjs/files/models/MyModel_result.js
@@ -29,7 +29,9 @@ goog.provide('models.MyModel');
  */
 models.MyModel = function() {
   models.MyModel.base(this, 'constructor');
-};
+
+this._strings = ["AAPL", "ADBE", "GOOG", "MSFT", "YHOO"];
+this._cities = ["London", "Miami", "Paris", "Sydney", "Tokyo"];};
 goog.inherits(models.MyModel, org.apache.flex.events.EventDispatcher);
 
 
@@ -44,14 +46,14 @@ models.MyModel.prototype._labelText;
  * @private
  * @type {Array}
  */
-models.MyModel.prototype._strings = ["AAPL", "ADBE", "GOOG", "MSFT", "YHOO"];
+models.MyModel.prototype._strings;
 
 
 /**
  * @private
  * @type {Array}
  */
-models.MyModel.prototype._cities = ["London", "Miami", "Paris", "Sydney", "Tokyo"];
+models.MyModel.prototype._cities;
 
 
 Object.defineProperties(models.MyModel.prototype, /** @lends {models.MyModel.prototype} */
{

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/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 67f54ba..ac83b58 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
@@ -285,6 +285,11 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         methodEmitter.emit(node);
     }
 
+    public void emitComplexInitializers(IClassNode node)
+    {
+    	classEmitter.emitComplexInitializers(node);
+    }
+    
     //--------------------------------------------------------------------------
     // Statements
     //--------------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
index ff83a52..98f9c35 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
@@ -24,15 +24,18 @@ import org.apache.flex.compiler.clients.MXMLJSC;
 import org.apache.flex.compiler.codegen.ISubEmitter;
 import org.apache.flex.compiler.codegen.js.IJSEmitter;
 import org.apache.flex.compiler.definitions.IClassDefinition;
+import org.apache.flex.compiler.definitions.IDefinition;
 import org.apache.flex.compiler.definitions.IFunctionDefinition;
 import org.apache.flex.compiler.internal.codegen.as.ASEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.JSSubEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.utils.DocEmitterUtils;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IAccessorNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IVariableNode;
 
@@ -85,6 +88,7 @@ public class ClassEmitter extends JSSubEmitter implements
                     write(ASEmitterTokens.SPACE);
                     write(ASEmitterTokens.BLOCK_OPEN);
                     writeNewline();
+                    fjs.emitComplexInitializers(node);
                     write(ASEmitterTokens.BLOCK_CLOSE);
                     write(ASEmitterTokens.SEMICOLON);
                 }
@@ -137,4 +141,28 @@ public class ClassEmitter extends JSSubEmitter implements
         fjs.getBindableEmitter().emit(definition);
         fjs.getAccessorEmitter().emit(definition);
     }
+    
+    public void emitComplexInitializers(IClassNode node)
+    {
+        IDefinitionNode[] dnodes = node.getAllMemberNodes();
+        for (IDefinitionNode dnode : dnodes)
+        {
+            if (dnode.getNodeID() == ASTNodeID.VariableID)
+            {
+            	IVariableNode varnode = ((IVariableNode)dnode);
+                IExpressionNode vnode = varnode.getAssignedValueNode();
+                if (vnode != null && (!(varnode.isConst() || EmitterUtils.isScalar(vnode))))
+                {
+                    writeNewline();
+                    write(ASEmitterTokens.THIS);
+                    write(ASEmitterTokens.MEMBER_ACCESS);
+                    write(dnode.getName());
+                    write(ASEmitterTokens.SPACE);
+                    writeToken(ASEmitterTokens.EQUAL);
+                    getEmitter().getWalker().walk(vnode);
+                    write(ASEmitterTokens.SEMICOLON);
+                }
+            }
+        }    	
+    }
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
index 95ff6a7..f5aef1a 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/FieldEmitter.java
@@ -85,7 +85,7 @@ public class FieldEmitter extends JSSubEmitter implements
         	write("_");
         }
         IExpressionNode vnode = node.getAssignedValueNode();
-        if (vnode != null)
+        if (vnode != null && (node.isConst() || EmitterUtils.isScalar(vnode)))
         {
             write(ASEmitterTokens.SPACE);
             writeToken(ASEmitterTokens.EQUAL);
@@ -111,4 +111,5 @@ public class FieldEmitter extends JSSubEmitter implements
             getModel().getBindableVars().add(node.getName());
         }
     }
+    
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MethodEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MethodEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MethodEmitter.java
index 5caa357..7383859 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MethodEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/MethodEmitter.java
@@ -34,6 +34,7 @@ import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.problems.ICompilerProblem;
 import org.apache.flex.compiler.projects.ICompilerProject;
+import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 
 public class MethodEmitter extends JSSubEmitter implements
@@ -92,6 +93,9 @@ public class MethodEmitter extends JSSubEmitter implements
             if (hasSuperClass)
                 fjs.emitSuperCall(node, JSSessionModel.CONSTRUCTOR_EMPTY);
             writeNewline();
+            IClassNode cnode = (IClassNode) node
+            .getAncestorOfType(IClassNode.class);
+            fjs.emitComplexInitializers(cnode);
             write(ASEmitterTokens.BLOCK_CLOSE);
         }
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
index 8a97565..a6c6d8c 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/utils/EmitterUtils.java
@@ -49,12 +49,14 @@ import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
+import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.tree.as.IPackageNode;
 import org.apache.flex.compiler.tree.as.IParameterNode;
 import org.apache.flex.compiler.tree.as.IScopedNode;
 import org.apache.flex.compiler.tree.as.ITypeNode;
+import org.apache.flex.compiler.utils.NativeUtils;
 
 /**
  * Various static methods used in shared emitter logic.
@@ -319,4 +321,43 @@ public class EmitterUtils
 
         return false;
     }
+    
+    public static boolean isScalar(IExpressionNode node)
+    {
+    	ASTNodeID id = node.getNodeID();
+        if (id == ASTNodeID.LiteralBooleanID ||
+        		id == ASTNodeID.LiteralIntegerID ||
+        		id == ASTNodeID.LiteralIntegerZeroID ||
+        		id == ASTNodeID.LiteralDoubleID ||
+        		id == ASTNodeID.LiteralNullID ||
+        		id == ASTNodeID.LiteralNumberID ||
+        		id == ASTNodeID.LiteralRegexID ||
+        		id == ASTNodeID.LiteralStringID ||
+        		id == ASTNodeID.LiteralUintID)
+        	return true;
+        if (id == ASTNodeID.IdentifierID)
+        {
+        	IIdentifierNode idnode = (IIdentifierNode)node;
+        	String idname = idnode.getName();
+        	if (idname.equals(NativeUtils.NativeASType.Infinity.name()) ||
+        		idname.equals(NativeUtils.NativeASType.undefined.name()) ||
+        		idname.equals(NativeUtils.NativeASType.NaN.name()))
+        		return true;
+        }
+        // special case -Infinity
+        if (id == ASTNodeID.Op_SubtractID &&
+        		node.getChildCount() == 1)
+        {
+        	IASNode child = node.getChild(0);
+        	if (child.getNodeID() == ASTNodeID.IdentifierID)
+        	{
+            	IIdentifierNode idnode = (IIdentifierNode)child;
+            	String idname = idnode.getName();
+            	if (idname.equals(NativeUtils.NativeASType.Infinity.name()))
+            		return true;        		
+        	}
+        }
+        return false;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/20e01589/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 5d44b8a..69975a0 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
@@ -47,6 +47,7 @@ import org.apache.flex.compiler.internal.codegen.databinding.XMLWatcherInfo;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitter;
 import org.apache.flex.compiler.internal.codegen.js.flexjs.JSFlexJSEmitterTokens;
 import org.apache.flex.compiler.internal.codegen.js.goog.JSGoogEmitterTokens;
+import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.internal.codegen.mxml.MXMLEmitter;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
 import org.apache.flex.compiler.internal.projects.FlexProject;
@@ -57,8 +58,10 @@ import org.apache.flex.compiler.internal.tree.as.MemberAccessExpressionNode;
 import org.apache.flex.compiler.projects.ICompilerProject;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IExpressionNode;
 import org.apache.flex.compiler.tree.as.IImportNode;
+import org.apache.flex.compiler.tree.as.IVariableNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLArrayNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLClassDefinitionNode;
 import org.apache.flex.compiler.tree.mxml.IMXMLClassNode;
@@ -205,6 +208,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
         emitClassDeclStart(cname, node.getBaseClassName(), false);
 
+        emitComplexInitializers(node);
+
         emitPropertyDecls();
         
         emitClassDeclEnd(cname, node.getBaseClassName());
@@ -285,6 +290,8 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
 
         emitClassDeclStart(cname, baseClassName, false);
 
+        emitComplexInitializers(classNode);
+        
         emitPropertyDecls();
         
         emitClassDeclEnd(cname, baseClassName);
@@ -347,7 +354,7 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
         write(JSGoogEmitterTokens.GOOG_CONSTRUCTOR);
         write(ASEmitterTokens.SINGLE_QUOTE);
         write(ASEmitterTokens.PAREN_CLOSE);
-        writeNewline(ASEmitterTokens.SEMICOLON);
+        writeNewline(ASEmitterTokens.SEMICOLON);        
     }
 
     //--------------------------------------------------------------------------
@@ -1952,4 +1959,39 @@ public class MXMLFlexJSEmitter extends MXMLEmitter implements
     	return name;
     }
 
+    private void emitComplexInitializers(IASNode node)
+    {
+    	int n = node.getChildCount();
+    	for (int i = 0; i < n; i++)
+    	{
+    		IASNode child = node.getChild(i);
+    		if (child.getNodeID() == ASTNodeID.MXMLScriptID)
+    		{
+    			int m = child.getChildCount();
+    			for (int j = 0; j < m; j++)
+    			{
+    				IASNode schild = child.getChild(j);
+    				if (schild.getNodeID() == ASTNodeID.VariableID)
+    				{
+    					IVariableNode varnode = (IVariableNode)schild;
+    			        IExpressionNode vnode = varnode.getAssignedValueNode();
+    			        if (vnode != null && (!(varnode.isConst() || EmitterUtils.isScalar(vnode))))
+    			        {
+    	                    writeNewline();
+    	                    write(ASEmitterTokens.THIS);
+    	                    write(ASEmitterTokens.MEMBER_ACCESS);
+    	                    write(varnode.getName());
+    	                    write(ASEmitterTokens.SPACE);
+    	                    writeToken(ASEmitterTokens.EQUAL);
+    	                    JSFlexJSEmitter fjs = (JSFlexJSEmitter) ((IMXMLBlockWalker) getMXMLWalker())
+    	                    .getASEmitter();
+    	                    fjs.getWalker().walk(vnode);
+    	                    write(ASEmitterTokens.SEMICOLON);
+
+    			        }
+    				}
+    			}
+    		}
+    	}
+    }
 }


Mime
View raw message