Minor algorithm change to address perf regression

This commit is contained in:
Ron Buckton 2023-05-26 15:31:29 -04:00
parent d762534463
commit 4488ac2b36
No known key found for this signature in database
GPG Key ID: 9ADA0DFD36502AB9

View File

@ -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))) {