Skip to content

Commit e3bfec5

Browse files
committed
Handle when advancing past , of call expression moves past endPos of formatting
Fixes #26513
1 parent 54a5be1 commit e3bfec5

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/services/formatting/formatting.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,17 +753,17 @@ namespace ts.formatting {
753753

754754
const listEndToken = getCloseTokenForOpenToken(listStartToken);
755755
if (listEndToken !== SyntaxKind.Unknown && formattingScanner.isOnToken()) {
756-
let tokenInfo = formattingScanner.readTokenInfo(parent);
756+
let tokenInfo: TokenInfo | undefined = formattingScanner.readTokenInfo(parent);
757757
if (tokenInfo.token.kind === SyntaxKind.CommaToken && isCallLikeExpression(parent)) {
758758
formattingScanner.advance();
759-
tokenInfo = formattingScanner.readTokenInfo(parent);
759+
tokenInfo = formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(parent) : undefined;
760760
}
761761

762762
// consume the list end token only if it is still belong to the parent
763763
// there might be the case when current token matches end token but does not considered as one
764764
// function (x: function) <--
765765
// without this check close paren will be interpreted as list end token for function expression which is wrong
766-
if (tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) {
766+
if (tokenInfo && tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) {
767767
// consume list end token
768768
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent);
769769
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <reference path="fourslash.ts"/>
2+
////export const strong: StrongParser = verify(fmap(build(() =>
3+
//// /*start*/surround('**', compress(some(union([inline]), '**')), '**')),/*end*/
4+
//// ns => [html('strong', ns)]
5+
////), ([el]) => hasTightStartText(el));
6+
7+
format.selection("start", "end");

0 commit comments

Comments
 (0)