Correctly indent multiline comments when retainLines: true (#12260)

This commit is contained in:
Ian Craig 2020-10-27 04:46:25 -07:00 committed by GitHub
parent 5b48f40a08
commit 87a30524f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 1 deletions

View File

@ -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)}`);
}

View File

@ -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 {}
}

View File

@ -0,0 +1,3 @@
{
"retainLines": true
}

View File

@ -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 {}
}