diff --git a/src/babel/generation/index.js b/src/babel/generation/index.js index fa68180c23..ed784c4019 100644 --- a/src/babel/generation/index.js +++ b/src/babel/generation/index.js @@ -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