Switch from undefined guard to asserts

In both fixSpelling and getSuggestionForNonexistentSymbol
This commit is contained in:
Nathan Shively-Sanders 2017-11-01 10:33:24 -07:00
parent 405d8cf8eb
commit a6a5b85b52
2 changed files with 6 additions and 7 deletions

View file

@ -15062,12 +15062,9 @@ 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) => {
// NOTE: `name` from the callback is supposed to === the outer `name`, but is undefined in some cases
if (name === undefined) {
return undefined;
}
function getSuggestionForNonexistentSymbol(location: Node, outerName: __String, meaning: SymbolFlags): string {
const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, (symbols, name, meaning) => {
Debug.assert(name !== undefined, "name should always be defined, and equal to " + 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, "name should be defined");
suggestion = checker.getSuggestionForNonexistentSymbol(node, name, convertSemanticMeaningToSymbolFlags(meaning));
}
if (suggestion) {
return [{