using the original sourcemap as the base
authorCaridy Patino <caridy@gmail.com>
Tue, 11 Nov 2014 19:38:01 +0000 (14:38 -0500)
committerRichard van Velzen <rvanvelzen1@gmail.com>
Sun, 4 Jan 2015 20:08:29 +0000 (21:08 +0100)
* Creates a new SourceMapGenerator based on a SourceMapConsumer:
  https://github.com/mozilla/source-map#sourcemapgeneratorfromsourcemapsourcemapconsumer

lib/sourcemap.js

index 948e3b3..3998e40 100644 (file)
@@ -53,11 +53,16 @@ function SourceMap(options) {
         orig_line_diff : 0,
         dest_line_diff : 0,
     });
-    var generator = new MOZ_SourceMap.SourceMapGenerator({
-        file       : options.file,
-        sourceRoot : options.root
-    });
     var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
+    var generator;
+    if (orig_map) {
+      generator = MOZ_SourceMap.SourceMapGenerator.fromSourceMap(orig_map);
+    } else {
+        generator = new MOZ_SourceMap.SourceMapGenerator({
+            file       : options.file,
+            sourceRoot : options.root
+        });
+    }
     function add(source, gen_line, gen_col, orig_line, orig_col, name) {
         if (orig_map) {
             var info = orig_map.originalPositionFor({
@@ -78,7 +83,7 @@ function SourceMap(options) {
             source    : source,
             name      : name
         });
-    };
+    }
     return {
         add        : add,
         get        : function() { return generator },