mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
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:
parent
63a941dc2a
commit
e73d755668
@ -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)
|
||||
|
||||
@ -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;
|
||||
|
||||
9
tests/cases/fourslash/formatAfterPasteInString.ts
Normal file
9
tests/cases/fourslash/formatAfterPasteInString.ts
Normal 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()");
|
||||
Loading…
x
Reference in New Issue
Block a user