mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(30003): formatter deletes comment after trailing comma (#49168)
Co-authored-by: TRCYX <trcyxs@gmail.com>
This commit is contained in:
@@ -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 */
|
||||
);`);
|
||||
Reference in New Issue
Block a user