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 2014/10/24 13:30:12 UTC
[20/22] git commit: [flex-falcon] [refs/heads/develop] - Added
'const' emission (ECMA 6) + tests
Added 'const' emission (ECMA 6) + tests
Signed-off-by: Erik de Bruin <er...@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/6961f0f5
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/6961f0f5
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/6961f0f5
Branch: refs/heads/develop
Commit: 6961f0f59e3d8ca7994d4796b1f0db380c6e1a3c
Parents: 9cab2bf
Author: Erik de Bruin <er...@ixsoftware.nl>
Authored: Fri Oct 24 11:49:10 2014 +0200
Committer: Erik de Bruin <er...@ixsoftware.nl>
Committed: Fri Oct 24 11:49:10 2014 +0200
----------------------------------------------------------------------
.../codegen/js/vf2js/TestVF2JSStatements.java | 34 ++++++++++++++++
.../codegen/js/vf2js/JSVF2JSEmitter.java | 42 ++++++++++++++++++++
2 files changed, 76 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6961f0f5/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/vf2js/TestVF2JSStatements.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/vf2js/TestVF2JSStatements.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/vf2js/TestVF2JSStatements.java
index e32a5d2..648666f 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/vf2js/TestVF2JSStatements.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/vf2js/TestVF2JSStatements.java
@@ -76,6 +76,40 @@ public class TestVF2JSStatements extends TestGoogStatements
asBlockWalker.visitVariable(node);
assertOut("var /** @type {Object} */ falconTest_a.ShaderClass");
}
+
+ //----------------------------------
+ // const declaration
+ //----------------------------------
+
+ @Override
+ @Test
+ public void testConstDeclaration()
+ {
+ IVariableNode node = (IVariableNode) getNode("const a = 42;",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("const /** @type {*} */ a = 42");
+ }
+
+ @Override
+ @Test
+ public void testConstDeclaration_withType()
+ {
+ IVariableNode node = (IVariableNode) getNode("const a:int = 42;",
+ IVariableNode.class);
+ asBlockWalker.visitVariable(node);
+ assertOut("const /** @type {number} */ 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("const /** @type {number} */ a = 4, /** @type {number} */ b = 11, /** @type {number} */ c = 42");
+ }
//----------------------------------
// for () { }
http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/6961f0f5/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
index 9b91eb2..0ca8e4b 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/vf2js/JSVF2JSEmitter.java
@@ -256,6 +256,48 @@ public class JSVF2JSEmitter extends JSGoogEmitter implements IJSVF2JSEmitter
}
@Override
+ public void emitVarDeclaration(IVariableNode node)
+ {
+ if (!(node instanceof ChainedVariableNode))
+ {
+ emitMemberKeyword(node);
+ }
+
+ IExpressionNode avnode = node.getAssignedValueNode();
+ if (avnode != null)
+ {
+ IDefinition def = avnode.resolveType(getWalker().getProject());
+
+ String opcode = avnode.getNodeID().getParaphrase();
+ if (opcode != "AnonymousFunction")
+ getDoc().emitVarDoc(node, def);
+ }
+ else
+ {
+ getDoc().emitVarDoc(node, null);
+ }
+
+ emitDeclarationName(node);
+ if (!(avnode instanceof IEmbedNode))
+ emitAssignedValue(avnode);
+
+ if (!(node instanceof ChainedVariableNode))
+ {
+ // check for chained variables
+ int len = node.getChildCount();
+ for (int i = 0; i < len; i++)
+ {
+ IASNode child = node.getChild(i);
+ if (child instanceof ChainedVariableNode)
+ {
+ writeToken(ASEmitterTokens.COMMA);
+ emitVarDeclaration((IVariableNode) child);
+ }
+ }
+ }
+ }
+
+ @Override
public void emitField(IVariableNode node)
{
IDefinition definition = getClassDefinition(node);