Remove sideeffectful position mutation.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user