You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by er...@apache.org on 2013/01/08 10:19:18 UTC

svn commit: r1430184 - in /flex/whiteboard/mschmalle/falconjx: compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/ compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/ compiler.jx/src/org/apache/flex/compiler/internal/js/c...

Author: erikdebruin
Date: Tue Jan  8 09:19:17 2013
New Revision: 1430184

URL: http://svn.apache.org/viewvc?rev=1430184&view=rev
Log:
- Removed the global 'JSSharedData.OUTPUT_ALTERNATE'. 
- '@Ignore' the tests that use the 'AMD' style of handling default parameter values.
- fixed issue where an extra '\t' was added to empty function bodies in some tests.

Modified:
    flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java
    flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogMethodMembers.java
    flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSSharedData.java
    flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java

Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java?rev=1430184&r1=1430183&r2=1430184&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java (original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java Tue Jan  8 09:19:17 2013
@@ -101,51 +101,31 @@ public class TestGoogEmiter extends Test
     }
 
     @Test
-    public void testDefaultParameter_NoBody()
-    {
-        /*
-        foo.bar.A.method1 = function(bar, bax) {
-            if (arguments.length < 2) {
-                if (arguments.length < 1) {
-                    bar = 42;
-                }
-                bax = 4;
-            }
-        }
-        */
-        JSSharedData.OUTPUT_JSDOC = false;
-        IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{\n}");
-        visitor.visitFunction(node);
-        assertOut("foo.bar.A.prototype.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t"
-                + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n}");
-        JSSharedData.OUTPUT_JSDOC = true;
-    }
-
-    @Test
-    public void testDefaultParameter_Body()
+    public void testDefaultParameter()
     {
         /*
-        foo.bar.A.method1 = function(bar, bax) {
-            if (arguments.length < 2) {
-                if (arguments.length < 1) {
-                    bar = 42;
-                }
-                bax = 4;
-            }
+        foo.bar.A.method1 = function(p1, p2, p3, p4) {
+        	p3 = typeof p3 !== 'undefined' ? p3 : 3;
+        	p4 = typeof p4 !== 'undefined' ? p4 : 4;
+        		
+            return p1 + p2 + p3 + p4;
         }
         */
         JSSharedData.OUTPUT_JSDOC = false;
-        IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{if (a) foo();}");
+        IFunctionNode node = getMethod("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{return p1 + p2 + p3 + p4;}");
         visitor.visitFunction(node);
-        assertOut("foo.bar.A.prototype.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t"
-                + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n\t"
-                + "if (a)\n\t\tfoo();\n}");
+        assertOut("foo.bar.A.prototype.method1 = function(p1, p2, p3, p4) {\n"
+                + "\tp3 = typeof p3 !== 'undefined' ? p3 : 3;\n"
+                + "\tp4 = typeof p4 !== 'undefined' ? p4 : 4;\n"
+                + "\treturn p1 + p2 + p3 + p4;\n}");
         JSSharedData.OUTPUT_JSDOC = true;
     }
-
+    
+    @Ignore
     @Test
-    public void testDefaultParameter()
+    public void testDefaultParameter_Alternate()
     {
+    	// (erikdebruin) this tests the 'alternate' handling of default values
         /*
          foo.bar.A.method1 = function(p1, p2, p3, p4) {
             if (arguments.length < 4) {
@@ -167,30 +147,50 @@ public class TestGoogEmiter extends Test
     }
 
     @Test
-    public void testDefaultParameter_Alternate()
+    public void testDefaultParameter_Body()
     {
         /*
         foo.bar.A.method1 = function(p1, p2, p3, p4) {
-        	p3 = typeof p3 !== 'undefined' ? p3 : 3;
-        	p4 = typeof p4 !== 'undefined' ? p4 : 4;
-        		
-            return p1 + p2 + p3 + p4;
+            p3 = typeof p3 !== 'undefined' ? p3 : 3;
+            p4 = typeof p4 !== 'undefined' ? p4 : 4;
         }
         */
         JSSharedData.OUTPUT_JSDOC = false;
-        JSSharedData.OUTPUT_ALTERNATE = true;
-        IFunctionNode node = getMethod("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{return p1 + p2 + p3 + p4;}");
+        IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{if (a) foo();}");
         visitor.visitFunction(node);
-        assertOut("foo.bar.A.prototype.method1 = function(p1, p2, p3, p4) {\n"
-                + "\tp3 = typeof p3 !== 'undefined' ? p3 : 3;\n"
-                + "\tp4 = typeof p4 !== 'undefined' ? p4 : 4;\n"
-                + "\treturn p1 + p2 + p3 + p4;\n}");
-        JSSharedData.OUTPUT_ALTERNATE = false;
+        assertOutDebug("foo.bar.A.prototype.method1 = function(bar, bax) {\n"
+                + "\tbar = typeof bar !== 'undefined' ? bar : 42;\n"
+                + "\tbax = typeof bax !== 'undefined' ? bax : 4;\n"
+                + "\tif (a)\n\t\tfoo();\n}");
         JSSharedData.OUTPUT_JSDOC = true;
     }
 
