Make the 'catchUp' call implicit to source location updates.

This commit is contained in:
Logan Smyth 2016-07-02 15:31:30 -07:00
parent 3680d10b6f
commit d6b1e36d49
4 changed files with 14 additions and 17 deletions

View File

@ -37,14 +37,10 @@ export default class Buffer {
buf: string;
last: string;
/**
* Description
*/
catchUp(node: Object) {
_catchUp(){
// catch up to this nodes newline if we're behind
if (node.loc && this.format.retainLines && this.buf) {
while (this.getCurrentLine() < node.loc.start.line) {
if (this.format.retainLines && this._sourcePosition.line !== null) {
while (this.getCurrentLine() < this._sourcePosition.line) {
this.push("\n");
}
}
@ -276,6 +272,8 @@ export default class Buffer {
this._sourcePosition.line = pos ? pos.line : null;
this._sourcePosition.column = pos ? pos.column : null;
this._sourcePosition.filename = loc && loc.filename || null;
this._catchUp();
}
/**
@ -283,7 +281,7 @@ export default class Buffer {
*/
withSource(prop: string, loc: Location, cb: () => void) {
if (!this.opts.sourceMaps) return cb();
if (!this.opts.sourceMaps && !this.format.retainLines) return cb();
// Use the call stack to manage a stack of "source location" data.
let originalLine = this._sourcePosition.line;

View File

@ -45,8 +45,6 @@ export default class Printer extends Buffer {
this.printLeadingComments(node, parent);
this.catchUp(node);
this._printNewline(true, node, parent, opts);
if (opts.before) opts.before();
@ -264,9 +262,7 @@ export default class Printer extends Buffer {
}
// Exclude comments from source mappings since they will only clutter things.
this.withSource(null, null, () => {
this.catchUp(comment);
this.withSource("start", comment.loc, () => {
// whitespace before
this.newline(this.whitespace.getNewlinesBefore(comment));

View File

@ -1,4 +1,6 @@
function foo(l){
return(
l);}
l);
}

View File

@ -1,10 +1,11 @@
function foo(l) {
return (
l);}
l);
}
function foo() {
return (
1 && 2 ||
3);}
3);
}