diff --git a/packages/babel-generator/src/printer.js b/packages/babel-generator/src/printer.js index 83a0321a0a70..1653d070444d 100644 --- a/packages/babel-generator/src/printer.js +++ b/packages/babel-generator/src/printer.js @@ -612,7 +612,7 @@ export default class Printer { const indentSize = Math.max( this._getIndent().length, - this._buf.getCurrentColumn(), + this.format.retainLines ? 0 : this._buf.getCurrentColumn(), ); val = val.replace(/\n(?!$)/g, `\n${" ".repeat(indentSize)}`); } diff --git a/packages/babel-generator/test/fixtures/comments/multi-comment-with-retainlines-option/input.js b/packages/babel-generator/test/fixtures/comments/multi-comment-with-retainlines-option/input.js new file mode 100644 index 000000000000..2aff8b2e73dd --- /dev/null +++ b/packages/babel-generator/test/fixtures/comments/multi-comment-with-retainlines-option/input.js @@ -0,0 +1,15 @@ +var foo = "this is a long string"; + +/** + * this is comment + */ +class Bar {} + +{ + const foo = "this is a really long line of text. this is a really long line of text."; + + /** + * Example + */ + class A {} +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/comments/multi-comment-with-retainlines-option/options.json b/packages/babel-generator/test/fixtures/comments/multi-comment-with-retainlines-option/options.json new file mode 100644 index 000000000000..97925bbcb61b --- /dev/null +++ b/packages/babel-generator/test/fixtures/comments/multi-comment-with-retainlines-option/options.json @@ -0,0 +1,3 @@ +{ + "retainLines": true +} diff --git a/packages/babel-generator/test/fixtures/comments/multi-comment-with-retainlines-option/output.js b/packages/babel-generator/test/fixtures/comments/multi-comment-with-retainlines-option/output.js new file mode 100644 index 000000000000..2aff8b2e73dd --- /dev/null +++ b/packages/babel-generator/test/fixtures/comments/multi-comment-with-retainlines-option/output.js @@ -0,0 +1,15 @@ +var foo = "this is a long string"; + +/** + * this is comment + */ +class Bar {} + +{ + const foo = "this is a really long line of text. this is a really long line of text."; + + /** + * Example + */ + class A {} +} \ No newline at end of file