+    @Ignore
     @Test
-    public void testDefaultParameter_AlternateNoBody()
+    public void testDefaultParameter_Body_Alternate()
+    {
+    	// (erikdebruin) this tests the 'alternate' handling of default values
+        /*
+        foo.bar.A.method1 = function(bar, bax) {
+            if (arguments.length < 2) {
+                if (arguments.length < 1) {
+                    bar = 42;
+                }
+                bax = 4;
+            }
+        }
+        */
+        JSSharedData.OUTPUT_JSDOC = false;
+        IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{if (a) foo();}");
+        visitor.visitFunction(node);
+        assertOut("foo.bar.A.prototype.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t"
+                + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n\t"
+                + "if (a)\n\t\tfoo();\n}");
+        JSSharedData.OUTPUT_JSDOC = true;
+    }
+
+    @Test
+    public void testDefaultParameter_NoBody()
     {
         /*
         foo.bar.A.method1 = function(p1, p2, p3, p4) {
@@ -199,13 +199,34 @@ public class TestGoogEmiter extends Test
         }
         */
         JSSharedData.OUTPUT_JSDOC = false;
-        JSSharedData.OUTPUT_ALTERNATE = true;
         IFunctionNode node = getMethod("function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{}");
         visitor.visitFunction(node);
         assertOut("foo.bar.A.prototype.method1 = function(p1, p2, p3, p4) {\n"
                 + "\tp3 = typeof p3 !== 'undefined' ? p3 : 3;\n"
                 + "\tp4 = typeof p4 !== 'undefined' ? p4 : 4;\n}");
-        JSSharedData.OUTPUT_ALTERNATE = false;
+        JSSharedData.OUTPUT_JSDOC = true;
+    }
+
+    @Ignore
+    @Test
+    public void testDefaultParameter_NoBody_Alternate()
+    {
+    	// (erikdebruin) this tests the 'alternate' handling of default values
+        /*
+        foo.bar.A.method1 = function(bar, bax) {
+            if (arguments.length < 2) {
+                if (arguments.length < 1) {
+                    bar = 42;
+                }
+                bax = 4;
+            }
+        }
+        */
+        JSSharedData.OUTPUT_JSDOC = false;
+        IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{\n}");
+        visitor.visitFunction(node);
+        assertOut("foo.bar.A.prototype.method1 = function(bar, bax) {\n\tif (arguments.length < 2) {\n\t\t"
+                + "if (arguments.length < 1) {\n\t\t\tbar = 42;\n\t\t}\n\t\tbax = 4;\n\t}\n}");
         JSSharedData.OUTPUT_JSDOC = true;
     }
 

Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogMethodMembers.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogMethodMembers.java?rev=1430184&r1=1430183&r2=1430184&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogMethodMembers.java (original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogMethodMembers.java Tue Jan  8 09:19:17 2013
@@ -24,6 +24,7 @@ import org.apache.flex.compiler.internal
 import org.apache.flex.compiler.internal.js.codegen.JSSharedData;
 import org.apache.flex.compiler.internal.js.driver.goog.GoogBackend;
 import org.apache.flex.compiler.tree.as.IFunctionNode;
+import org.junit.Ignore;
 import org.junit.Test;
 
 /**
@@ -37,22 +38,9 @@ public class TestGoogMethodMembers exten
 	// TODO (erikdebruin)
 	//  1) ideally '@this' should only be included in the annotation if there is
 	//     actually a reference to 'this' in the function body
-	//  9) switch 'alternate' indicator to point to 'Wienberg style', not mine ;-)
 	// 10) can we safely ignore the 'public' and custom namespaces?
 
     @Override
-    public void tearDown()
-    {
-        super.tearDown();
-        // XXX (mschmalle) We really have to get rid of these globals.
-        // I had all tests in TestGoogEmitter fail because this wasn't switched back
-        // to false in your tests below, this proves these are bad and are just 
-        // left from FalconJS
-        // not switching this back to false was leaving extra \t in method blocks
-        JSSharedData.OUTPUT_ALTERNATE = false;
-    }
-    
-    @Override
     @Test
     public void testMethod()
     {
@@ -93,14 +81,15 @@ public class TestGoogMethodMembers exten
     public void testMethod_withDefaultParameterTypeReturnType()
     {
         IFunctionNode node = getMethod("function foo(bar:String = \"baz\"):int{\treturn -1;}");
-    	JSSharedData.OUTPUT_ALTERNATE = true;
         visitor.visitFunction(node);
         assertOut("/**\n * @param {string=} bar\n * @return {number}\n */\nA.prototype.foo = function(bar) {\n\tbar = typeof bar !== 'undefined' ? bar : \"baz\";\n\treturn -1;\n}");
     }
 
