@@ -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;
@@ -2122,7 +2124,7 @@ namespace ts {
21222124 }
21232125 }
21242126 if (!result) {
2125- if (nameNotFoundMessage) {
2127+ if (nameNotFoundMessage && produceDiagnostics ) {
21262128 if (!errorLocation ||
21272129 !checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
21282130 !checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -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) {
@@ -2172,7 +2174,7 @@ namespace ts {
21722174 }
21732175
21742176 // Perform extra checks only if error reporting was requested
2175- if (nameNotFoundMessage) {
2177+ if (nameNotFoundMessage && produceDiagnostics ) {
21762178 if (propertyWithInvalidInitializer && !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields)) {
21772179 // We have a match, but the reference occurred within a property initializer and the identifier also binds
21782180 // 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 {
1363813640
1363913641 function getGlobalSymbol(name: __String, meaning: SymbolFlags, diagnostic: DiagnosticMessage | undefined): Symbol | undefined {
1364013642 // 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 );
1364213644 }
1364313645
1364413646 function getGlobalType(name: __String, arity: 0, reportErrors: true): ObjectType;
@@ -28620,7 +28622,7 @@ namespace ts {
2862028622
2862128623 function getSuggestedSymbolForNonexistentSymbol(location: Node | undefined, outerName: __String, meaning: SymbolFlags): Symbol | undefined {
2862228624 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) => {
2862428626 Debug.assertEqual(outerName, name, "name should equal outerName");
2862528627 const symbol = getSymbol(symbols, name, meaning);
2862628628 // 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