Pass values directly to avoid object usage.

This commit is contained in:
Logan Smyth 2016-07-05 20:16:12 -07:00
parent abb9618e8c
commit c5a6c5c291
2 changed files with 13 additions and 11 deletions

View File

@ -319,7 +319,8 @@ export default class Buffer {
}
// If there the line is ending, adding a new mapping marker is redundant
if (this.opts.sourceMaps && str[0] !== "\n") this.map.mark(this._position, this._sourcePosition);
if (this.opts.sourceMaps && str[0] !== "\n") this.map.mark(this._position, this._sourcePosition.line,
this._sourcePosition.column, this._sourcePosition.filename);
//
this._position.push(str);

View File

@ -1,4 +1,5 @@
import sourceMap from "source-map";
import type Position from "./position";
/**
* Build a sourcemap.
@ -45,33 +46,33 @@ export default class SourceMap {
* values to insert a mapping to nothing.
*/
mark(position, sourcePos: Object) {
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 && sourcePos.line === null) return;
if (this._lastGenLine !== position.line && line === null) return;
// If this mapping points to the same source location as the last one, we can ignore it since
// the previous one covers it.
if (this._lastGenLine === position.line && this._lastSourceLine === sourcePos.line &&
this._lastSourceColumn === sourcePos.column) {
if (this._lastGenLine === position.line && this._lastSourceLine === line &&
this._lastSourceColumn === column) {
return;
}
this._lastGenLine = position.line;
this._lastSourceLine = sourcePos.line;
this._lastSourceColumn = sourcePos.column;
this._lastSourceLine = line;
this._lastSourceColumn = column;
map.addMapping({
generated: {
line: position.line,
column: position.column
},
source: sourcePos.line == null ? null : sourcePos.filename || this.opts.sourceFileName,
original: sourcePos.line == null ? null : {
line: sourcePos.line,
column: sourcePos.column,
source: line == null ? null : filename || this.opts.sourceFileName,
original: line == null ? null : {
line: line,
column: column,
},
});
}