Special case check for this identifiers to skip exhaustive scope traversal (#58079)

This commit is contained in:
Wesley Wigham 2024-04-04 15:51:15 -07:00 committed by GitHub
parent 69e7e57b15
commit 84eff8fa29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8671,7 +8671,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return { introducesError, node };
}
const meaning = getMeaningOfEntityNameReference(node);
const sym = resolveEntityName(leftmost, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true);
let sym: Symbol | undefined;
if (isThisIdentifier(leftmost)) {
// `this` isn't a bindable identifier - skip resolution, find a relevant `this` symbol directly and avoid exhaustive scope traversal
sym = getSymbolOfDeclaration(getThisContainer(leftmost, /*includeArrowFunctions*/ false, /*includeClassComputedPropertyName*/ false));
if (isSymbolAccessible(sym, leftmost, meaning, /*shouldComputeAliasesToMakeVisible*/ false).accessibility !== SymbolAccessibility.Accessible) {
introducesError = true;
context.tracker.reportInaccessibleThisError();
}
return { introducesError, node: attachSymbolToLeftmostIdentifier(node) as T };
}
sym = resolveEntityName(leftmost, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true);
if (sym) {
// If a parameter is resolvable in the current context it is also visible, so no need to go to symbol accesibility
if (