Handle when advancing past , of call expression moves past endPos of formatting

Fixes #26513
This commit is contained in:
Sheetal Nandi 2018-10-12 15:58:31 -07:00
parent 54a5be1860
commit e3bfec5217
2 changed files with 10 additions and 3 deletions

View File

@ -753,17 +753,17 @@ namespace ts.formatting {
const listEndToken = getCloseTokenForOpenToken(listStartToken);
if (listEndToken !== SyntaxKind.Unknown && formattingScanner.isOnToken()) {
let tokenInfo = formattingScanner.readTokenInfo(parent);
let tokenInfo: TokenInfo | undefined = formattingScanner.readTokenInfo(parent);
if (tokenInfo.token.kind === SyntaxKind.CommaToken && isCallLikeExpression(parent)) {
formattingScanner.advance();
tokenInfo = formattingScanner.readTokenInfo(parent);
tokenInfo = formattingScanner.isOnToken() ? formattingScanner.readTokenInfo(parent) : undefined;
}
// consume the list end token only if it is still belong to the parent
// there might be the case when current token matches end token but does not considered as one
// function (x: function) <--
// without this check close paren will be interpreted as list end token for function expression which is wrong
if (tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) {
if (tokenInfo && tokenInfo.token.kind === listEndToken && rangeContainsRange(parent, tokenInfo.token)) {
// consume list end token
consumeTokenAndAdvanceScanner(tokenInfo, parent, listDynamicIndentation, parent);
}

View File

@ -0,0 +1,7 @@
/// <reference path="fourslash.ts"/>
////export const strong: StrongParser = verify(fmap(build(() =>
//// /*start*/surround('**', compress(some(union([inline]), '**')), '**')),/*end*/
//// ns => [html('strong', ns)]
////), ([el]) => hasTightStartText(el));
format.selection("start", "end");