Skip to content

Commit 84eff8f

Browse files
authored
Special case check for this identifiers to skip exhaustive scope traversal (microsoft#58079)
1 parent 69e7e57 commit 84eff8f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8671,7 +8671,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
86718671
return { introducesError, node };
86728672
}
86738673
const meaning = getMeaningOfEntityNameReference(node);
8674-
const sym = resolveEntityName(leftmost, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true);
8674+
let sym: Symbol | undefined;
8675+
if (isThisIdentifier(leftmost)) {
8676+
// `this` isn't a bindable identifier - skip resolution, find a relevant `this` symbol directly and avoid exhaustive scope traversal
8677+
sym = getSymbolOfDeclaration(getThisContainer(leftmost, /*includeArrowFunctions*/ false, /*includeClassComputedPropertyName*/ false));
8678+
if (isSymbolAccessible(sym, leftmost, meaning, /*shouldComputeAliasesToMakeVisible*/ false).accessibility !== SymbolAccessibility.Accessible) {
8679+
introducesError = true;
8680+
context.tracker.reportInaccessibleThisError();
8681+
}
8682+
return { introducesError, node: attachSymbolToLeftmostIdentifier(node) as T };
8683+
}
8684+
sym = resolveEntityName(leftmost, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true);
86758685
if (sym) {
86768686
// If a parameter is resolvable in the current context it is also visible, so no need to go to symbol accesibility
86778687
if (

0 commit comments

Comments
 (0)