You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2018/12/03 22:16:23 UTC

[royale-compiler] branch develop updated: compiler-jx: uses sourceRoot field in source maps for .swc files

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 c6cfd66  compiler-jx: uses sourceRoot field in source maps for .swc files
c6cfd66 is described below

commit c6cfd66fb0e5e51af077399f0454274d43aec965
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Mon Dec 3 14:16:17 2018 -0800

    compiler-jx: uses sourceRoot field in source maps for .swc files
---
 .../compiler/internal/codegen/js/JSWriter.java     | 26 ++++++++++++++++------
 .../compiler/internal/codegen/mxml/MXMLWriter.java |  9 +++++++-
 2 files changed, 27 insertions(+), 8 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 b43c873..0f383a3 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
@@ -109,11 +109,18 @@ public class JSWriter implements IJSWriter
         if (jsSourceMapOut != null)
         {
             String sourceMapFilePath = null;
+            String sourceRoot = null;
             if (sourceMapFile != null)
             {
                 sourceMapFilePath = sourceMapFile.getAbsolutePath();
                 convertMappingSourcePathsToRelative(emitter, sourceMapFile);
             }
+            else
+            {
+                sourceRoot = System.getProperty("user.dir");
+                convertMappingSourcePathsToRelative((IMappingEmitter) emitter, new File(sourceRoot, "test.js.map"));
+                sourceRoot = convertSourcePathToURI(sourceRoot);
+            }
             convertMappingSourcePathsToURI(emitter);
 
             File compilationUnitFile = new File(compilationUnit.getAbsoluteFilename());
@@ -122,7 +129,7 @@ public class JSWriter implements IJSWriter
             {
                 String fileName = compilationUnitFile.getName();
                 fileName = fileName.replace(".as", ".js");
-                String sourceMap = sourceMapEmitter.emitSourceMap(fileName, sourceMapFilePath, null);
+                String sourceMap = sourceMapEmitter.emitSourceMap(fileName, sourceMapFilePath, sourceRoot);
                 jsSourceMapOut.write(sourceMap.getBytes());
             } catch (Exception e)
             {
@@ -148,15 +155,20 @@ public class JSWriter implements IJSWriter
         {
             //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('\\', '/');
+            sourcePath = convertSourcePathToURI(sourcePath);
             mapping.sourcePath = sourcePath;
         }
     }
+    
+    protected String convertSourcePathToURI(String sourcePath)
+    {
+        File file = new File(sourcePath);
+        if(file.isAbsolute())
+        {
+            sourcePath = "file:///" + sourcePath;
+        }
+        return sourcePath.replace('\\', '/');
+    }
 
     //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 6ecf661..580aafe 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
@@ -82,11 +82,18 @@ public class MXMLWriter extends JSWriter
         if (sourceMapOut != null)
         {
             String sourceMapFilePath = null;
+            String sourceRoot = null;
             if (sourceMapFile != null)
             {
                 sourceMapFilePath = sourceMapFile.getAbsolutePath();
                 convertMappingSourcePathsToRelative((IMappingEmitter) mxmlEmitter, sourceMapFile);
             }
+            else
+            {
+                sourceRoot = System.getProperty("user.dir");
+                convertMappingSourcePathsToRelative((IMappingEmitter) mxmlEmitter, new File(sourceRoot, "test.js.map"));
+                sourceRoot = convertSourcePathToURI(sourceRoot);
+            }
             convertMappingSourcePathsToURI((IMappingEmitter) mxmlEmitter);
 
             File compilationUnitFile = new File(compilationUnit.getAbsoluteFilename());
@@ -95,7 +102,7 @@ public class MXMLWriter extends JSWriter
             {
                 String fileName = compilationUnitFile.getName();
                 fileName = fileName.replace(".mxml", ".js");
-                String sourceMap = sourceMapEmitter.emitSourceMap(fileName, sourceMapFilePath, null);
+                String sourceMap = sourceMapEmitter.emitSourceMap(fileName, sourceMapFilePath, sourceRoot);
                 sourceMapOut.write(sourceMap.getBytes());
             } catch (Exception e)
             {