Remove sideeffectful position mutation.

This commit is contained in:
Logan Smyth
2016-07-02 12:42:15 -07:00
parent e4da8cfea5
commit 177c092496
3 changed files with 4 additions and 7 deletions

View File

@@ -333,7 +333,7 @@ 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._sourcePosition);
if (this.opts.sourceMaps && str[0] !== "\n") this.map.mark(this.position, this._sourcePosition);
//
this.position.push(str);

View File

@@ -31,7 +31,7 @@ class Generator extends Printer {
this._inForStatementInitCounter = 0;
this.whitespace = new Whitespace(tokens);
this.map = new SourceMap(position, opts, code);
this.map = new SourceMap(opts, code);
}
format: {

View File

@@ -5,8 +5,7 @@ import sourceMap from "source-map";
*/
export default class SourceMap {
constructor(position, opts, code) {
this.position = position;
constructor(opts, code) {
this.opts = opts;
this.last = {generated: {}, original: {}};
@@ -46,12 +45,10 @@ export default class SourceMap {
* values to insert a mapping to nothing.
*/
mark(sourcePos: Object) {
mark(position, sourcePos: Object) {
let map = this.map;
if (!map) return; // no source map
let position = this.position;
// Adding an empty mapping at the start of a generated line just clutters the map.
if (this._lastGenLine !== position.line && sourcePos.line === null) return;