From e0701af46e06f0cef2ceaae8a867c978b45fd278 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 23 Jul 2024 15:57:54 -0700 Subject: [PATCH] Skip markLinkedReferences import elision walk entirely in some common cases (#59398) --- src/compiler/checker.ts | 13 ++++++++----- src/compiler/emitter.ts | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c5cd771cfff19..72a39d04e90ed 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -49271,11 +49271,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { function checkSingleIdentifier(node: Node) { const nodeLinks = getNodeLinks(node); - nodeLinks.calculatedFlags |= NodeCheckFlags.ConstructorReference | NodeCheckFlags.CapturedBlockScopedBinding | NodeCheckFlags.BlockScopedBindingInLoop; - if (isIdentifier(node) && isExpressionNodeOrShorthandPropertyAssignmentName(node) && !(isPropertyAccessExpression(node.parent) && node.parent.name === node)) { - const s = getResolvedSymbol(node); - if (s && s !== unknownSymbol) { - checkIdentifierCalculateNodeCheckFlags(node, s); + nodeLinks.calculatedFlags |= NodeCheckFlags.ConstructorReference; + if (isIdentifier(node)) { + nodeLinks.calculatedFlags |= NodeCheckFlags.BlockScopedBindingInLoop | NodeCheckFlags.CapturedBlockScopedBinding; // Can't set on all arbitrary nodes (these nodes have this flag set by `checkSingleBlockScopeBinding` only) + if (isExpressionNodeOrShorthandPropertyAssignmentName(node) && !(isPropertyAccessExpression(node.parent) && node.parent.name === node)) { + const s = getResolvedSymbol(node); + if (s && s !== unknownSymbol) { + checkIdentifierCalculateNodeCheckFlags(node, s); + } } } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e5e035c93becc..8c8c9f85fd2b6 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -947,6 +947,7 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi } function markLinkedReferences(file: SourceFile) { + if (ts.isSourceFileJS(file)) return; // JS files don't use reference calculations as they don't do import ellision, no need to calculate it ts.forEachChildRecursively(file, n => { if (isImportEqualsDeclaration(n) && !(ts.getSyntacticModifierFlags(n) & ts.ModifierFlags.Export)) return "skip"; // These are deferred and marked in a chain when referenced if (ts.isImportDeclaration(n)) return "skip"; // likewise, these are ultimately what get marked by calls on other nodes - we want to skip them