Added support for multiple input source maps to SourceMap object.

The addInput method on the object can be used to add sourcemaps for individual input files.
This commit is contained in:
Arnavion 2015-08-04 10:59:14 -07:00
parent ab15d676d7
commit 87f31ed488

View File

@ -53,6 +53,7 @@ function SourceMap(options) {
orig_line_diff : 0,
dest_line_diff : 0,
});
var orig_maps = Object.create(null);
var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
var generator;
if (orig_map) {
@ -63,9 +64,15 @@ function SourceMap(options) {
sourceRoot : options.root
});
}
function addInput(rawSourceMap) {
var consumer = new MOZ_SourceMap.SourceMapConsumer(rawSourceMap);
orig_maps[consumer.file] = consumer;
}
function add(source, gen_line, gen_col, orig_line, orig_col, name) {
if (orig_map) {
var info = orig_map.originalPositionFor({
var originalMap = orig_maps[source] || orig_map;
if (originalMap) {
var info = originalMap.originalPositionFor({
line: orig_line,
column: orig_col
});
@ -77,6 +84,7 @@ function SourceMap(options) {
orig_col = info.column;
name = info.name || name;
}
generator.addMapping({
generated : { line: gen_line + options.dest_line_diff, column: gen_col },
original : { line: orig_line + options.orig_line_diff, column: orig_col },
@ -85,6 +93,7 @@ function SourceMap(options) {
});
}
return {
addInput : addInput,
add : add,
get : function() { return generator },
toString : function() { return JSON.stringify(generator.toJSON()); }