incubator-flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mschma...@apache.org
Subject svn commit: r1426192 - in /incubator/flex/whiteboard/mschmalle/falconjx: compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java
Date Thu, 27 Dec 2012 13:21:07 GMT
Author: mschmalle
Date: Thu Dec 27 13:21:06 2012
New Revision: 1426192

URL: http://svn.apache.org/viewvc?rev=1426192&view=rev
Log:
Flex:FalconJx
- Fixed parameter alternate indent when no block code exists

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

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java?rev=1426192&r1=1426191&r2=1426192&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/js/internal/js/codegen/TestGoogEmiter.java
Thu Dec 27 13:21:06 2012
@@ -188,11 +188,30 @@ public class TestGoogEmiter extends Test
         assertOut("foo.bar.A.method1 = function(p1, p2, p3, p4) {\n" +
         		"\tp3 = typeof p3 !== 'undefined' ? p3 : 3;\n" +
         		"\tp4 = typeof p4 !== 'undefined' ? p4 : 4;\n" +
-        		"\n" +
                 "\treturn p1 + p2 + p3 + p4;\n}");
         JSSharedData.OUTPUT_ALTERNATE = false;
         JSSharedData.OUTPUT_JSDOC = true;
     }
+    
+    @Test
+    public void testDefaultParameter_AlternateNoBody()
+    {
+        /*
+        foo.bar.A.method1 = function(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{}");
+        visitor.visitFunction(node);
+        assertOut("foo.bar.A.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;
+    }
 
     protected IBackend createBackend()
     {

Modified: incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java
URL: http://svn.apache.org/viewvc/incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java?rev=1426192&r1=1426191&r2=1426192&view=diff
==============================================================================
--- incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java
(original)
+++ incubator/flex/whiteboard/mschmalle/falconjx/compiler.jx/src/org/apache/flex/compiler/internal/js/codgen/JSGoogEmitter.java
Thu Dec 27 13:21:06 2012
@@ -197,7 +197,7 @@ public class JSGoogEmitter extends JSEmi
             write(qname);
             write(".");
         }
-        
+
         emitMemberName(node);
         write(" ");
         write("=");
@@ -210,13 +210,13 @@ public class JSGoogEmitter extends JSEmi
     @Override
     public void emitFunctionBlockHeader(IFunctionNode node)
     {
-        if (JSSharedData.OUTPUT_ALTERNATE) 
+        if (JSSharedData.OUTPUT_ALTERNATE)
         {
-        	emitDefaultParameterCodeBlock_Alternate(node);
-        } 
-        else 
+            emitDefaultParameterCodeBlock_Alternate(node);
+        }
+        else
         {
-        	emitDefaultParameterCodeBlock(node);
+            emitDefaultParameterCodeBlock(node);
         }
     }
 
@@ -232,7 +232,7 @@ public class JSGoogEmitter extends JSEmi
             List<IParameterNode> parameters = new ArrayList<IParameterNode>(
                     defaults.values());
             Collections.reverse(parameters);
-            
+
             int len = defaults.size();
             int numDefaults = 0;
             // make the header in reverse order
@@ -246,7 +246,7 @@ public class JSGoogEmitter extends JSEmi
                 }
                 len--;
             }
-            
+
             Collections.reverse(parameters);
             for (IParameterNode pnode : parameters)
             {
@@ -281,39 +281,45 @@ public class JSGoogEmitter extends JSEmi
     private void emitDefaultParameterCodeBlock_Alternate(IFunctionNode node)
     {
         // (erikdebruin) implemented alternative approach to handling 
-    	//               default parameter values in JS
+        //               default parameter values in JS
+
+        IParameterNode[] pnodes = node.getParameterNodes();
 
-    	IParameterNode[] pnodes = node.getParameterNodes();
-        
         Map<Integer, IParameterNode> defaults = getDefaults(pnodes);
-        
+
+        if (!hasBody(node))
+        {
+            indentPush();
+            write("\t");
+        }
+
         final StringBuilder code = new StringBuilder();
-        
+
         if (defaults != null)
         {
             List<IParameterNode> parameters = new ArrayList<IParameterNode>(
                     defaults.values());
-            
+
             int numDefaults = 0;
             for (IParameterNode pnode : parameters)
             {
                 if (pnode != null)
                 {
-                	if (numDefaults > 0)
-                		code.append(getIndent(getCurrentIndent()));
-                	
-                    code.append(
-                    		pnode.getName() + 
-                    		" = typeof " + pnode.getName() + " !== 'undefined' ? " + 
-                    		pnode.getName() + " : " + 
-                    		pnode.getDefaultValue() + ";\n");
-                    
+                    if (numDefaults > 0)
+                        code.append(getIndent(getCurrentIndent()));
+
+                    code.append(pnode.getName() + " = typeof "
+                            + pnode.getName() + " !== 'undefined' ? "
+                            + pnode.getName() + " : " + pnode.getDefaultValue()
+                            + ";\n");
+
                     numDefaults++;
                 }
             }
 
-            code.append("\n");
-            
+            if (!hasBody(node))
+                indentPop();
+
             write(code.toString());
         }
     }
@@ -364,4 +370,9 @@ public class JSGoogEmitter extends JSEmi
         return result;
     }
 
+    private static boolean hasBody(IFunctionNode node)
+    {
+        IScopedNode scope = node.getScopedNode();
+        return scope.getChildCount() > 0;
+    }
 }



Mime
View raw message