From 4488ac2b3621ff31e400561ce85b2b41beb037fa Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Fri, 26 May 2023 15:31:29 -0400 Subject: [PATCH] Minor algorithm change to address perf regression --- src/compiler/checker.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 26d96d2a64d..3c8d83e5240 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3024,12 +3024,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // (it refers to the constant type of the expression instead) return undefined; } - if (isModuleDeclaration(location) && lastLocation && location.name === lastLocation) { - // If this is the name of a namespace, skip the parent since it will have is own locals that could - // conflict. - lastLocation = location; - location = location.parent; - } // Locals of a source file are not in scope (because they get merged into the global symbol table) if (canHaveLocals(location) && location.locals && !isGlobalSourceFile(location)) { if (result = lookup(location.locals, name, meaning)) { @@ -3071,6 +3065,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } } } + else if (location.kind === SyntaxKind.ModuleDeclaration) { + // If this is the name of a namespace, skip the parent since it will have is own locals that could + // conflict. + useResult = lastLocation === (location as ModuleDeclaration).body; + } else if (location.kind === SyntaxKind.ConditionalType) { // A type parameter declared using 'infer T' in a conditional type is visible only in // the true branch of the conditional type. @@ -3092,6 +3091,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { isInExternalModule = true; // falls through case SyntaxKind.ModuleDeclaration: + if (isModuleDeclaration(location) && lastLocation === location.name) break; const moduleExports = getSymbolOfDeclaration(location as SourceFile | ModuleDeclaration)?.exports || emptySymbols; if (location.kind === SyntaxKind.SourceFile || (isModuleDeclaration(location) && location.flags & NodeFlags.Ambient && !isGlobalScopeAugmentation(location))) {