@@ -1782,8 +1782,9 @@ namespace ts {
1782
1782
nameNotFoundMessage: DiagnosticMessage | undefined,
1783
1783
nameArg: __String | Identifier | undefined,
1784
1784
isUse: boolean,
1785
- excludeGlobals = false): Symbol | undefined {
1786
- return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol);
1785
+ excludeGlobals = false,
1786
+ getSpellingSuggstions = true): Symbol | undefined {
1787
+ return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSpellingSuggstions, getSymbol);
1787
1788
}
1788
1789
1789
1790
function resolveNameHelper(
@@ -1794,6 +1795,7 @@ namespace ts {
1794
1795
nameArg: __String | Identifier | undefined,
1795
1796
isUse: boolean,
1796
1797
excludeGlobals: boolean,
1798
+ getSpellingSuggestions: boolean,
1797
1799
lookup: typeof getSymbol): Symbol | undefined {
1798
1800
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
1799
1801
let result: Symbol | undefined;
@@ -2123,7 +2125,7 @@ namespace ts {
2123
2125
}
2124
2126
}
2125
2127
if (!result) {
2126
- if (nameNotFoundMessage) {
2128
+ if (nameNotFoundMessage && produceDiagnostics ) {
2127
2129
if (!errorLocation ||
2128
2130
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
2129
2131
!checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -2133,7 +2135,7 @@ namespace ts {
2133
2135
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
2134
2136
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
2135
2137
let suggestion: Symbol | undefined;
2136
- if (suggestionCount < maximumSuggestionCount) {
2138
+ if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
2137
2139
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
2138
2140
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
2139
2141
if (isGlobalScopeAugmentationDeclaration) {
@@ -2173,7 +2175,7 @@ namespace ts {
2173
2175
}
2174
2176
2175
2177
// Perform extra checks only if error reporting was requested
2176
- if (nameNotFoundMessage) {
2178
+ if (nameNotFoundMessage && produceDiagnostics ) {
2177
2179
if (propertyWithInvalidInitializer && !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields)) {
2178
2180
// We have a match, but the reference occurred within a property initializer and the identifier also binds
2179
2181
// to a local variable in the constructor where the code will be emitted. Note that this is actually allowed
@@ -13658,7 +13660,7 @@ namespace ts {
13658
13660
13659
13661
function getGlobalSymbol(name: __String, meaning: SymbolFlags, diagnostic: DiagnosticMessage | undefined): Symbol | undefined {
13660
13662
// Don't track references for global symbols anyway, so value if `isReference` is arbitrary
13661
- return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false);
13663
+ return resolveName(undefined, name, meaning, diagnostic, name, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ false );
13662
13664
}
13663
13665
13664
13666
function getGlobalType(name: __String, arity: 0, reportErrors: true): ObjectType;
@@ -28720,7 +28722,7 @@ namespace ts {
28720
28722
28721
28723
function getSuggestedSymbolForNonexistentSymbol(location: Node | undefined, outerName: __String, meaning: SymbolFlags): Symbol | undefined {
28722
28724
Debug.assert(outerName !== undefined, "outername should always be defined");
28723
- const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, (symbols, name, meaning) => {
28725
+ const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, /*getSpellingSuggestions*/ true, (symbols, name, meaning) => {
28724
28726
Debug.assertEqual(outerName, name, "name should equal outerName");
28725
28727
const symbol = getSymbol(symbols, name, meaning);
28726
28728
// 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