From c5a6c5c291b0295973289c2e4a1da9ff0f389e3b Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Tue, 5 Jul 2016 20:16:12 -0700 Subject: [PATCH] Pass values directly to avoid object usage. --- packages/babel-generator/src/buffer.js | 3 ++- packages/babel-generator/src/source-map.js | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/babel-generator/src/buffer.js b/packages/babel-generator/src/buffer.js index 0b691e4be0..d7b24a2b65 100644 --- a/packages/babel-generator/src/buffer.js +++ b/packages/babel-generator/src/buffer.js @@ -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); diff --git a/packages/babel-generator/src/source-map.js b/packages/babel-generator/src/source-map.js index 5987e75c44..36bfe89097 100644 --- a/packages/babel-generator/src/source-map.js +++ b/packages/babel-generator/src/source-map.js @@ -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, }, }); }