Fix formatter's processChildNodes (#48921)

processChildNodes needs to skip processing when the node array is
outside the target range, just like processChildNode already does for a
single node.

Fixes #48006
This commit is contained in:
Nathan Shively-Sanders 2022-05-02 12:50:24 -07:00 committed by GitHub
parent 63a941dc2a
commit e73d755668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 2 deletions

View File

@ -778,6 +778,13 @@ namespace ts.formatting {
let listDynamicIndentation = parentDynamicIndentation;
let startLine = parentStartLine;
// node range is outside the target range - do not dive inside
if (!rangeOverlapsWithStartEnd(originalRange, nodes.pos, nodes.end)) {
if (nodes.end < originalRange.pos) {
formattingScanner.skipToEndOf(nodes);
}
return;
}
if (listStartToken !== SyntaxKind.Unknown) {
// introduce a new indentation scope for lists (including list start and end tokens)

View File

@ -12,7 +12,7 @@ namespace ts.formatting {
readEOFTokenRange(): TextRangeWithKind;
getCurrentLeadingTrivia(): TextRangeWithKind[] | undefined;
lastTrailingTriviaWasNewLine(): boolean;
skipToEndOf(node: Node): void;
skipToEndOf(node: Node | NodeArray<Node>): void;
skipToStartOf(node: Node): void;
}
@ -286,7 +286,7 @@ namespace ts.formatting {
return tokenInfo;
}
function skipToEndOf(node: Node): void {
function skipToEndOf(node: Node | NodeArray<Node>): void {
scanner.setTextPos(node.end);
savedPos = scanner.getStartPos();
lastScanAction = undefined;

View File

@ -0,0 +1,9 @@
/// <reference path='fourslash.ts' />
//// /*2*/const x = f('aa/*1*/a').x()
goTo.marker('1');
edit.paste("bb");
format.document();
goTo.marker('2');
verify.currentLineContentIs("const x = f('aabba').x()");