Merge pull request #19039 from Microsoft/guard-name-in-getSuggestionForNonexistentSymbol

In getSuggestionForNonexistentSymbol, guard name against undefined
This commit is contained in:
Nathan Shively-Sanders
2017-11-07 15:03:26 -08:00
committed by GitHub
2 changed files with 7 additions and 4 deletions

View File

@@ -15344,9 +15344,10 @@ namespace ts {
return suggestion && symbolName(suggestion);
}
function getSuggestionForNonexistentSymbol(location: Node, name: __String, meaning: SymbolFlags): string {
const result = resolveNameHelper(location, name, meaning, /*nameNotFoundMessage*/ undefined, name, /*isUse*/ false, (symbols, name, meaning) => {
// `name` from the callback === the outer `name`
function getSuggestionForNonexistentSymbol(location: Node, outerName: __String, meaning: SymbolFlags): string {
Debug.assert(outerName !== undefined, "outername should always be defined");
const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, (symbols, name, meaning) => {
Debug.assertEqual(outerName, name, "name should equal outerName");
const symbol = getSymbol(symbols, name, meaning);
// 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
// So the table *contains* `x` but `x` isn't actually in scope.

View File

@@ -22,7 +22,9 @@ namespace ts.codefix {
}
else {
const meaning = getMeaningFromLocation(node);
suggestion = checker.getSuggestionForNonexistentSymbol(node, getTextOfNode(node), convertSemanticMeaningToSymbolFlags(meaning));
const name = getTextOfNode(node);
Debug.assert(name !== undefined, "name should be defined");
suggestion = checker.getSuggestionForNonexistentSymbol(node, name, convertSemanticMeaningToSymbolFlags(meaning));
}
if (suggestion) {
return [{