1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- "use strict";
- function SourceMap(options) {
- options = defaults(options, {
- file : null,
- root : null,
- orig : null,
- orig_line_diff : 0,
- dest_line_diff : 0,
- });
- 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({
- 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()); }
- };
- };
|