File: /home/f/r/e/frenchy/www/french-american.org/current/node_modules/uglyfly-js/lib/SourceMap.js
/***********************************************************************
Copyright 2014 (c) Saair Quaderi <saair.quaderi@gmail.com>
Copyright 2012-2013 (c) Mihai Bazon <mihai.bazon@gmail.com>
UglyflyJS sourcecode can be found here:
https://github.com/quaderi/uglyflyjs
UglyflyJS (by Saair) is a fork of UglifyJS2 (by Mihai Bazon)
Both libraries are released under the BSD 2-Clause License.
***********************************************************************/
/*globals define, module, require */
((typeof define === "function") ? define :
function () { "use strict"; require('./nd').apply(module, arguments); })(
"SourceMap",
[
"defaults"
],
function (defaults) {
"use strict";
// a small wrapper around fitzgen's source-map library
function SourceMap(MOZ_SourceMap, options) {
var orig_map,
generator;
options = defaults(options, {
file: null,
root: null,
orig: null,
orig_line_diff: 0,
dest_line_diff: 0
});
orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
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) {
var info;
if (orig_map) {
info = orig_map.originalPositionFor({
line: orig_line,
column: orig_col
});
if (info.source === null) {
return;
}
source = info.source;
orig_line = info.line;
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
},
source: source,
name: name
});
}
return {
add: add,
get: function () {
return generator;
},
toString: function () {
return JSON.stringify(generator.toJSON());
}
};
}
return SourceMap;
}
);