properly catch up to comments position - fixes #1384

This commit is contained in:
Sebastian McKenzie 2015-04-29 23:57:43 +01:00
parent 4345f7945b
commit 16c86c25b7

View File

@ -147,15 +147,17 @@ class CodeGenerator {
return print;
}
print(node, parent, opts = {}) {
if (!node) return;
catchUp(node) {
// catch up to this nodes newline if we're behind
if (node.loc && this.format.retainLines) {
if (node.loc && this.format.retainLines && this.buffer.buf) {
while (this.position.line < node.loc.start.line) {
this._push("\n");
}
}
}
print(node, parent, opts = {}) {
if (!node) return;
if (parent && parent._compact) {
node._compact = true;
@ -205,6 +207,8 @@ class CodeGenerator {
this.printLeadingComments(node, parent);
this.catchUp(node);
newline(true);
if (opts.before) opts.before();
@ -336,6 +340,8 @@ class CodeGenerator {
if (skip) return;
this.catchUp(comment);
// whitespace before
this.newline(this.whitespace.getNewlinesBefore(comment));
@ -348,7 +354,6 @@ class CodeGenerator {
}
//
if (comment.type === "Block" && this.format.indent.adjustMultilineComment) {
var offset = comment.loc.start.column;
if (offset) {
@ -365,7 +370,6 @@ class CodeGenerator {
}
//
this._push(val);
// whitespace after