fix(30003): formatter deletes comment after trailing comma (#49168)

Co-authored-by: TRCYX <trcyxs@gmail.com>
This commit is contained in:
TRCYX
2022-05-27 10:09:52 -07:00
committed by GitHub
co-authored by TRCYX
parent 757a3acbde
commit 38631e6412
5 changed files with 35 additions and 5 deletions
+3 -5
View File
@@ -836,11 +836,9 @@ namespace ts.formatting {
if (listEndToken !== SyntaxKind.Unknown && formattingScanner.isOnToken() && formattingScanner.getStartPos() < originalRange.end) {
let tokenInfo: TokenInfo | undefined = formattingScanner.readTokenInfo(parent);
if (tokenInfo.token.kind === SyntaxKind.CommaToken && isCallLikeExpression(parent)) {
const commaTokenLine = sourceFile.getLineAndCharacterOfPosition(tokenInfo.token.pos).line;
if (startLine !== commaTokenLine) {
formattingScanner.advance();
tokenInfo = formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(parent) : undefined;
}
// consume the comma
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent);
tokenInfo = formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(parent) : undefined;
}
// consume the list end token only if it is still belong to the parent
@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts"/>
////foo(
//// 1, /* comment */ );
format.document();
verify.currentFileContentIs(`foo(
1, /* comment */);`);
@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts"/>
////new Foo(1
////, /* comment */ );
format.document();
verify.currentFileContentIs(`new Foo(1
, /* comment */);`);
@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts"/>
////new Foo(1,
//// /* comment */ );
format.document();
verify.currentFileContentIs(`new Foo(1,
/* comment */);`);
@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts"/>
////new Foo(1, /* comment */
//// );
format.document();
verify.currentFileContentIs(`new Foo(1, /* comment */
);`);