flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From erikdebr...@apache.org
Subject [5/5] git commit: [flex-falcon] [refs/heads/develop] - In FlexJS 'const' declarations weren't getting emitted as with a 'var' keyword
Date Wed, 01 Jul 2015 15:46:38 GMT
In FlexJS 'const' declarations weren't getting emitted as with a 'var' keyword

Omitting keywords, especially when running in strict mode, won't work out well.

Signed-off-by: Erik de Bruin <erik@ixsoftware.nl>


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

Branch: refs/heads/develop
Commit: e7cc6f5ed866f44e79befce2eae7b21d8b4e5118
Parents: fe8d704
Author: Erik de Bruin <erik@ixsoftware.nl>
Authored: Wed Jul 1 17:45:33 2015 +0200
Committer: Erik de Bruin <erik@ixsoftware.nl>
Committed: Wed Jul 1 17:45:33 2015 +0200

----------------------------------------------------------------------
 .../js/flexjs/TestFlexJSMethodMembers.java      |  8 +++++
 .../codegen/js/flexjs/TestFlexJSStatements.java | 34 ++++++++++++++++++++
 .../codegen/js/flexjs/JSFlexJSEmitter.java      | 13 ++++++++
 .../codegen/js/jx/VarDeclarationEmitter.java    |  5 +++
 4 files changed, 60 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e7cc6f5e/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSMethodMembers.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSMethodMembers.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSMethodMembers.java
index a11ea8d..0ede063 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSMethodMembers.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSMethodMembers.java
@@ -190,6 +190,14 @@ public class TestFlexJSMethodMembers extends TestGoogMethodMembers
         assertOut("/**\n * @expose\n * @param {string} bar\n * @param {number=} baz\n * @return
{number}\n * @override\n */\nFalconTest_A.prototype.foo = function(bar, baz) {\n  baz = typeof
baz !== 'undefined' ? baz : null;\n  return -1;\n}");
     }
 
+    @Test
+    public void testMethod_withConstDeclaration()
+    {
+        IFunctionNode node = getMethod("public function foo():String{const A:String = 'Hello
World'; return A;}");
+        asBlockWalker.visitFunction(node);
+        assertOut("/**\n * @expose\n * @return {string}\n */\nFalconTest_A.prototype.foo
= function() {\n  \n/**\n * @const\n * @type {string}\n */\nvar A = 'Hello World';\n  return
A;\n}");
+    }
+
     @Override
     protected IBackend createBackend()
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e7cc6f5e/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
index 2369ecb..7d8e725 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/flexjs/TestFlexJSStatements.java
@@ -56,6 +56,40 @@ public class TestFlexJSStatements extends TestGoogStatements
     }
 
     //----------------------------------
+    // const declaration
+    //----------------------------------
+
+    @Override
+    @Test
+    public void testConstDeclaration()
+    {
+        IVariableNode node = (IVariableNode) getNode("const a = 42;",
+                IVariableNode.class);
+        asBlockWalker.visitVariable(node);
+        assertOut("\n/**\n * @const\n * @type {*}\n */\nvar a = 42");
+    }
+
+    @Override
+    @Test
+    public void testConstDeclaration_withType()
+    {
+        IVariableNode node = (IVariableNode) getNode("const a:int = 42;",
+                IVariableNode.class);
+        asBlockWalker.visitVariable(node);
+        assertOut("\n/**\n * @const\n * @type {number}\n */\nvar a = 42");
+    }
+
+    @Override
+    @Test
+    public void testConstDeclaration_withList()
+    {
+        IVariableNode node = (IVariableNode) getNode(
+                "const a:int = 4, b:int = 11, c:int = 42;", IVariableNode.class);
+        asBlockWalker.visitVariable(node);
+        assertOut("\n/**\n * @const\n * @type {number}\n */\nvar a = 4, \n/**\n * @const\n
* @type {number}\n */\nb = 11, \n/**\n * @const\n * @type {number}\n */\nc = 42");
+    }
+
+    //----------------------------------
     // for () { }
     //----------------------------------
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e7cc6f5e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
index e1df65a..210ec5f 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/flexjs/JSFlexJSEmitter.java
@@ -174,6 +174,19 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
     }
 
     @Override
+    public void emitMemberKeyword(IDefinitionNode node)
+    {
+        if (node instanceof IFunctionNode)
+        {
+            writeToken(ASEmitterTokens.FUNCTION);
+        }
+        else if (node instanceof IVariableNode)
+        {
+            writeToken(ASEmitterTokens.VAR);
+        }
+    }
+
+    @Override
     public void emitMemberName(IDefinitionNode node)
     {
         write(node.getName());

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/e7cc6f5e/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
index 8b57ea9..ef5be6b 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/jx/VarDeclarationEmitter.java
@@ -65,6 +65,11 @@ public class VarDeclarationEmitter extends JSSubEmitter implements
             fjs.getDocEmitter().emitVarDoc(node, null);
         }
 
+        if (!(node instanceof ChainedVariableNode) && node.isConst())
+        {
+            fjs.emitMemberKeyword(node);
+        }
+
         fjs.emitDeclarationName(node);
         if (!(avnode instanceof IEmbedNode))
             fjs.emitAssignedValue(avnode);


Mime
View raw message