Skip to content

Commit 9b36e11

Browse files
authored
Merge pull request microsoft#19039 from Microsoft/guard-name-in-getSuggestionForNonexistentSymbol
In getSuggestionForNonexistentSymbol, guard name against undefined
2 parents 62eeb72 + c6f343e commit 9b36e11

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/compiler/checker.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15344,9 +15344,10 @@ namespace ts {
1534415344
return suggestion && symbolName(suggestion);
1534515345
}
1534615346

15347-
function getSuggestionForNonexistentSymbol(location: Node, name: __String, meaning: SymbolFlags): string {
15348-
const result = resolveNameHelper(location, name, meaning, /*nameNotFoundMessage*/ undefined, name, /*isUse*/ false, (symbols, name, meaning) => {
15349-
// `name` from the callback === the outer `name`
15347+
function getSuggestionForNonexistentSymbol(location: Node, outerName: __String, meaning: SymbolFlags): string {
15348+
Debug.assert(outerName !== undefined, "outername should always be defined");
15349+
const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, (symbols, name, meaning) => {
15350+
Debug.assertEqual(outerName, name, "name should equal outerName");
1535015351
const symbol = getSymbol(symbols, name, meaning);
1535115352
// Sometimes the symbol is found when location is a return type of a function: `typeof x` and `x` is declared in the body of the function
1535215353
// So the table *contains* `x` but `x` isn't actually in scope.

src/services/codefixes/fixSpelling.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ namespace ts.codefix {
2222
}
2323
else {
2424
const meaning = getMeaningFromLocation(node);
25-
suggestion = checker.getSuggestionForNonexistentSymbol(node, getTextOfNode(node), convertSemanticMeaningToSymbolFlags(meaning));
25+
const name = getTextOfNode(node);
26+
Debug.assert(name !== undefined, "name should be defined");
27+
suggestion = checker.getSuggestionForNonexistentSymbol(node, name, convertSemanticMeaningToSymbolFlags(meaning));
2628
}
2729
if (suggestion) {
2830
return [{

0 commit comments

Comments
 (0)