Drop unneeded condition in SourceMap class.

This commit is contained in:
Logan Smyth 2016-07-05 21:14:30 -07:00
parent 3073c63e58
commit 8379c21939

View File

@ -7,24 +7,18 @@ import type Position from "./position";
export default class SourceMap {
constructor(opts, code) {
this.opts = opts;
this.last = {generated: {}, original: {}};
this._opts = opts;
this._map = new sourceMap.SourceMapGenerator({
file: opts.sourceMapTarget,
sourceRoot: opts.sourceRoot
});
if (opts.sourceMaps) {
this.map = new sourceMap.SourceMapGenerator({
file: opts.sourceMapTarget,
sourceRoot: opts.sourceRoot
if (typeof code === "string") {
this._map.setSourceContent(opts.sourceFileName, code);
} else if (typeof code === "object") {
Object.keys(code).forEach((sourceFileName) => {
this._map.setSourceContent(sourceFileName, code[sourceFileName]);
});
if (typeof code === "string") {
this.map.setSourceContent(opts.sourceFileName, code);
} else if (typeof code === "object") {
Object.keys(code).forEach((sourceFileName) => {
this.map.setSourceContent(sourceFileName, code[sourceFileName]);
});
}
} else {
this.map = null;
}
}
@ -33,12 +27,7 @@ export default class SourceMap {
*/
get() {
let map = this.map;
if (map) {
return map.toJSON();
} else {
return map;
}
return this._map.toJSON();
}
/**
@ -47,9 +36,6 @@ export default class SourceMap {
*/
mark(position: Position, line: number, column: number, filename: ?string) {
let map = this.map;
if (!map) return; // no source map
// Adding an empty mapping at the start of a generated line just clutters the map.
if (this._lastGenLine !== position.line && line === null) return;
@ -64,12 +50,12 @@ export default class SourceMap {
this._lastSourceLine = line;
this._lastSourceColumn = column;
map.addMapping({
this._map.addMapping({
generated: {
line: position.line,
column: position.column
},
source: line == null ? null : filename || this.opts.sourceFileName,
source: line == null ? null : filename || this._opts.sourceFileName,
original: line == null ? null : {
line: line,
column: column,