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 11:48:11 UTC
svn commit: r1430205 - 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/goog/
Author: erikdebruin
Date: Tue Jan 8 10:48:10 2013
New Revision: 1430205
URL: http://svn.apache.org/viewvc?rev=1430205&view=rev
Log:
- implemented handling of 'chained' variable declarations ("var a, b, c;")
- fixed issue where a return type 'void' would result in a 'goog' annotation " * @return {void}"
- cleaned up a few minor issues 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/TestGoogFieldMembers.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=1430205&r1=1430204&r2=1430205&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 10:48:10 2013
@@ -25,7 +25,6 @@ import org.apache.flex.compiler.internal
import org.apache.flex.compiler.internal.js.driver.goog.GoogBackend;
import org.apache.flex.compiler.tree.as.IFileNode;
import org.apache.flex.compiler.tree.as.IFunctionNode;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -55,7 +54,7 @@ public class TestGoogEmiter extends Test
+ "return \"Don't \" + _privateVar + value; }";
IFileNode node = getFileNode(code);
visitor.visitFile(node);
- //assertOut("");
+ assertOut("goog.provide('com.example.components.MyTextButton');\n\ngoog.require('org.apache.flex.html.staticControls.TextButton');\n\n/**\n * @constructor\n */\ncom.example.components.MyTextButton = function() {\n\tif (foo() != 42) {\n\t\tbar();\n\t}\n};\n\n/**\n * @private\n * @type {string}\n */\ncom.example.components.MyTextButton.prototype._privateVar = \"do \";\n\n/**\n * @type {Number}\n */\ncom.example.components.MyTextButton.prototype.publicProperty = 100;\n\n/**\n * @param {string} value\n * @return {string}\n */\ncom.example.components.MyTextButton.prototype.myFunction = function(value) {\n\treturn \"Don't \" + _privateVar + value;\n};\n\n");
}
@Test
@@ -88,16 +87,12 @@ public class TestGoogEmiter extends Test
JSSharedData.OUTPUT_JSDOC = true;
}
- @Ignore
@Test
public void testSimpleMultipleParameter_JSDoc()
{
- // jsdoc still needs to be sorted out before tests are executing
IFunctionNode node = getMethod("function method1(bar:int, baz:String, goo:A):void{\n}");
visitor.visitFunction(node);
- assertOut("/**\n * @this {foo.bar.A}\n * @param {int} bar\n * @param {String} baz\n"
- + " * @param {A} goo\n * @return {void}\n */\nfoo.bar.A.prototype.method1 = "
- + "function(bar, baz, goo) {\n}");
+ assertOut("/**\n * @param {number} bar\n * @param {string} baz\n * @param {A} goo\n */\nfoo.bar.A.prototype.method1 = function(bar, baz, goo) {\n}");
}
@Test
@@ -133,7 +128,7 @@ public class TestGoogEmiter extends Test
JSSharedData.OUTPUT_JSDOC = false;
IFunctionNode node = getMethod("function method1(bar:int = 42, bax:int = 4):void{if (a) foo();}");
visitor.visitFunction(node);
- assertOutDebug("foo.bar.A.prototype.method1 = function(bar, bax) {\n"
+ assertOut("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}");
Modified: flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogFieldMembers.java
URL: http://svn.apache.org/viewvc/flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogFieldMembers.java?rev=1430205&r1=1430204&r2=1430205&view=diff
==============================================================================
--- flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogFieldMembers.java (original)
+++ flex/whiteboard/mschmalle/falconjx/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogFieldMembers.java Tue Jan 8 10:48:10 2013
@@ -55,7 +55,6 @@ public class TestGoogFieldMembers extend
@Test
public void testField_withType()
{
- // same as 'testField'
IVariableNode node = getField("var foo:int;");
visitor.visitVariable(node);
assertOut("/**\n * @type {number}\n */\nA.prototype.foo");
@@ -65,7 +64,6 @@ public class TestGoogFieldMembers extend
@Test
public void testField_withTypeValue()
{
- // same as 'testField'
IVariableNode node = getField("var foo:int = 420;");
visitor.visitVariable(node);
assertOut("/**\n * @type {number}\n */\nA.prototype.foo = 420");
@@ -86,7 +84,7 @@ public class TestGoogFieldMembers extend
{
IVariableNode node = getField("mx_internal var foo:int = 420;");
visitor.visitVariable(node);
- // we ignore custom namespaces completely (are there side effects I'm missing?)
+ // (erikdebruin) we ignore custom namespaces completely (are there side effects I'm missing?)
assertOut("/**\n * @type {number}\n */\nA.prototype.foo = 420");
}
@@ -120,16 +118,12 @@ public class TestGoogFieldMembers extend
}
@Override
- @Ignore
@Test
public void testField_withList()
{
- // TODO (erikdebruin) I think we need to write out all the 'chained'
- // declarations on their own lines to get the
- // annotations right
IVariableNode node = getField("protected var a:int = 4, b:int = 11, c:int = 42;");
visitor.visitVariable(node);
- assertOut("");
+ assertOut("/**\n * @protected\n * @type {number}\n */\nA.prototype.a = 4;\n\n/**\n * @protected\n * @type {number}\n */\nA.prototype.b = 11;\n\n/**\n * @protected\n * @type {number}\n */\nA.prototype.c = 42");
}
//--------------------------------------------------------------------------
@@ -178,7 +172,7 @@ public class TestGoogFieldMembers extend
{
IVariableNode node = getField("mx_internal static const foo:int = 420;");
visitor.visitVariable(node);
- // we ignore custom namespaces completely (are there side effects I'm missing?)
+ // (erikdebruin) we ignore custom namespaces completely (are there side effects I'm missing?)
assertOut("/**\n * @const\n * @type {number}\n */\nA.foo = 420");
}
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=1430205&r1=1430204&r2=1430205&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 10:48:10 2013
@@ -32,6 +32,7 @@ import org.apache.flex.compiler.definiti
import org.apache.flex.compiler.definitions.ITypeDefinition;
import org.apache.flex.compiler.internal.js.codegen.JSEmitter;
import org.apache.flex.compiler.internal.semantics.SemanticUtils;
+import org.apache.flex.compiler.internal.tree.as.ChainedVariableNode;
import org.apache.flex.compiler.internal.tree.as.FunctionNode;
import org.apache.flex.compiler.js.codegen.goog.IJSGoogDocEmitter;
import org.apache.flex.compiler.js.codegen.goog.IJSGoogEmitter;
@@ -68,11 +69,6 @@ public class JSGoogEmitter extends JSEmi
//
//--------------------------------------------------------------------------
- public void emitJSDocPackgeHeader(IPackageNode node)
- {
- // getDocEmitter().emmitPackageHeader(node);
- }
-
@Override
public void emitJSDocVariable(IVariableNode node)
{
@@ -221,7 +217,7 @@ public class JSGoogEmitter extends JSEmi
IClassDefinition definition = getClassDefinition(node);
emitJSDocVariable(node);
-
+
String root = "";
if (!node.isConst())
root = "prototype.";
@@ -233,6 +229,21 @@ public class JSGoogEmitter extends JSEmi
write(" = ");
getWalker().walk(vnode);
}
+
+ if (!(node instanceof ChainedVariableNode))
+ {
+ int len = node.getChildCount();
+ for (int i = 0; i < len; i++)
+ {
+ IASNode child = node.getChild(i);
+ if (child instanceof ChainedVariableNode)
+ {
+ write(";");
+ write("\n\n");
+ emitField((IVariableNode) child);
+ }
+ }
+ }
}
@Override
@@ -282,10 +293,8 @@ public class JSGoogEmitter extends JSEmi
}
// @return
- // TODO (erikdebruin) only emit @return when there actually is
- // a return value defined
String returnType = node.getReturnType();
- if (returnType != "")
+ if (returnType != "" && returnType != "void")
{
if (!hasDoc)
{
@@ -368,74 +377,8 @@ public class JSGoogEmitter extends JSEmi
emitDefaultParameterCodeBlock(node);
}
- /*
- private void emitDefaultParameterCodeBlock_Alternate(IFunctionNode node)
- {
- // TODO (mschmalle) test for ... rest
- // if default parameters exist, produce the init code
- IParameterNode[] pnodes = node.getParameterNodes();
- Map<Integer, IParameterNode> defaults = getDefaults(pnodes);
- if (pnodes.length == 0)
- return;
-
- final StringBuilder code = new StringBuilder();
- if (defaults != null)
- {
- List<IParameterNode> parameters = new ArrayList<IParameterNode>(
- defaults.values());
- Collections.reverse(parameters);
-
- int len = defaults.size();
- int numDefaults = 0;
- // make the header in reverse order
- for (IParameterNode pnode : parameters)
- {
- if (pnode != null)
- {
- code.append(getIndent(numDefaults));
- code.append("if (arguments.length < " + len + ") {\n");
- numDefaults++;
- }
- len--;
- }
-
- Collections.reverse(parameters);
- for (IParameterNode pnode : parameters)
- {
- if (pnode != null)
- {
- code.append(getIndent(numDefaults));
- code.append(pnode.getName());
- code.append(" = ");
- code.append(pnode.getDefaultValue());
- code.append(";\n");
- code.append(getIndent(numDefaults - 1));
- code.append("}");
- if (numDefaults > 1)
- code.append("\n");
- numDefaults--;
- }
- }
- IScopedNode sbn = node.getScopedNode();
- boolean hasBody = sbn.getChildCount() > 0;
- // adds the current block indent to the generated code
- String indent = getIndent(getCurrentIndent() + (!hasBody ? 1 : 0));
- String result = code.toString().replaceAll("\n", "\n" + indent);
- // if the block dosn't have a body (children), need to add indent to head
- if (!hasBody)
- result = indent + result;
- // have to add newline after the replace or we get an extra indent
- result += "\n";
- write(result);
- }
- }
- */
-
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;