Skip to content

Commit 2064b74

Browse files
committed
Move checks to a place that makes more sense
1 parent 0612e18 commit 2064b74

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/compiler/checker.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,8 +1781,9 @@ namespace ts {
17811781
nameNotFoundMessage: DiagnosticMessage | undefined,
17821782
nameArg: __String | Identifier | undefined,
17831783
isUse: boolean,
1784-
excludeGlobals = false): Symbol | undefined {
1785-
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol);
1784+
excludeGlobals = false,
1785+
getSpellingSuggstions = true): Symbol | undefined {
1786+
return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggstions, getSymbol);
17861787
}
17871788

17881789
function resolveNameHelper(
@@ -1793,6 +1794,7 @@ namespace ts {
17931794
nameArg: __String | Identifier | undefined,
17941795
isUse: boolean,
17951796
excludeGlobals: boolean,
1797+
getSpellingSuggestions: boolean,
17961798
lookup: typeof getSymbol): Symbol | undefined {
17971799
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
17981800
let result: Symbol | undefined;
@@ -2132,7 +2134,7 @@ namespace ts {
21322134
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
21332135
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
21342136
let suggestion: Symbol | undefined;
2135-
if (suggestionCount < maximumSuggestionCount) {
2137+
if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
21362138
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
21372139
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
21382140
if (isGlobalScopeAugmentationDeclaration) {
@@ -13657,7 +13659,7 @@ namespace ts {
1365713659

1365813660
function getGlobalSymbol(name: __String, meaning: SymbolFlags, diagnostic: DiagnosticMessage | undefined): Symbol | undefined {
1365913661
// Don't track references for global symbols anyway, so value if `isReference` is arbitrary
13660-
return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false);
13662+
return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ false);
1366113663
}
1366213664

1366313665
function getGlobalType(name: __String, arity: 0, reportErrors: true): ObjectType;
@@ -28718,7 +28720,7 @@ namespace ts {
2871828720

2871928721
function getSuggestedSymbolForNonexistentSymbol(location: Node | undefined, outerName: __String, meaning: SymbolFlags): Symbol | undefined {
2872028722
Debug.assert(outerName !== undefined, "outername should always be defined");
28721-
const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, (symbols, name, meaning) => {
28723+
const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ true, (symbols, name, meaning) => {
2872228724
Debug.assertEqual(outerName, name, "name should equal outerName");
2872328725
const symbol = getSymbol(symbols, name, meaning);
2872428726
// 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
@@ -28816,8 +28818,7 @@ namespace ts {
2881628818
return candidateName;
2881728819
}
2881828820

28819-
// Don't try to resolve aliases if global types aren't initialized yet
28820-
if (globalObjectType && candidate.flags & SymbolFlags.Alias) {
28821+
if (candidate.flags & SymbolFlags.Alias) {
2882128822
const alias = tryResolveAlias(candidate);
2882228823
if (alias && alias.flags & meaning) {
2882328824
return candidateName;

0 commit comments

Comments
 (0)