Skip to content

Commit 20a6be6

Browse files
author
Andy
authored
Clarify assumptions in verifyImportFixAtPosition (microsoft#21899)
1 parent 7a6a067 commit 20a6be6

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/harness/fourslash.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,12 +2549,14 @@ Actual: ${stringify(fullActual)}`);
25492549
}
25502550

25512551
public verifyImportFixAtPosition(expectedTextArray: string[], errorCode?: number) {
2552-
const ranges = this.getRanges().filter(r => r.fileName === this.activeFile.fileName);
2552+
const { fileName } = this.activeFile;
2553+
const ranges = this.getRanges().filter(r => r.fileName === fileName);
25532554
if (ranges.length !== 1) {
25542555
this.raiseError("Exactly one range should be specified in the testfile.");
25552556
}
2557+
const range = ts.first(ranges);
25562558

2557-
const codeFixes = this.getCodeFixes(this.activeFile.fileName, errorCode);
2559+
const codeFixes = this.getCodeFixes(fileName, errorCode);
25582560

25592561
if (codeFixes.length === 0) {
25602562
if (expectedTextArray.length !== 0) {
@@ -2564,11 +2566,14 @@ Actual: ${stringify(fullActual)}`);
25642566
}
25652567

25662568
const actualTextArray: string[] = [];
2567-
const scriptInfo = this.languageServiceAdapterHost.getScriptInfo(codeFixes[0].changes[0].fileName);
2569+
const scriptInfo = this.languageServiceAdapterHost.getScriptInfo(fileName);
25682570
const originalContent = scriptInfo.content;
25692571
for (const codeFix of codeFixes) {
2570-
this.applyEdits(codeFix.changes[0].fileName, codeFix.changes[0].textChanges, /*isFormattingEdit*/ false);
2571-
const text = this.rangeText(ranges[0]);
2572+
ts.Debug.assert(codeFix.changes.length === 1);
2573+
const change = ts.first(codeFix.changes);
2574+
ts.Debug.assert(change.fileName === fileName);
2575+
this.applyEdits(change.fileName, change.textChanges, /*isFormattingEdit*/ false);
2576+
const text = this.rangeText(range);
25722577
actualTextArray.push(text);
25732578
scriptInfo.updateContent(originalContent);
25742579
}

0 commit comments

Comments
 (0)