You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by jo...@apache.org on 2016/04/06 01:56:46 UTC

[28/33] git commit: [flex-falcon] [refs/heads/develop] - source maps for chained variables, and some expanded tests for variables in general

source maps for chained variables, and some expanded tests for variables in general


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

Branch: refs/heads/develop
Commit: 799f906953c9be6bb909001dda96a46551736053
Parents: 7e47c2d
Author: Josh Tynjala <jo...@apache.org>
Authored: Fri Apr 1 16:21:44 2016 -0700
Committer: Josh Tynjala <jo...@apache.org>
Committed: Fri Apr 1 16:21:44 2016 -0700

----------------------------------------------------------------------
 .../js/sourcemaps/TestSourceMapStatements.java  | 62 +++++++++++++++++---
 .../flex/compiler/codegen/js/IJSEmitter.java    |  1 +
 .../compiler/internal/codegen/js/JSEmitter.java | 17 ++++++
 .../codegen/js/jx/VarDeclarationEmitter.java    |  4 ++
 4 files changed, 77 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/799f9069/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java
----------------------------------------------------------------------
diff --git a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java
index edb4ed7..713c3cf 100644
--- a/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java
+++ b/compiler.jx.tests/src/org/apache/flex/compiler/internal/codegen/js/sourcemaps/TestSourceMapStatements.java
@@ -20,8 +20,9 @@ public class TestSourceMapStatements extends SourceMapTestBase
                 IVariableNode.class);
         asBlockWalker.visitVariable(node);
         //var /** @type {*} */ a
-        assertMapping(node, 0, 0, 0, 0, 0, 4);
-        assertMapping(node, 0, 5, 0, 4, 0, 21);
+        assertMapping(node, 0, 0, 0, 0, 0, 4);   // var
+        assertMapping(node, 0, 4, 0, 21, 0, 22); // a
+        assertMapping(node, 0, 5, 0, 4, 0, 21);  // (type)
     }
 
     @Test
@@ -31,8 +32,9 @@ public class TestSourceMapStatements extends SourceMapTestBase
                 IVariableNode.class);
         asBlockWalker.visitVariable(node);
         //var /** @type {number} */ a
-        assertMapping(node, 0, 0, 0, 0, 0, 4);
-        assertMapping(node, 0, 5, 0, 4, 0, 26);
+        assertMapping(node, 0, 0, 0, 0, 0, 4);   // var
+        assertMapping(node, 0, 4, 0, 26, 0, 27); // a
+        assertMapping(node, 0, 5, 0, 4, 0, 26);  // :int
     }
 
     @Test
@@ -42,9 +44,55 @@ public class TestSourceMapStatements extends SourceMapTestBase
                 IVariableNode.class);
         asBlockWalker.visitVariable(node);
         //var /** @type {number} */ a = 42
