diff --git a/packages/babel-generator/src/printer.ts b/packages/babel-generator/src/printer.ts index c7d71d5a5cb8..70cf22cf6721 100644 --- a/packages/babel-generator/src/printer.ts +++ b/packages/babel-generator/src/printer.ts @@ -823,8 +823,10 @@ class Printer { const lastCommentLine = this._lastCommentLine; if (startLine > 0 && lastCommentLine > 0) { const offset = startLine - lastCommentLine; - this.newline(offset || 1); - return; + if (offset >= 0) { + this.newline(offset || 1); + return; + } } // don't add newlines at the beginning of the file diff --git a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-4363/output.js b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-4363/output.js index 01c0b28d434f..27b56c755aff 100644 --- a/packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-4363/output.js +++ b/packages/babel-plugin-transform-block-scoping/test/fixtures/general/issue-4363/output.js @@ -9,7 +9,8 @@ function WithoutCurlyBraces() { return foo.call(this); } console.log(_this, k); // => undefined - };for (var k in kv) { + }; + for (var k in kv) { _loop(k); } } @@ -25,7 +26,8 @@ function WithCurlyBraces() { return foo.call(this); } console.log(_this2, k); // => 777 - };for (var k in kv) { + }; + for (var k in kv) { _loop2(k); } }