aboutsummaryrefslogtreecommitdiff
path: root/lib/sourcemap.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sourcemap.js')
-rw-r--r--lib/sourcemap.js73
1 files changed, 40 insertions, 33 deletions
diff --git a/lib/sourcemap.js b/lib/sourcemap.js
index dcb8e476..2feec45d 100644
--- a/lib/sourcemap.js
+++ b/lib/sourcemap.js
@@ -46,16 +46,15 @@
// a small wrapper around fitzgen's source-map library
function SourceMap(options) {
options = defaults(options, {
- file : null,
- root : null,
- orig : null,
-
- orig_line_diff : 0,
- dest_line_diff : 0,
- });
+ file: null,
+ root: null,
+ orig: null,
+ orig_line_diff: 0,
+ dest_line_diff: 0,
+ }, true);
var generator = new MOZ_SourceMap.SourceMapGenerator({
- file : options.file,
- sourceRoot : options.root
+ file: options.file,
+ sourceRoot: options.root
});
var maps = options.orig && Object.create(null);
if (maps) for (var source in options.orig) {
@@ -68,30 +67,38 @@ function SourceMap(options) {
}
maps[source] = map;
}
-
- function add(source, gen_line, gen_col, orig_line, orig_col, name) {
- var map = maps && maps[source];
- if (map) {
- var info = map.originalPositionFor({
- line: orig_line,
- column: orig_col
+ return {
+ add: function(source, gen_line, gen_col, orig_line, orig_col, name) {
+ var map = maps && maps[source];
+ if (map) {
+ var info = 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({
+ name: name,
+ source: source,
+ generated: {
+ line: gen_line + options.dest_line_diff,
+ column: gen_col
+ },
+ original: {
+ line: orig_line + options.orig_line_diff,
+ column: orig_col
+ }
});
- if (info.source === null) return;
- source = info.source;
- orig_line = info.line;
- orig_col = info.column;
- name = info.name || name;
+ },
+ get: function() {
+ return generator;
+ },
+ toString: function() {
+ return JSON.stringify(generator.toJSON());
}
- 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()); }
};
-};
+}