+    @Ignore
     @Test
     public void testMethod_withDefaultParameterTypeReturnType_Alternate()
     {
+    	// (erikdebruin) this tests the 'alternate' handling of default values
         IFunctionNode node = getMethod("function foo(bar:String = \"baz\"):int{\treturn -1;}");
         visitor.visitFunction(node);
         assertOut("/**\n * @param {string=} bar\n * @return {number}\n */\nA.prototype.foo = function(bar) {\n\tif (arguments.length < 1) {\n\t\tbar = \"baz\";\n\t}\n\treturn -1;\n}");
@@ -111,14 +100,15 @@ public class TestGoogMethodMembers exten
     public void testMethod_withMultipleDefaultParameterTypeReturnType()
     {
         IFunctionNode node = getMethod("function foo(bar:String, baz:int = null):int{\treturn -1;}");
-    	JSSharedData.OUTPUT_ALTERNATE = true;
         visitor.visitFunction(node);
         assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n */\nA.prototype.foo = function(bar, baz) {\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
     }
 
+    @Ignore
     @Test
     public void testMethod_withMultipleDefaultParameterTypeReturnType_Alternate()
     {
+    	// (erikdebruin) this tests the 'alternate' handling of default values
         IFunctionNode node = getMethod("function foo(bar:String, baz:int = null):int{\treturn -1;}");
         visitor.visitFunction(node);
         assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n */\nA.prototype.foo = function(bar, baz) {\n\tif (arguments.length < 2) {\n\t\tbaz = null;\n\t}\n\treturn -1;\n}");
@@ -138,7 +128,6 @@ public class TestGoogMethodMembers exten
     public void testMethod_withNamespace()
     {
         IFunctionNode node = getMethod("public function foo(bar:String, baz:int = null):int{\treturn -1;}");
-    	JSSharedData.OUTPUT_ALTERNATE = true;
         visitor.visitFunction(node);
         // we ignore the 'public' namespace completely
         assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n */\nA.prototype.foo = function(bar, baz) {\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
@@ -149,7 +138,6 @@ public class TestGoogMethodMembers exten
     public void testMethod_withNamespaceCustom()
     {
         IFunctionNode node = getMethod("mx_internal function foo(bar:String, baz:int = null):int{\treturn -1;}");
-    	JSSharedData.OUTPUT_ALTERNATE = true;
         visitor.visitFunction(node);
         // we ignore the custom namespaces completely (are there side effects I'm missing?)
         assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n */\nA.prototype.foo = function(bar, baz) {\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
@@ -160,7 +148,6 @@ public class TestGoogMethodMembers exten
     public void testMethod_withNamespaceModifiers()
     {
         IFunctionNode node = getMethod("public static function foo(bar:String, baz:int = null):int{\treturn -1;}");
-    	JSSharedData.OUTPUT_ALTERNATE = true;
         visitor.visitFunction(node);
         // (erikdebruin) here we actually DO want to declare the method
         //               directly on the 'class' constructor instead of the
@@ -173,7 +160,6 @@ public class TestGoogMethodMembers exten
     public void testMethod_withNamespaceModifierOverride()
     {
         IFunctionNode node = getMethod("public override function foo(bar:String, baz:int = null):int{\treturn -1;}");
-    	JSSharedData.OUTPUT_ALTERNATE = true;
         visitor.visitFunction(node);
         assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n * @override\n */\nA.prototype.foo = function(bar, baz) {\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
     }
@@ -183,7 +169,6 @@ public class TestGoogMethodMembers exten
     public void testMethod_withNamespaceModifierOverrideBackwards()
     {
         IFunctionNode node = getMethod("override public function foo(bar:String, baz:int = null):int{return -1;}");
-    	JSSharedData.OUTPUT_ALTERNATE = true;
         visitor.visitFunction(node);
         assertOut("/**\n * @param {string} bar\n * @param {number=} baz\n * @return {number}\n * @override\n */\nA.prototype.foo = function(bar, baz) {\n\tbaz = typeof baz !== 'undefined' ? baz : null;\n\treturn -1;\n}");
     }
@@ -220,14 +205,6 @@ public class TestGoogMethodMembers exten
     }
     
     @Override
-    protected IFunctionNode getMethod(String code)
-    {
-    	JSSharedData.OUTPUT_ALTERNATE = false;
-    	
-    	return super.getMethod(code);
-    }
-
-    @Override
     protected IBackend createBackend()
     {
         return new GoogBackend();

Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSSharedData.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSSharedData.java?rev=1430184&r1=1430183&r2=1430184&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSSharedData.java (original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/JSSharedData.java Tue Jan  8 09:19:17 2013
@@ -41,7 +41,6 @@ public class JSSharedData
     
     // TODO (mschmalle) Temp until I figure out the correct place for configuration
     public static boolean OUTPUT_JSDOC = true;
-    public static boolean OUTPUT_ALTERNATE = false;
     
     public static IBackend backend;
     public static String OUTPUT_EXTENSION;

Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java?rev=1430184&r1=1430183&r2=1430184&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java (original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java Tue Jan  8 09:19:17 2013
@@ -21,7 +21,6 @@ package org.apache.flex.compiler.interna
 
 import java.io.FilterWriter;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,7 +31,6 @@ import org.apache.flex.compiler.definiti
 import org.apache.flex.compiler.definitions.IPackageDefinition;
 import org.apache.flex.compiler.definitions.ITypeDefinition;
 import org.apache.flex.compiler.internal.js.codegen.JSEmitter;
-import org.apache.flex.compiler.internal.js.codegen.JSSharedData;
 import org.apache.flex.compiler.internal.semantics.SemanticUtils;
 import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.js.codegen.goog.IJSGoogDocEmitter;
@@ -367,17 +365,11 @@ public class JSGoogEmitter extends JSEmi
     {
         emitRestParameterCodeBlock(node);
 
-        if (JSSharedData.OUTPUT_ALTERNATE)
-        {
-            emitDefaultParameterCodeBlock_Alternate(node);
-        }
-        else
-        {
-            emitDefaultParameterCodeBlock(node);
-        }
+        emitDefaultParameterCodeBlock(node);
     }
 
-    private void emitDefaultParameterCodeBlock(IFunctionNode node)
+    /*
+    private void emitDefaultParameterCodeBlock_Alternate(IFunctionNode node)
     {
         // TODO (mschmalle) test for ... rest 
         // if default parameters exist, produce the init code
@@ -437,26 +429,29 @@ public class JSGoogEmitter extends JSEmi
             write(result);
         }
     }
-
-    private void emitDefaultParameterCodeBlock_Alternate(IFunctionNode node)
+	*/
+    
+    private void emitDefaultParameterCodeBlock(IFunctionNode node)
     {
         // (erikdebruin) implemented alternative approach to handling 
         //               default parameter values in JS
 
         IParameterNode[] pnodes = node.getParameterNodes();
+        if (pnodes.length == 0)
+            return;
 
         Map<Integer, IParameterNode> defaults = getDefaults(pnodes);
 
-        if (!hasBody(node))
-        {
-            indentPush();
-            write("\t");
-        }
-
         final StringBuilder code = new StringBuilder();
 
         if (defaults != null)
         {
+            if (!hasBody(node))
+            {
+                indentPush();
+                write("\t");
+            }
+
             List<IParameterNode> parameters = new ArrayList<IParameterNode>(
                     defaults.values());