-        assertMapping(node, 0, 0, 0, 0, 0, 4);
-        assertMapping(node, 0, 5, 0, 4, 0, 26);
-        assertMapping(node, 0, 9, 0, 27, 0, 30);
+        assertMapping(node, 0, 0, 0, 0, 0, 4);    // var
+        assertMapping(node, 0, 4, 0, 26, 0, 27);  // a
+        assertMapping(node, 0, 5, 0, 4, 0, 26);   // :int
+        assertMapping(node, 0, 9, 0, 27, 0, 30);  // =
+        assertMapping(node, 0, 12, 0, 30, 0, 32); // 42
+    }
+
+    @Test
+    public void testVarDeclaration_withTypeAssignedValueComplex()
+    {
+        IVariableNode node = (IVariableNode) getNode(
+                "class A { public function b():void { var a:Foo = new Foo(42, 'goo');}} class Foo {}", IVariableNode.class, WRAP_LEVEL_PACKAGE);
+        asBlockWalker.visitVariable(node);
+        //var /** @type {Foo} */ a = new Foo(42, 'goo')
+        assertMapping(node, 0, 0, 0, 0, 0, 4);    // var
+        assertMapping(node, 0, 4, 0, 23, 0, 24);  // a
+        assertMapping(node, 0, 5, 0, 4, 0, 23);   // :Foo
+        assertMapping(node, 0, 9, 0, 24, 0, 27);  // =
+        assertMapping(node, 0, 12, 0, 27, 0, 31);  // new
+        assertMapping(node, 0, 16, 0, 31, 0, 34);  // Foo
+        assertMapping(node, 0, 19, 0, 34, 0, 35);  // (
+        assertMapping(node, 0, 20, 0, 35, 0, 37);  // 42
+        assertMapping(node, 0, 22, 0, 37, 0, 39);  // ,
+        assertMapping(node, 0, 24, 0, 39, 0, 44);  // 'goo'
+        assertMapping(node, 0, 29, 0, 44, 0, 45);  // )
+    }
+
+    @Test
+    public void testVarDeclaration_withList()
+    {
+        IVariableNode node = (IVariableNode) getNode(
+                "var a:int = 4, b:int = 11, c:int = 42;", IVariableNode.class);
+        asBlockWalker.visitVariable(node);
+        //var /** @type {number} */ a = 4, /** @type {number} */ b = 11, /** @type {number} */ c = 42
+        assertMapping(node, 0, 0, 0, 0, 0, 4);    // var
+        assertMapping(node, 0, 4, 0, 26, 0, 27);  // a
+        assertMapping(node, 0, 5, 0, 4, 0, 26);   // :int
+        assertMapping(node, 0, 9, 0, 27, 0, 30);  // =
+        assertMapping(node, 0, 12, 0, 30, 0, 31); // 4
+        assertMapping(node, 0, 13, 0, 31, 0, 33); // ,
+        assertMapping(node, 0, 15, 0, 55, 0, 56); // b
+        assertMapping(node, 0, 16, 0, 33, 0, 55); // :int
+        assertMapping(node, 0, 20, 0, 56, 0, 59); // =
+        assertMapping(node, 0, 23, 0, 59, 0, 61); // 11
+        assertMapping(node, 0, 25, 0, 61, 0, 63); // ,
+        assertMapping(node, 0, 27, 0, 85, 0, 86); // c
+        assertMapping(node, 0, 28, 0, 63, 0, 85); // :int
+        assertMapping(node, 0, 32, 0, 86, 0, 89); // =
+        assertMapping(node, 0, 35, 0, 89, 0, 91); // 42
     }
 
     protected IBackend createBackend()

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/799f9069/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
index 6dcea99..56a0c05 100644
--- a/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/codegen/js/IJSEmitter.java
@@ -47,6 +47,7 @@ public interface IJSEmitter extends IASEmitter
     void startMapping(ISourceLocation node);
     void startMapping(ISourceLocation node, int startOffset);
     void startMapping(ISourceLocation node, int line, int column);
+    void startMapping(ISourceLocation node, ISourceLocation previousNode, ISourceLocation nextNode);
     
     void endMapping(ISourceLocation node);
     void pushSourceMapName(ISourceLocation node);

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/799f9069/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
----------------------------------------------------------------------
diff --git a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
index 5f5b816..71c7d6e 100644
--- a/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
+++ b/compiler.jx/src/org/apache/flex/compiler/internal/codegen/js/JSEmitter.java
@@ -639,6 +639,23 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
     {
         startMapping(node, node.getLine(), node.getColumn() + startOffset);
     }
+
+    public void startMapping(ISourceLocation node, ISourceLocation previousNode, ISourceLocation nextNode)
+    {
+        if(previousNode.getLine() == nextNode.getLine())
+        {
+            //start at the end of the previous node
+            startMapping(node, previousNode.getLine(), previousNode.getColumn() + previousNode.getAbsoluteEnd() - previousNode.getAbsoluteStart());
+        }
+        else
+        {
+            //fill the rest of the line with the previous node
+            startMapping(node, previousNode.getLine(), previousNode.getColumn() + previousNode.getAbsoluteEnd() - previousNode.getAbsoluteStart());
+            endMapping(node);
+            //fill the beginning of the line with the next node
+            startMapping(node, nextNode.getLine(), 0);
+        }
+    }
     
     public void startMapping(ISourceLocation node, int line, int column)
     {

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/799f9069/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 159a4f0..0cbb60a 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
@@ -98,7 +98,11 @@ public class VarDeclarationEmitter extends JSSubEmitter implements
                 IASNode child = node.getChild(i);
                 if (child instanceof ChainedVariableNode)
                 {
+                    getEmitter().startMapping(node,
+                            node.getChild(i - 1),
+                            child);
                     writeToken(ASEmitterTokens.COMMA);
+                    getEmitter().endMapping(node);
                     fjs.emitVarDeclaration((IVariableNode) child);
                 }
             }