@@ -1781,8 +1781,9 @@ namespace ts {
1781
1781
nameNotFoundMessage: DiagnosticMessage | undefined,
1782
1782
nameArg: __String | Identifier | undefined,
1783
1783
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);
1786
1787
}
1787
1788
1788
1789
function resolveNameHelper(
@@ -1793,6 +1794,7 @@ namespace ts {
1793
1794
nameArg: __String | Identifier | undefined,
1794
1795
isUse: boolean,
1795
1796
excludeGlobals: boolean,
1797
+ getSpellingSuggestions: boolean,
1796
1798
lookup: typeof getSymbol): Symbol | undefined {
1797
1799
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
1798
1800
let result: Symbol | undefined;
@@ -2122,7 +2124,7 @@ namespace ts {
2122
2124
}
2123
2125
}
2124
2126
if (!result) {
2125
- if (nameNotFoundMessage) {
2127
+ if (nameNotFoundMessage && produceDiagnostics ) {
2126
2128
if (!errorLocation ||
2127
2129
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
2128
2130
!checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -2132,7 +2134,7 @@ namespace ts {
2132
2134
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
2133
2135
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
2134
2136
let suggestion: Symbol | undefined;
2135
- if (suggestionCount < maximumSuggestionCount) {
2137
+ if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
2136
2138
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
2137
2139
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
2138
2140
if (isGlobalScopeAugmentationDeclaration) {
@@ -2172,7 +2174,7 @@ namespace ts {
2172
2174
}
2173
2175
2174
2176
// Perform extra checks only if error reporting was requested
2175
- if (nameNotFoundMessage) {
2177
+ if (nameNotFoundMessage && produceDiagnostics ) {
2176
2178
if (propertyWithInvalidInitializer && !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields)) {
2177
2179
// We have a match, but the reference occurred within a property initializer and the identifier also binds
2178
2180
// to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
@@ -13638,7 +13640,7 @@ namespace ts {
13638
13640
13639
13641
function getGlobalSymbol(name: __String, meaning: SymbolFlags, diagnostic: DiagnosticMessage | undefined): Symbol | undefined {
13640
13642
// Don't track references for global symbols anyway, so value if `isReference` is arbitrary
13641
- return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false);
13643
+ return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ false );
13642
13644
}
13643
13645
13644
13646
function getGlobalType(name: __String, arity: 0, reportErrors: true): ObjectType;
@@ -28620,7 +28622,7 @@ namespace ts {
28620
28622
28621
28623
function getSuggestedSymbolForNonexistentSymbol(location: Node | undefined, outerName: __String, meaning: SymbolFlags): Symbol | undefined {
28622
28624
Debug.assert(outerName !== undefined, "outername should always be defined");
28623
- const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, (symbols, name, meaning) => {
28625
+ const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ true, (symbols, name, meaning) => {
28624
28626
Debug.assertEqual(outerName, name, "name should equal outerName");
28625
28627
const symbol = getSymbol(symbols, name, meaning);
28626
28628
// 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
0 commit comments