generator: avoid redundant source map mappings

This commit is contained in:
Sebastian McKenzie
2014-11-09 12:03:47 +11:00
parent aedc013ab8
commit b84cb1828b

View File

@@ -1,6 +1,7 @@
module.exports = SourceMap;
var sourceMap = require("source-map");
var t = require("../types");
function SourceMap(position, opts, code) {
this.position = position;
@@ -33,14 +34,22 @@ SourceMap.prototype.mark = function (node, type) {
var map = this.map;
if (!map) return; // no source map
if (t.isProgram(node) || t.isFile(node)) return; // illegal mapping nodes
var position = this.position;
var generated = {
line: position.line,
column: position.column
};
var original = loc[type];
if (generated.line === original.line && generated.column === original.column) return; // nothing to map
map.addMapping({
source: this.opts.sourceFileName,
generated: {
line: position.line,
column: position.column
},
original: loc[type]
generated: generated,
original: original
});
};