Repository: flex-falcon Updated Branches: refs/heads/develop aacc73f88 -> ddf557d20
change when we emit closure wrappers Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/ddf557d2 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/ddf557d2 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/ddf557d2 Branch: refs/heads/develop Commit: ddf557d207797de1dce3758f4ce55dabffb09ff2 Parents: aacc73f Author: Alex Harui <aha...@apache.org> Authored: Mon Jul 17 12:30:20 2017 -0700 Committer: Alex Harui <aha...@apache.org> Committed: Mon Jul 17 12:30:27 2017 -0700 ---------------------------------------------------------------------- .../codegen/js/jx/IdentifierEmitter.java | 21 +++------------ .../js/flexjs/TestFlexJSExpressions.java | 28 +++++++++++++++++--- 2 files changed, 28 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ddf557d2/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java index 58bcedf..3af926e 100644 --- a/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java +++ b/compiler-jx/src/main/java/org/apache/flex/compiler/internal/codegen/js/jx/IdentifierEmitter.java @@ -184,23 +184,10 @@ public class IdentifierEmitter extends JSSubEmitter implements } else if (!NativeUtils.isNative(node.getName())) { - boolean identifierIsLocalOrInstanceFunctionAsValue = false; - if (identifierIsPlainFunction) - { - FunctionClassification fc = ((FunctionDefinition)nodeDef).getFunctionClassification(); - identifierIsLocalOrInstanceFunctionAsValue = - (fc == FunctionClassification.LOCAL || fc == FunctionClassification.CLASS_MEMBER) && - // not a value if parent is a function call or member access expression - (!(parentNodeId == ASTNodeID.MemberAccessExpressionID || parentNodeId == ASTNodeID.FunctionCallID)); - - } - // an instance method as a parameter or - // a local function - boolean generateClosure = (parentNodeId == ASTNodeID.ContainerID - && identifierIsPlainFunction && ((FunctionDefinition) nodeDef) - .getFunctionClassification() == FunctionClassification.CLASS_MEMBER) - || identifierIsLocalOrInstanceFunctionAsValue; - + // an instance method not in a function call or member access + boolean generateClosure = identifierIsPlainFunction && ((FunctionDefinition) nodeDef) + .getFunctionClassification() == FunctionClassification.CLASS_MEMBER && + (!(parentNodeId == ASTNodeID.FunctionCallID || parentNodeId == ASTNodeID.MemberAccessExpressionID)); if (generateClosure) { getEmitter().emitClosureStart(); http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/ddf557d2/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java ---------------------------------------------------------------------- diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java index 7c9fa2f..b5a7de5 100644 --- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java +++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSExpressions.java @@ -773,7 +773,7 @@ public class TestFlexJSExpressions extends TestGoogExpressions "public class B {public function b() { function c(f:Function):void {}; function d():void {}; c(d); }}", IFunctionNode.class, WRAP_LEVEL_PACKAGE); asBlockWalker.visitFunction(node); - assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n var self = this;\n function c(f) {\n };\n function d() {\n };\n c(org.apache.flex.utils.Language.closure(d, this, 'd'));\n}"); + assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n var self = this;\n function c(f) {\n };\n function d() {\n };\n c(d);\n}"); } @Test @@ -783,7 +783,7 @@ public class TestFlexJSExpressions extends TestGoogExpressions "public class B {public function b() { function c(s:String, f:Function):void {}; function d():void {}; c('foo', d); }}", IFunctionNode.class, WRAP_LEVEL_PACKAGE); asBlockWalker.visitFunction(node); - assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n var self = this;\n function c(s, f) {\n };\n function d() {\n };\n c('foo', org.apache.flex.utils.Language.closure(d, this, 'd'));\n}"); + assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n var self = this;\n function c(s, f) {\n };\n function d() {\n };\n c('foo', d);\n}"); } @Test @@ -793,7 +793,7 @@ public class TestFlexJSExpressions extends TestGoogExpressions "public class B {public function b() { c('foo', d); function c(s:String, f:Function):void {}; function d():void {};}}", IFunctionNode.class, WRAP_LEVEL_PACKAGE); asBlockWalker.visitFunction(node); - assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n var self = this;\n function c(s, f) {\n };\n function d() {\n };\n c('foo', org.apache.flex.utils.Language.closure(d, this, 'd'));\n \n}"); + assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n var self = this;\n function c(s, f) {\n };\n function d() {\n };\n c('foo', d);\n \n}"); } @Test @@ -803,7 +803,27 @@ public class TestFlexJSExpressions extends TestGoogExpressions "public class B {public function b() { function d():void {}; c('foo', d); } public function c(s:String, f:Function):void {};}", IFunctionNode.class, WRAP_LEVEL_PACKAGE); asBlockWalker.visitFunction(node); - assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n var self = this;\n function d() {\n };\n this.c('foo', org.apache.flex.utils.Language.closure(d, this, 'd'));\n}"); + assertOut("/**\n * @export\n */\nB.prototype.b = function() {\n var self = this;\n function d() {\n };\n this.c('foo', d);\n}"); + } + + @Test + public void testArgumentAsArgument() + { + IFunctionNode node = (IFunctionNode) getNode( + "public class B {public function b(ff:Function) { function c(f:Function):void {}; c(ff); }}", + IFunctionNode.class, WRAP_LEVEL_PACKAGE); + asBlockWalker.visitFunction(node); + assertOut("/**\n * @export\n * @param {Function} ff\n */\nB.prototype.b = function(ff) {\n var self = this;\n function c(f) {\n };\n c(ff);\n}"); + } + + @Test + public void testArgumentAsArgumentInStatic() + { + IFunctionNode node = (IFunctionNode) getNode( + "public class B {public static function b(ff:Function) { function c(f:Function):void {}; c(ff); }}", + IFunctionNode.class, WRAP_LEVEL_PACKAGE); + asBlockWalker.visitFunction(node); + assertOut("/**\n * @export\n * @param {Function} ff\n */\nB.b = function(ff) {\n function c(f) {\n };\n c(ff);\n}"); } @Test