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/22 13:44:39 UTC
svn commit: r1436877 - in /flex/falcon/trunk:
compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/
compiler.jx.tests/test-files/
compiler.jx/src/org/apache/flex/compiler/constants/
compiler.jx/src/org/apache/flex/compiler/internal/j...
Author: erikdebruin
Date: Tue Jan 22 12:44:39 2013
New Revision: 1436877
URL: http://svn.apache.org/viewvc?rev=1436877&view=rev
Log:
- 'goog' output needs "this." in front of unqualified function calls
Added:
flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/constants/
flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/constants/IASGlobalFunctionConstants.java (with props)
Modified:
flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java
flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogExpressions.java
flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogPackage.java
flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogStatements.java
flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object.as
flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object_result.js
flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
Modified: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java?rev=1436877&r1=1436876&r2=1436877&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java (original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogEmiter.java Tue Jan 22 12:44:39 2013
@@ -49,7 +49,7 @@ public class TestGoogEmiter extends Test
+ "return \"Don't \" + _privateVar + value; }";
IFileNode node = getFileNode(code);
visitor.visitFile(node);
- assertOut("goog.provide('com.example.components.MyTextButton');\n\ngoog.require('spark.components.Button');\n\n/**\n * @constructor\n * @extends {spark.components.Button}\n */\ncom.example.components.MyTextButton = function() {\n\tgoog.base(this);\n\tif (foo() != 42) {\n\t\tbar();\n\t}\n}\ngoog.inherits(com.example.components.MyTextButton, spark.components.Button);\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};");
+ assertOut("goog.provide('com.example.components.MyTextButton');\n\ngoog.require('spark.components.Button');\n\n/**\n * @constructor\n * @extends {spark.components.Button}\n */\ncom.example.components.MyTextButton = function() {\n\tgoog.base(this);\n\tif (this.foo() != 42) {\n\t\tthis.bar();\n\t}\n}\ngoog.inherits(com.example.components.MyTextButton, spark.components.Button);\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};");
}
@Test
@@ -108,7 +108,7 @@ public class TestGoogEmiter extends Test
+ "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}");
+ + "\tif (a)\n\t\tthis.foo();\n}");
}
@Test
Modified: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogExpressions.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogExpressions.java?rev=1436877&r1=1436876&r2=1436877&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogExpressions.java (original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogExpressions.java Tue Jan 22 12:44:39 2013
@@ -113,7 +113,7 @@ public class TestGoogExpressions extends
"if (a) {addListener('foo', function(event:Object):void{doit();});}",
IIfNode.class);
visitor.visitIf(node);
- assertOut("if (a) {\n\taddListener('foo', function(event) {\n\t\tdoit();\n\t});\n}");
+ assertOut("if (a) {\n\tthis.addListener('foo', function(event) {\n\t\tthis.doit();\n\t});\n}");
}
@Override
Modified: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogPackage.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogPackage.java?rev=1436877&r1=1436876&r2=1436877&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogPackage.java (original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogPackage.java Tue Jan 22 12:44:39 2013
@@ -93,7 +93,7 @@ public class TestGoogPackage extends Tes
{
IFileNode node = getFileNode("package foo.bar.baz {public class A{public function A(){if (a){for (var i:Object in obj){doit();}}}}}");
visitor.visitFile(node);
- assertOut("goog.provide('foo.bar.baz.A');\n\n/**\n * @constructor\n */\nfoo.bar.baz.A = function() {\n\tif (a) {\n\t\tfor (var /** @type {Object} */ i in obj) {\n\t\t\tdoit();\n\t\t}\n\t}\n};");
+ assertOut("goog.provide('foo.bar.baz.A');\n\n/**\n * @constructor\n */\nfoo.bar.baz.A = function() {\n\tif (a) {\n\t\tfor (var /** @type {Object} */ i in obj) {\n\t\t\tthis.doit();\n\t\t}\n\t}\n};");
}
@Override
Modified: flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogStatements.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogStatements.java?rev=1436877&r1=1436876&r2=1436877&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogStatements.java (original)
+++ flex/falcon/trunk/compiler.jx.tests/src/org/apache/flex/compiler/internal/js/codegen/goog/TestGoogStatements.java Tue Jan 22 12:44:39 2013
@@ -283,7 +283,7 @@ public class TestGoogStatements extends
+ "foo: for each(var i:int in obj) break foo;",
IFileNode.class);
visitor.visitFile(node);
- assertOut("goog.provide('A');\n\n/**\n * @constructor\n */\nA = function() {\n};\n\nA.prototype.a = function() {\n\ttry {\n\t\ta;\n\t} catch (e) {\n\t\tif (a) {\n\t\t\tif (b) {\n\t\t\t\tif (c)\n\t\t\t\t\tb;\n\t\t\t\telse if (f)\n\t\t\t\t\ta;\n\t\t\t\telse\n\t\t\t\t\te;\n\t\t\t}\n\t\t}\n\t} finally {\n\t}\n\tif (d)\n\t\tfor (var /** @type {number} */ i = 0; i < len; i++)\n\t\t\tbreak;\n\tif (a) {\n\t\twith (ab) {\n\t\t\tc();\n\t\t}\n\t\tdo {\n\t\t\ta++;\n\t\t\tdo\n\t\t\t\ta++;\n\t\t\twhile (a > b);\n\t\t} while (c > d);\n\t}\n\tif (b) {\n\t\ttry {\n\t\t\ta;\n\t\t\tthrow new Error('foo');\n\t\t} catch (e) {\n\t\t\tswitch (i) {\n\t\t\t\tcase 1:\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t} catch (f) {\n\t\t\tc;\n\t\t\teee.dd;\n\t\t} finally {\n\t\t\td;\n\t\t\tvar /** @type {Object} */ a = function(foo, bar) {\n\t\t\t\tbar = typeof bar !== 'undefined' ? bar : 'goo';\n\t\t\t\treturn -1;\n\t\t\t};\n\t\t\teee.dd;\n\t\t\teee.dd;\n\t\t\teee.dd;\n\t\t\
teee.dd;\n\t\t}\n\t}\n\tfoo : for-each (var /** @type {number} */ i in obj)\n\t\tbreak foo;;\n};");
+ assertOut("goog.provide('A');\n\n/**\n * @constructor\n */\nA = function() {\n};\n\nA.prototype.a = function() {\n\ttry {\n\t\ta;\n\t} catch (e) {\n\t\tif (a) {\n\t\t\tif (b) {\n\t\t\t\tif (c)\n\t\t\t\t\tb;\n\t\t\t\telse if (f)\n\t\t\t\t\ta;\n\t\t\t\telse\n\t\t\t\t\te;\n\t\t\t}\n\t\t}\n\t} finally {\n\t}\n\tif (d)\n\t\tfor (var /** @type {number} */ i = 0; i < len; i++)\n\t\t\tbreak;\n\tif (a) {\n\t\twith (ab) {\n\t\t\tthis.c();\n\t\t}\n\t\tdo {\n\t\t\ta++;\n\t\t\tdo\n\t\t\t\ta++;\n\t\t\twhile (a > b);\n\t\t} while (c > d);\n\t}\n\tif (b) {\n\t\ttry {\n\t\t\ta;\n\t\t\tthrow new Error('foo');\n\t\t} catch (e) {\n\t\t\tswitch (i) {\n\t\t\t\tcase 1:\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\treturn;\n\t\t\t}\n\t\t} catch (f) {\n\t\t\tc;\n\t\t\teee.dd;\n\t\t} finally {\n\t\t\td;\n\t\t\tvar /** @type {Object} */ a = function(foo, bar) {\n\t\t\t\tbar = typeof bar !== 'undefined' ? bar : 'goo';\n\t\t\t\treturn -1;\n\t\t\t};\n\t\t\teee.dd;\n\t\t\teee.dd;\n\t\t\teee.dd;\n
\t\t\teee.dd;\n\t\t}\n\t}\n\tfoo : for-each (var /** @type {number} */ i in obj)\n\t\tbreak foo;;\n};");
}
Modified: flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object.as
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object.as?rev=1436877&r1=1436876&r2=1436877&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object.as (original)
+++ flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object.as Tue Jan 22 12:44:39 2013
@@ -1,15 +1,19 @@
package org.apache.flex
{
+import flash.events.EventDispatcher;
+
import spark.components.Button;
-public class A
+public class A extends EventDispatcher
{
public function A() {}
public function init()
{
var btn:Button = new Button();
+
+ addEventListener("click", function () {});
}
}
}
\ No newline at end of file
Modified: flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object_result.js
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object_result.js?rev=1436877&r1=1436876&r2=1436877&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object_result.js (original)
+++ flex/falcon/trunk/compiler.jx.tests/test-files/qualify-new-object_result.js Tue Jan 22 12:44:39 2013
@@ -1,13 +1,19 @@
goog.provide('org.apache.flex.A');
+goog.require('flash.events.EventDispatcher');
goog.require('spark.components.Button');
/**
* @constructor
+ * @extends {flash.events.EventDispatcher}
*/
org.apache.flex.A = function() {
-};
+ goog.base(this);
+}
+goog.inherits(org.apache.flex.A, flash.events.EventDispatcher);
org.apache.flex.A.prototype.init = function() {
var /** @type {spark.components.Button} */ btn = new spark.components.Button();
+ this.addEventListener("click", function() {
+ });
};
\ No newline at end of file
Added: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/constants/IASGlobalFunctionConstants.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/constants/IASGlobalFunctionConstants.java?rev=1436877&view=auto
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/constants/IASGlobalFunctionConstants.java (added)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/constants/IASGlobalFunctionConstants.java Tue Jan 22 12:44:39 2013
@@ -0,0 +1,93 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.flex.compiler.constants;
+
+
+/**
+ * AS3 language global functions, such as Array, encodeURI, isNaN etc.
+ *
+ * @author Erik de Bruin
+ */
+public interface IASGlobalFunctionConstants
+{
+ static final String Array = "Array";
+ static final String Boolean = "Boolean";
+ static final String decodeURI = "decodeURI";
+ static final String decodeURIComponent = "decodeURIComponent";
+ static final String encodeURI = "encodeURI";
+ static final String encodeURIComponent = "encodeURIComponent";
+ static final String escape = "escape";
+ static final String _int = "int";
+ static final String isFinite = "isFinite";
+ static final String isNaN = "isNaN";
+ static final String isXMLName = "isXMLName";
+ static final String Number = "Number";
+ static final String Object = "Object";
+ static final String parseFloat = "parseFloat";
+ static final String parseInt = "parseInt";
+ static final String String = "String";
+ static final String trace = "trace";
+ static final String uint = "uint";
+ static final String unescape = "unescape";
+ static final String Vector = "Vector";
+ static final String XML = "XML";
+ static final String XMLList = "XMLList";
+
+ /**
+ * An enumeration of core built-in functions.
+ */
+ static enum BuiltinType
+ {
+ ARRAY(IASGlobalFunctionConstants.Array),
+ BOOLEAN(IASGlobalFunctionConstants.Boolean),
+ DECODEURI(IASGlobalFunctionConstants.decodeURI),
+ DECODEURICOMPONENT(IASGlobalFunctionConstants.decodeURIComponent),
+ ENCODEURI(IASGlobalFunctionConstants.encodeURI),
+ ENCODEURICOMPONENT(IASGlobalFunctionConstants.encodeURIComponent),
+ ESCAPE(IASGlobalFunctionConstants.escape),
+ INT(IASGlobalFunctionConstants._int),
+ ISFINITE(IASGlobalFunctionConstants.isFinite),
+ ISNAN(IASGlobalFunctionConstants.isNaN),
+ ISXMLNAME(IASGlobalFunctionConstants.isXMLName),
+ NUMBER(IASGlobalFunctionConstants.Number),
+ OBJECT(IASGlobalFunctionConstants.Object),
+ PARSEFLOAT(IASGlobalFunctionConstants.parseFloat),
+ PARSEINT(IASGlobalFunctionConstants.parseInt),
+ STRING(IASGlobalFunctionConstants.String),
+ TRACE(IASGlobalFunctionConstants.trace),
+ UINT(IASGlobalFunctionConstants.uint),
+ UNESCAPE(IASGlobalFunctionConstants.unescape),
+ VECTOR(IASGlobalFunctionConstants.Vector),
+ XML(IASGlobalFunctionConstants.XML),
+ XMLLIST(IASGlobalFunctionConstants.XMLList);
+
+ private BuiltinType(String name)
+ {
+ this.name = name;
+ }
+
+ private final String name;
+
+ public String getName()
+ {
+ return name;
+ }
+ }
+}
Propchange: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/constants/IASGlobalFunctionConstants.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java
URL: http://svn.apache.org/viewvc/flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java?rev=1436877&r1=1436876&r2=1436877&view=diff
==============================================================================
--- flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java (original)
+++ flex/falcon/trunk/compiler.jx/src/org/apache/flex/compiler/internal/js/codegen/goog/JSGoogEmitter.java Tue Jan 22 12:44:39 2013
@@ -28,6 +28,7 @@ import java.util.Map;
import org.apache.flex.compiler.common.ASModifier;
import org.apache.flex.compiler.common.ModifiersSet;
+import org.apache.flex.compiler.constants.IASGlobalFunctionConstants;
import org.apache.flex.compiler.constants.IASKeywordConstants;
import org.apache.flex.compiler.constants.IASLanguageConstants;
import org.apache.flex.compiler.definitions.IClassDefinition;
@@ -502,6 +503,40 @@ public class JSGoogEmitter extends JSEmi
write(PERIOD);
}
}
+ else
+ {
+ // (erikdebruin) 'goog' likes all non-global function calls to
+ // be prefixed with 'this'... unless they already
+ // have a 'this' reference ;-)
+// ILanguageIdentifierNode linode = null;
+// if (cnode instanceof ILanguageIdentifierNode)
+// linode = (ILanguageIdentifierNode) cnode;
+//
+// boolean hasThis = linode != null
+// && linode.getKind() == LanguageIdentifierKind.THIS;
+ if (node.getChild(0).getNodeID() != ASTNodeID.MemberAccessExpressionID)
+ {
+ String name = node.getFunctionName();
+ boolean isBuiltinFunction = name.matches("Vector\\.<.*>");
+ IASGlobalFunctionConstants.BuiltinType[] builtinTypes =
+ IASGlobalFunctionConstants.BuiltinType.values();
+ for (IASGlobalFunctionConstants.BuiltinType builtinType
+ : builtinTypes)
+ {
+ if (name.equalsIgnoreCase(builtinType.getName()))
+ {
+ isBuiltinFunction = true;
+ break;
+ }
+ }
+
+ if (!isBuiltinFunction)
+ {
+ write(IASKeywordConstants.THIS);
+ write(PERIOD);
+ }
+ }
+ }
getWalker().walk(node.getNameNode());