@@ -7272,7 +7272,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
72727272 //
72737273 // If the declaration is in a JS file, then we don't need to do this at all, as there are no annotations besides
72747274 // JSDoc, which are always outside the function declaration, so are not in the parameter scope.
7275- let restoreEnclosingDeclaration : (() => void) | undefined;
7275+ let cleanup : (() => void) | undefined;
72767276 if (
72777277 context.enclosingDeclaration
72787278 && signature.declaration
@@ -7292,11 +7292,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
72927292 // It'd likely be better to store this somewhere else for isSymbolAccessible, but
72937293 // since that API _only_ uses the enclosing declaration (and its parents), this is
72947294 // seems like the best way to inject names into that search process.
7295- const locals = context.fakeScopeLocals ??= createSymbolTable();
7295+ const existingFakeScope = findAncestor(context.enclosingDeclaration, node => !!getNodeLinks(node).fakeScopeForSignatureDeclaration);
7296+ Debug.assertOptionalNode(existingFakeScope, isBlock);
72967297
7297- // Performance optimization; if this is empty then we're not going to find a fake scope
7298- // in the parents of context.enclosingDeclaration, so skip searching later.
7299- const couldHaveFakeScopeAncestor = !!locals.size;
7298+ const locals = existingFakeScope?.locals ?? createSymbolTable();
73007299
73017300 let newLocals: __String[] | undefined;
73027301 for (const param of expandedParams) {
@@ -7311,8 +7310,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
73117310 forEach(newLocals, s => locals.delete(s));
73127311 }
73137312
7314- if (couldHaveFakeScopeAncestor && findAncestor(context.enclosingDeclaration, node => !!getNodeLinks(node).fakeScopeForSignatureDeclaration) ) {
7315- restoreEnclosingDeclaration = removeNewLocals;
7313+ if (existingFakeScope ) {
7314+ cleanup = removeNewLocals;
73167315 }
73177316 else {
73187317 // Use a Block for this; the type of the node doesn't matter so long as it
@@ -7325,7 +7324,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
73257324 setParent(fakeScope, saveEnclosingDeclaration);
73267325 context.enclosingDeclaration = fakeScope;
73277326
7328- restoreEnclosingDeclaration = () => {
7327+ cleanup = () => {
73297328 context.enclosingDeclaration = saveEnclosingDeclaration;
73307329 removeNewLocals();
73317330 };
@@ -7388,7 +7387,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
73887387 node.typeArguments = factory.createNodeArray(typeArguments);
73897388 }
73907389
7391- restoreEnclosingDeclaration ?.();
7390+ cleanup ?.();
73927391 return node;
73937392 }
73947393
@@ -48551,7 +48550,6 @@ interface NodeBuilderContext {
4855148550 usedSymbolNames?: Set<string>;
4855248551 remappedSymbolNames?: Map<SymbolId, string>;
4855348552 reverseMappedStack?: ReverseMappedSymbol[];
48554- fakeScopeLocals?: SymbolTable;
4855548553}
4855648554
4855748555class SymbolTrackerImpl implements SymbolTracker {
0 commit comments