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] - hack in support for force-linking via import foo.bar.baz; baz
Date Tue, 11 Oct 2016 15:52:56 GMT
hack in support for force-linking via import foo.bar.baz; baz


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

Branch: refs/heads/develop
Commit: cc3183d18311137e1705d89ee9dca69f2a013068
Parents: 86644a9
Author: Alex Harui <aharui@apache.org>
Authored: Mon Oct 10 14:46:23 2016 -0700
Committer: Alex Harui <aharui@apache.org>
Committed: Tue Oct 11 08:52:49 2016 -0700

----------------------------------------------------------------------
 .../internal/codegen/js/jx/ClassEmitter.java    | 35 ++++++++++++++++++++
 .../codegen/js/flexjs/TestFlexJSClass.java      | 16 +++++----
 2 files changed, 44 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/cc3183d1/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
index 0a37cf4..d629b5d 100644
--- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/ClassEmitter.java
@@ -28,9 +28,12 @@ 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.goog.JSGoogEmitterTokens;
 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.internal.tree.as.IdentifierNode;
 import org.apache.flex.compiler.tree.ASTNodeID;
+import org.apache.flex.compiler.tree.as.IASNode;
 import org.apache.flex.compiler.tree.as.IAccessorNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.apache.flex.compiler.tree.as.IDefinitionNode;
@@ -65,6 +68,38 @@ public class ClassEmitter extends JSSubEmitter implements
 
         IFunctionDefinition ctorDefinition = definition.getConstructor();
 
+        // look for force-linking pattern in scope block node
+        int childNodeCount = node.getChildCount();
+        for (int i = 0; i < childNodeCount; i++)
+        {
+        	IASNode child = node.getChild(i);
+        	if (child.getNodeID() == ASTNodeID.BlockID)
+        	{
+        		int blockNodeCount = child.getChildCount();
+        		for (int j = 0; j < blockNodeCount - 1; j++)
+        		{
+        			IASNode blockChild = child.getChild(j);
+        			if (blockChild.getNodeID() == ASTNodeID.ImportID)
+        			{
+        				IASNode afterChild = child.getChild(j + 1);
+        				if (afterChild.getNodeID() == ASTNodeID.IdentifierID)
+        				{
+                            write(JSGoogEmitterTokens.GOOG_REQUIRE);
+                            write(ASEmitterTokens.PAREN_OPEN);
+                            write(ASEmitterTokens.SINGLE_QUOTE);
+                            getEmitter().emitIdentifier((IdentifierNode)afterChild);    
                       
+                            write(ASEmitterTokens.SINGLE_QUOTE);
+                            write(ASEmitterTokens.PAREN_CLOSE);
+                            writeNewline(ASEmitterTokens.SEMICOLON);
+                            writeNewline();
+                            writeNewline();
+        				}
+        			}
+        		}
+        		break;
+        	}        	
+        }
+        
         // Static-only (Singleton) classes may not have a constructor
         if (ctorDefinition != null)
         {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/cc3183d1/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
index 8b91070..a28583e 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
@@ -23,6 +23,7 @@ import org.apache.flex.compiler.driver.IBackend;
 import org.apache.flex.compiler.internal.codegen.js.goog.TestGoogClass;
 import org.apache.flex.compiler.internal.driver.js.flexjs.FlexJSBackend;
 import org.apache.flex.compiler.internal.projects.FlexJSProject;
+import org.apache.flex.compiler.internal.tree.as.FileNode;
 import org.apache.flex.compiler.tree.as.IClassNode;
 import org.junit.Test;
 
@@ -31,13 +32,6 @@ import org.junit.Test;
  */
 public class TestFlexJSClass extends TestGoogClass
 {
-	// TODO: aharui Use cinit() to initialize statics
-	//         private static var foo:Boolean = someStaticMethodToFollow();
-	//         private static function someStaticMethodToFollow():Boolean {};
-
-	// TODO: aharui Use cinit() to handle force-linking
-	//         import somePackage.someClass; someClass;
-
     @Override
     public void setUp()
     {
@@ -233,6 +227,14 @@ public class TestFlexJSClass extends TestGoogClass
         assertOut("/**\n * @constructor\n */\norg.apache.flex.A = function() {\n};\n\n\n/**\n
* @export\n * @type {number}\n */\norg.apache.flex.A.a = 10;\n\n\n/**\n * @export\n * @type
{string}\n */\norg.apache.flex.A.b;\n\n\n/**\n * @private\n * @return {string}\n */\norg.apache.flex.A.initStatic
= function() {\n  return \"foo\";\n};\n\n\norg.apache.flex.A.b = org.apache.flex.A.initStatic();");
     }
     
+    @Test
+    public void testImportForceLinkingAsStaticInitializers()
+    {
+        FileNode node = (FileNode)getNode("package org.apache.flex {\npublic class A {\nimport
flash.display.Sprite; Sprite;\n}}", FileNode.class, 0);
+        asBlockWalker.visitFile(node);
+        assertOut("/**\n * org.apache.flex.A\n *\n * @fileoverview\n *\n * @suppress {checkTypes|accessControls}\n
*/\n\ngoog.provide('org.apache.flex.A');\n\n\n\ngoog.require('flash.display.Sprite');\n\n\n/**\n
* @constructor\n */\norg.apache.flex.A = function() {\n};");
+    }
+    
     @Override
     @Test
     public void testConstants()


Mime
View raw message