From 84eff8fa29ce260ceb7025e3aa6544831d5e1a63 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 4 Apr 2024 15:51:15 -0700 Subject: [PATCH] Special case check for this identifiers to skip exhaustive scope traversal (#58079) --- src/compiler/checker.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3c344f32f9a..3d8ab4ee212 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 (