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 2019/12/17 16:45:07 UTC

[royale-compiler] branch develop updated: JSWriter: fixed issue where source map creation failed with null exception if relative path reached root drive path on Windows

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 caa0dfd  JSWriter: fixed issue where source map creation failed with null exception if relative path reached root drive path on Windows
caa0dfd is described below

commit caa0dfd234184a4215e50af39cabef81095a4b4b
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Dec 17 08:44:58 2019 -0800

    JSWriter: fixed issue where source map creation failed with null exception if relative path reached root drive path on Windows
---
 .../compiler/internal/codegen/js/JSWriter.java     | 31 ++++++++++++++++------
 .../compiler/internal/codegen/mxml/MXMLWriter.java |  4 +--
 2 files changed, 25 insertions(+), 10 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 376bcba..f47ce7f 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,7 +109,7 @@ public class JSWriter implements IJSWriter
         }
         catch (IOException e)
         {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
         }
 
         if (jsSourceMapOut != null)
@@ -137,9 +137,10 @@ public class JSWriter implements IJSWriter
                 fileName = fileName.replace(".as", ".js");
                 String sourceMap = sourceMapEmitter.emitSourceMap(fileName, sourceMapFilePath, sourceRoot);
                 jsSourceMapOut.write(sourceMap.getBytes("utf8"));
-            } catch (Exception e)
+            }
+            catch (Exception e)
             {
-                e.printStackTrace();
+                e.printStackTrace(System.err);
             }
         }
     }
@@ -150,7 +151,11 @@ public class JSWriter implements IJSWriter
         for (IMappingEmitter.SourceMapMapping mapping : mappings)
         {
             String relativePath = relativize(mapping.sourcePath, relativeToFile.getAbsolutePath());
-            mapping.sourcePath = relativePath;
+            //this shouldn't happen, but if it does, keep the absolute path
+            if (relativePath != null)
+            {
+                mapping.sourcePath = relativePath;
+            }
         }
     }
     
@@ -159,7 +164,6 @@ public class JSWriter implements IJSWriter
         List<IMappingEmitter.SourceMapMapping> mappings = emitter.getSourceMapMappings();
         for (IMappingEmitter.SourceMapMapping mapping : mappings)
         {
-            //prefer forward slash because web browser devtools expect it
             String sourcePath = mapping.sourcePath;
             sourcePath = convertSourcePathToURI(sourcePath);
             mapping.sourcePath = sourcePath;
@@ -168,11 +172,16 @@ public class JSWriter implements IJSWriter
     
     protected String convertSourcePathToURI(String sourcePath)
     {
+        if (sourcePath == null)
+        {
+            return null;
+        }
         File file = new File(sourcePath);
-        if(file.isAbsolute())
+        if (file.isAbsolute())
         {
             sourcePath = "file:///" + sourcePath;
         }
+        //prefer forward slash because web browser devtools expect it
         return sourcePath.replace('\\', '/');
     }
 
@@ -191,8 +200,14 @@ public class JSWriter implements IJSWriter
         currentFile = currentFile.getParentFile();
         while (currentFile != null)
         {
-            String absoluteCurrentFile = currentFile.getAbsolutePath() + File.separator;
-            if(caseInsensitive)
+            String absoluteCurrentFile = currentFile.getAbsolutePath();
+            if (!absoluteCurrentFile.endsWith(File.separator))
+            {
+                //if it's already there don't duplicate it
+                //for instance, a windows drive will be c:\ already
+                absoluteCurrentFile += File.separator;
+            }
+            if (caseInsensitive)
             {
                 absoluteCurrentFile = absoluteCurrentFile.toLowerCase();
             }
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 9e45aaf..0a80240 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
@@ -74,7 +74,7 @@ public class MXMLWriter extends JSWriter
         }
         catch (IOException e)
         {
-            e.printStackTrace();
+            e.printStackTrace(System.err);
         }
 
         if (sourceMapOut != null)
@@ -104,7 +104,7 @@ public class MXMLWriter extends JSWriter
                 sourceMapOut.write(sourceMap.getBytes("utf8"));
             } catch (Exception e)
             {
-                e.printStackTrace();
+                e.printStackTrace(System.err);
             }
         }
     }