flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject git commit: [flex-falcon] [refs/heads/develop] - FLEX-35060 fix use of 'self'
Date Fri, 18 Nov 2016 22:56:03 GMT
Repository: flex-falcon
Updated Branches:
  refs/heads/develop 2b6e4d690 -> b41d40959


FLEX-35060 fix use of 'self'


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/b41d4095
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/b41d4095
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/b41d4095

Branch: refs/heads/develop
Commit: b41d4095987fc823421909e12b2964f3967f5e59
Parents: 2b6e4d6
Author: Alex Harui <aharui@apache.org>
Authored: Fri Nov 18 14:55:55 2016 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Nov 18 14:55:55 2016 -0800

----------------------------------------------------------------------
 .../internal/codegen/js/jx/IdentifierEmitter.java     | 11 +++++++++++
 .../internal/codegen/js/flexjs/TestFlexJSClass.java   |  2 +-
 .../codegen/js/flexjs/TestFlexJSExpressions.java      | 14 ++++++++++++++
 .../resources/flexjs/files/LocalFunction_result.js    |  2 +-
 4 files changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b41d4095/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 7573db4..5a464ad 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
@@ -36,9 +36,11 @@ import org.apache.flex.compiler.internal.codegen.js.utils.EmitterUtils;
 import org.apache.flex.compiler.internal.definitions.AccessorDefinition;
 import org.apache.flex.compiler.internal.definitions.FunctionDefinition;
 import org.apache.flex.compiler.internal.definitions.TypeDefinitionBase;
+import org.apache.flex.compiler.internal.tree.as.FunctionNode;
 import org.apache.flex.compiler.internal.tree.as.NonResolvingIdentifierNode;
 import org.apache.flex.compiler.tree.ASTNodeID;
 import org.apache.flex.compiler.tree.as.IASNode;
+import org.apache.flex.compiler.tree.as.IFunctionNode;
 import org.apache.flex.compiler.tree.as.IFunctionObjectNode;
 import org.apache.flex.compiler.tree.as.IIdentifierNode;
 import org.apache.flex.compiler.tree.as.IMemberAccessExpressionNode;
@@ -211,9 +213,18 @@ public class IdentifierEmitter extends JSSubEmitter implements
                         .getParent().getAncestorOfType(
                                 IFunctionObjectNode.class);
 
+                IFunctionNode functionNode = (IFunctionNode) node
+                .getParent().getAncestorOfType(
+                        IFunctionNode.class);
+                IFunctionDefinition functionDef = null;
+                if (functionNode != null)
+                	functionDef = functionNode.getDefinition();
+
                 startMapping(node);
                 if (functionObjectNode != null)
                     write(JSGoogEmitterTokens.SELF);
+                else if (functionNode != null && functionDef.getFunctionClassification()
== FunctionClassification.LOCAL)
+                    write(JSGoogEmitterTokens.SELF);
                 else
                     write(ASEmitterTokens.THIS);
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b41d4095/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
index da74f36..fcb93e7 100644
--- a/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
+++ b/compiler-jx/src/test/java/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSClass.java
@@ -322,7 +322,7 @@ public class TestFlexJSClass extends TestGoogClass
                 + "public function foo2():String{function bar2(param1:String):String {return
param1 + baz1;}; return bar2('foo');}"
                 + "}");
         asBlockWalker.visitClass(node);
-        assertOut("/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n
* @export\n * @type {string}\n */\norg.apache.flex.B.prototype.baz1;\n\n\n/**\n * @export\n
* @return {string}\n */\norg.apache.flex.B.prototype.foo1 = function() {\n  var self = this;\n
 function bar1() {\n    return this.baz1;\n  };\n  return bar1();\n};\n\n\n/**\n * @export\n
* @return {string}\n */\norg.apache.flex.B.prototype.foo2 = function() {\n  var self = this;\n
 function bar2(param1) {\n    return param1 + this.baz1;\n  };\n  return bar2('foo');\n};");
+        assertOut("/**\n * @constructor\n */\norg.apache.flex.B = function() {\n};\n\n\n/**\n
* @export\n * @type {string}\n */\norg.apache.flex.B.prototype.baz1;\n\n\n/**\n * @export\n
* @return {string}\n */\norg.apache.flex.B.prototype.foo1 = function() {\n  var self = this;\n
 function bar1() {\n    return self.baz1;\n  };\n  return bar1();\n};\n\n\n/**\n * @export\n
* @return {string}\n */\norg.apache.flex.B.prototype.foo2 = function() {\n  var self = this;\n
 function bar2(param1) {\n    return param1 + self.baz1;\n  };\n  return bar2('foo');\n};");
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b41d4095/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 8873627..273780f 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
@@ -1039,6 +1039,20 @@ public class TestFlexJSExpressions extends TestGoogExpressions
         		  "  var /** @type {Object} */ c = b(a);\n}");
     }
     
+    @Test
+    public void testParametersInInnerFunctions()
+    {
+        IFunctionNode node = (IFunctionNode) getNode(
+                "public var bar:String = baz; public function foo():void { function localFunction():void
{ trace(bar); } localFunction() }",
+                IFunctionNode.class, WRAP_LEVEL_CLASS);
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @export\n */\n" + 
+        		  "FalconTest_A.prototype.foo = function() {\n" +
+        		  "  var self = this;\n" +
+        		  "  function localFunction() {\n    org.apache.flex.utils.Language.trace(self.bar);\n
 };\n" +
+        		  "  localFunction();\n}");
+    }
+    
     @Override
     @Test
     public void testVisitAs()

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/b41d4095/compiler-jx/src/test/resources/flexjs/files/LocalFunction_result.js
----------------------------------------------------------------------
diff --git a/compiler-jx/src/test/resources/flexjs/files/LocalFunction_result.js b/compiler-jx/src/test/resources/flexjs/files/LocalFunction_result.js
index db02d56..957a84a 100644
--- a/compiler-jx/src/test/resources/flexjs/files/LocalFunction_result.js
+++ b/compiler-jx/src/test/resources/flexjs/files/LocalFunction_result.js
@@ -44,7 +44,7 @@ LocalFunction.prototype.myMemberProperty = "got it: ";
 LocalFunction.prototype.myMemberMethod = function(value) {
   var self = this;
   function myLocalFunction(value) {
-    return this.myMemberProperty + value;
+    return self.myMemberProperty + value;
   };
   org.apache.flex.utils.Language.trace("WOW! :: " + myLocalFunction(value + 42));
 };


Mime
View raw message