12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- "use strict";
- function SourceMap(options) {
- options = defaults(options, {
- file : null,
- root : null,
- orig : null,
- 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);
- if (orig_map && Array.isArray(options.orig.sources)) {
- orig_map._sources.toArray().forEach(function(source) {
- var sourceContent = orig_map.sourceContentFor(source, true);
- if (sourceContent) {
- generator.setSourceContent(source, sourceContent);
- }
- });
- }
- function add(source, gen_line, gen_col, orig_line, orig_col, name) {
- if (orig_map) {
- var 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()); }
- };
- };
|