Skip to content

Commit

Permalink
Correctly indent multiline comments when retainLines: true (#12260)
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-craig committed Oct 27, 2020
1 parent 5b48f40 commit 87a3052
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/babel-generator/src/printer.js
Expand Up @@ -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)}`);
}
Expand Down
@@ -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 {}
}
@@ -0,0 +1,3 @@
{
"retainLines": true
}
@@ -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 {}
}

0 comments on commit 87a3052

Please sign in to comment.