Skip to content

Commit 441a994

Browse files
andrewbranchmprobst
authored andcommitted
Fix checker initialization crash (microsoft#46973)
* Fix checker initialization crash * Move checks to a place that makes more sense
1 parent 1125bbc commit 441a994

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/compiler/checker.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,8 +1782,9 @@ namespace ts {
17821782
nameNotFoundMessage: DiagnosticMessage | undefined,
17831783
nameArg: __String | Identifier | undefined,
17841784
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);
17871788
}
17881789

17891790
function resolveNameHelper(
@@ -1794,6 +1795,7 @@ namespace ts {
17941795
nameArg: __String | Identifier | undefined,
17951796
isUse: boolean,
17961797
excludeGlobals: boolean,
1798+
getSpellingSuggestions: boolean,
17971799
lookup: typeof getSymbol): Symbol | undefined {
17981800
const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
17991801
let result: Symbol | undefined;
@@ -2123,7 +2125,7 @@ namespace ts {
21232125
}
21242126
}
21252127
if (!result) {
2126-
if (nameNotFoundMessage) {
2128+
if (nameNotFoundMessage && produceDiagnostics) {
21272129
if (!errorLocation ||
21282130
!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg!) && // TODO: GH#18217
21292131
!checkAndReportErrorForExtendingInterface(errorLocation) &&
@@ -2133,7 +2135,7 @@ namespace ts {
21332135
!checkAndReportErrorForUsingNamespaceModuleAsValue(errorLocation, name, meaning) &&
21342136
!checkAndReportErrorForUsingValueAsType(errorLocation, name, meaning)) {
21352137
let suggestion: Symbol | undefined;
2136-
if (suggestionCount < maximumSuggestionCount) {
2138+
if (getSpellingSuggestions && suggestionCount < maximumSuggestionCount) {
21372139
suggestion = getSuggestedSymbolForNonexistentSymbol(originalLocation, name, meaning);
21382140
const isGlobalScopeAugmentationDeclaration = suggestion?.valueDeclaration && isAmbientModule(suggestion.valueDeclaration) && isGlobalScopeAugmentation(suggestion.valueDeclaration);
21392141
if (isGlobalScopeAugmentationDeclaration) {
@@ -2173,7 +2175,7 @@ namespace ts {
21732175
}
21742176

21752177
// Perform extra checks only if error reporting was requested
2176-
if (nameNotFoundMessage) {
2178+
if (nameNotFoundMessage && produceDiagnostics) {
21772179
if (propertyWithInvalidInitializer && !(getEmitScriptTarget(compilerOptions) === ScriptTarget.ESNext && useDefineForClassFields)) {
21782180
// We have a match, but the reference occurred within a property initializer and the identifier also binds
21792181
// 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 {
1365813660

1365913661
function getGlobalSymbol(name: __String, meaning: SymbolFlags, diagnostic: DiagnosticMessage | undefined): Symbol | undefined {
1366013662
// 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);
1366213664
}
1366313665

1366413666
function getGlobalType(name: __String, arity: 0, reportErrors: true): ObjectType;
@@ -28720,7 +28722,7 @@ namespace ts {
2872028722

2872128723
function getSuggestedSymbolForNonexistentSymbol(location: Node | undefined, outerName: __String, meaning: SymbolFlags): Symbol | undefined {
2872228724
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) => {
2872428726
Debug.assertEqual(outerName, name, "name should equal outerName");
2872528727
const symbol = getSymbol(symbols, name, meaning);
2872628728
// 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

Comments
 (0)