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:22 UTC

[04/33] git commit: [flex-falcon] [refs/heads/develop] - JSEmitter: added addLineToMappings() and removeLineFromMappings() to allow source maps to be adjusted during post processing when lines are added or removed

JSEmitter: added addLineToMappings() and removeLineFromMappings() to allow source maps to be adjusted during post processing when lines are added or removed


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

Branch: refs/heads/develop
Commit: 4b3f7be940ad71c8951394c0723f72335a90feec
Parents: f4af840
Author: Josh Tynjala <jo...@apache.org>
Authored: Wed Mar 23 19:19:33 2016 -0700
Committer: Josh Tynjala <jo...@apache.org>
Committed: Wed Mar 23 19:19:33 2016 -0700

----------------------------------------------------------------------
 .../compiler/internal/codegen/js/JSEmitter.java | 42 ++++++++++++++++++++
 .../codegen/js/flexjs/JSFlexJSEmitter.java      |  7 +++-
 2 files changed, 48 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4b3f7be9/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 e903094..7e29a08 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
@@ -293,4 +293,46 @@ public class JSEmitter extends ASEmitter implements IJSEmitter
         lastMapping = null;
     }
 
+    /**
+     * Adjusts the line numbers saved in the source map when a line should be
+     * added during post processing.
+     *
+     * @param lineIndex
+     */
+    protected void addLineToMappings(int lineIndex)
+    {
+        for (SourceMapMapping mapping : sourceMapMappings)
+        {
+            FilePosition destStartPosition = mapping.destStartPosition;
+            int startLine = destStartPosition.getLine();
+            if(startLine > lineIndex)
+            {
+                mapping.destStartPosition = new FilePosition(startLine + 1, destStartPosition.getColumn());
+                FilePosition destEndPosition = mapping.destEndPosition;
+                mapping.destEndPosition = new FilePosition(destEndPosition.getLine() + 1, destEndPosition.getColumn());
+            }
+        }
+    }
+
+    /**
+     * Adjusts the line numbers saved in the source map when a line should be
+     * removed during post processing.
+     * 
+     * @param lineIndex
+     */
+    protected void removeLineFromMappings(int lineIndex)
+    {
+        for (SourceMapMapping mapping : sourceMapMappings)
+        {
+            FilePosition destStartPosition = mapping.destStartPosition;
+            int startLine = destStartPosition.getLine();
+            if(startLine > lineIndex)
+            {
+                mapping.destStartPosition = new FilePosition(startLine - 1, destStartPosition.getColumn());
+                FilePosition destEndPosition = mapping.destEndPosition;
+                mapping.destEndPosition = new FilePosition(destEndPosition.getLine() - 1, destEndPosition.getColumn());
+            }
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4b3f7be9/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 ee18337..2f5775e 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
@@ -143,8 +143,9 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
         boolean foundLanguage = false;
     	boolean sawRequires = false;
     	boolean stillSearching = true;
-    	for (String line : lines)
+    	for (int i = 0; i < lines.length; i++)
     	{
+            String line = lines[i];
     		if (stillSearching)
     		{
 	            int c = line.indexOf(JSGoogEmitterTokens.GOOG_REQUIRE.getToken());
@@ -158,7 +159,10 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
                     }
 	    			sawRequires = true;
 	    			if (!usedNames.contains(s))
+                    {
+                        removeLineFromMappings(i);
                         continue;
+                    }
 	    		}
 	    		else if (sawRequires)
                 {
@@ -183,6 +187,7 @@ public class JSFlexJSEmitter extends JSGoogEmitter implements IJSFlexJSEmitter
                             appendString.append(ASEmitterTokens.PAREN_CLOSE.getToken());
                             appendString.append(ASEmitterTokens.SEMICOLON.getToken());
                             finalLines.add(appendString.toString());
+                            addLineToMappings(i);
                         }
                     }
                 }