From a6a5b85b522b89d061aaf0baaaaf39103ba0c346 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 1 Nov 2017 10:33:24 -0700 Subject: [PATCH] Switch from undefined guard to asserts In both fixSpelling and getSuggestionForNonexistentSymbol --- src/compiler/checker.ts | 9 +++------ src/services/codefixes/fixSpelling.ts | 4 +++- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 738a484d254..b28ecb082a1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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. diff --git a/src/services/codefixes/fixSpelling.ts b/src/services/codefixes/fixSpelling.ts index ff3bd455291..e5c15ade5a2 100644 --- a/src/services/codefixes/fixSpelling.ts +++ b/src/services/codefixes/fixSpelling.ts @@ -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 [{