diff --git a/packages/babel/src/generation/index.js b/packages/babel/src/generation/index.js index 6790be88c6..68a6703852 100644 --- a/packages/babel/src/generation/index.js +++ b/packages/babel/src/generation/index.js @@ -456,7 +456,7 @@ class CodeGenerator { // force a newline for line comments when retainLines is set in case the next printed node // doesn't catch up - if (this.format.retainLines && comment.type === "CommentLine") { + if ((this.format.compact || this.format.retainLines) && comment.type === "CommentLine") { val += "\n"; } diff --git a/packages/babel/test/fixtures/generation/compact/options.json b/packages/babel/test/fixtures/generation/compact/options.json new file mode 100644 index 0000000000..eb4e948bfa --- /dev/null +++ b/packages/babel/test/fixtures/generation/compact/options.json @@ -0,0 +1,3 @@ +{ + "compact": true +} diff --git a/packages/babel/test/fixtures/generation/compact/single-line-comment/actual.js b/packages/babel/test/fixtures/generation/compact/single-line-comment/actual.js new file mode 100644 index 0000000000..e2589c7138 --- /dev/null +++ b/packages/babel/test/fixtures/generation/compact/single-line-comment/actual.js @@ -0,0 +1,2 @@ +// foo +bar(); diff --git a/packages/babel/test/fixtures/generation/compact/single-line-comment/expected.js b/packages/babel/test/fixtures/generation/compact/single-line-comment/expected.js new file mode 100644 index 0000000000..e2589c7138 --- /dev/null +++ b/packages/babel/test/fixtures/generation/compact/single-line-comment/expected.js @@ -0,0 +1,2 @@ +// foo +bar();