This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git


The following commit(s) were added to refs/heads/develop by this push:
     new fab3428  compiler-jx: absolute paths in source maps are converted to 
file:/// URIs
fab3428 is described below

commit fab34288e76391987c70c7960613ffb33a2bf90f
Author: Josh Tynjala <[email protected]>
AuthorDate: Fri Nov 30 11:42:36 2018 -0800

    compiler-jx: absolute paths in source maps are converted to file:/// URIs
---
 .../compiler/internal/codegen/js/JSWriter.java       | 20 ++++++++++++++++++--
 .../compiler/internal/codegen/mxml/MXMLWriter.java   |  1 +
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
index 47cf0ec..b43c873 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/JSWriter.java
@@ -114,6 +114,7 @@ public class JSWriter implements IJSWriter
                 sourceMapFilePath = sourceMapFile.getAbsolutePath();
                 convertMappingSourcePathsToRelative(emitter, sourceMapFile);
             }
+            convertMappingSourcePathsToURI(emitter);
 
             File compilationUnitFile = new 
File(compilationUnit.getAbsoluteFilename());
             ISourceMapEmitter sourceMapEmitter = 
backend.createSourceMapEmitter(emitter);
@@ -136,11 +137,26 @@ public class JSWriter implements IJSWriter
         for (IMappingEmitter.SourceMapMapping mapping : mappings)
         {
             String relativePath = relativize(mapping.sourcePath, 
relativeToFile.getAbsolutePath());
-            //prefer forward slash
-            relativePath = relativePath.replace('\\', '/');
             mapping.sourcePath = relativePath;
         }
     }
+    
+    protected void convertMappingSourcePathsToURI(IMappingEmitter emitter)
+    {
+        List<IMappingEmitter.SourceMapMapping> mappings = 
emitter.getSourceMapMappings();
+        for (IMappingEmitter.SourceMapMapping mapping : mappings)
+        {
+            //prefer forward slash because web browser devtools expect it
+            String sourcePath = mapping.sourcePath;
+            File file = new File(sourcePath);
+            if(file.isAbsolute())
+            {
+                sourcePath = "file:///" + sourcePath;
+            }
+            sourcePath = sourcePath.replace('\\', '/');
+            mapping.sourcePath = sourcePath;
+        }
+    }
 
     //if we ever support Java 7, the java.nio.file.Path relativize() method
     //should be able to replace this method
diff --git 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLWriter.java
 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLWriter.java
index 6274d53..6ecf661 100644
--- 
a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLWriter.java
+++ 
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/mxml/MXMLWriter.java
@@ -87,6 +87,7 @@ public class MXMLWriter extends JSWriter
                 sourceMapFilePath = sourceMapFile.getAbsolutePath();
                 convertMappingSourcePathsToRelative((IMappingEmitter) 
mxmlEmitter, sourceMapFile);
             }
+            convertMappingSourcePathsToURI((IMappingEmitter) mxmlEmitter);
 
             File compilationUnitFile = new 
File(compilationUnit.getAbsoluteFilename());
             ISourceMapEmitter sourceMapEmitter = 
backend.createSourceMapEmitter((IMappingEmitter) mxmlEmitter);

Reply via email to