From 2981d5adef0e61ac3ee497c12047f61ad251de42 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:05:39 -0800 Subject: [PATCH 1/4] Accept arbitrary AST nodes in the reuse helper The reuse helper also processes property names and type parameter declarations. A TypeNode annotation misrepresents these supported callers even though Go accepts the node aliases interchangeably. --- tsc/internal/checker/nodecopy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsc/internal/checker/nodecopy.go b/tsc/internal/checker/nodecopy.go index 71ed761dcbdc8..913930bd53095 100644 --- a/tsc/internal/checker/nodecopy.go +++ b/tsc/internal/checker/nodecopy.go @@ -220,7 +220,7 @@ func (b *NodeBuilderImpl) finalizeBoundary(bound *recoveryBoundary) bool { return true } -func (b *NodeBuilderImpl) tryReuseExistingNodeHelper(existing *ast.TypeNode) *ast.TypeNode { +func (b *NodeBuilderImpl) tryReuseExistingNodeHelper(existing *ast.Node) *ast.Node { bound := b.createRecoveryBoundary() var transformed *ast.Node v := getExistingNodeTreeVisitor(b, bound) // !!! TODO: Cache visitor and just reset bound+host builder? We try this for a *lot* of nodes. From 794f5f2acec7ec409245321ac5e32ccbfe1e3435 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:05:39 -0800 Subject: [PATCH 2/4] Correct named evaluation result annotations Named evaluation transforms preserve the surrounding declaration kinds. Describing their results as expressions hides the contracts expected by their callers. --- .../transformers/estransforms/namedevaluation.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tsc/internal/transformers/estransforms/namedevaluation.go b/tsc/internal/transformers/estransforms/namedevaluation.go index 3b986a5b9d009..03ff4a28923b1 100644 --- a/tsc/internal/transformers/estransforms/namedevaluation.go +++ b/tsc/internal/transformers/estransforms/namedevaluation.go @@ -270,7 +270,7 @@ func finishTransformNamedEvaluation( return factory.RestoreOuterExpressions(expression, updatedExpression, ast.OEKAll) } -func transformNamedEvaluationOfPropertyAssignment(context *printer.EmitContext, node *ast.PropertyAssignment /*NamedEvaluation & PropertyAssignment*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.Expression { +func transformNamedEvaluationOfPropertyAssignment(context *printer.EmitContext, node *ast.PropertyAssignment /*NamedEvaluation & PropertyAssignment*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.PropertyAssignmentNode { // 13.2.5.5 RS: PropertyDefinitionEvaluation // PropertyAssignment : PropertyName `:` AssignmentExpression // ... @@ -284,7 +284,7 @@ func transformNamedEvaluationOfPropertyAssignment(context *printer.EmitContext, return factory.UpdatePropertyAssignment(node, nil /*modifiers*/, name, nil /*postfixToken*/, nil /*typeNode*/, initializer) } -func transformNamedEvaluationOfShorthandAssignmentProperty(emitContext *printer.EmitContext, node *ast.ShorthandPropertyAssignment /*NamedEvaluation & ShorthandPropertyAssignment*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.Expression { +func transformNamedEvaluationOfShorthandAssignmentProperty(emitContext *printer.EmitContext, node *ast.ShorthandPropertyAssignment /*NamedEvaluation & ShorthandPropertyAssignment*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.ShorthandPropertyAssignmentNode { // 13.15.5.3 RS: PropertyDestructuringAssignmentEvaluation // AssignmentProperty : IdentifierReference Initializer? // ... @@ -312,7 +312,7 @@ func transformNamedEvaluationOfShorthandAssignmentProperty(emitContext *printer. ) } -func transformNamedEvaluationOfVariableDeclaration(emitContext *printer.EmitContext, node *ast.VariableDeclaration /*NamedEvaluation & VariableDeclaration*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.Expression { +func transformNamedEvaluationOfVariableDeclaration(emitContext *printer.EmitContext, node *ast.VariableDeclaration /*NamedEvaluation & VariableDeclaration*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.VariableDeclarationNode { // 14.3.1.2 RS: Evaluation // LexicalBinding : BindingIdentifier Initializer // ... @@ -344,7 +344,7 @@ func transformNamedEvaluationOfVariableDeclaration(emitContext *printer.EmitCont ) } -func transformNamedEvaluationOfParameterDeclaration(emitContext *printer.EmitContext, node *ast.ParameterDeclaration /*NamedEvaluation & ParameterDeclaration*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.Expression { +func transformNamedEvaluationOfParameterDeclaration(emitContext *printer.EmitContext, node *ast.ParameterDeclaration /*NamedEvaluation & ParameterDeclaration*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.ParameterDeclarationNode { // 8.6.3 RS: IteratorBindingInitialization // SingleNameBinding : BindingIdentifier Initializer? // ... @@ -380,7 +380,7 @@ func transformNamedEvaluationOfParameterDeclaration(emitContext *printer.EmitCon ) } -func transformNamedEvaluationOfBindingElement(emitContext *printer.EmitContext, node *ast.BindingElement /*NamedEvaluation & BindingElement*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.Expression { +func transformNamedEvaluationOfBindingElement(emitContext *printer.EmitContext, node *ast.BindingElement /*NamedEvaluation & BindingElement*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.BindingElementNode { // 8.6.3 RS: IteratorBindingInitialization // SingleNameBinding : BindingIdentifier Initializer? // ... @@ -414,7 +414,7 @@ func transformNamedEvaluationOfBindingElement(emitContext *printer.EmitContext, ) } -func transformNamedEvaluationOfPropertyDeclaration(emitContext *printer.EmitContext, node *ast.PropertyDeclaration /*NamedEvaluation & PropertyDeclaration*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.Expression { +func transformNamedEvaluationOfPropertyDeclaration(emitContext *printer.EmitContext, node *ast.PropertyDeclaration /*NamedEvaluation & PropertyDeclaration*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.PropertyDeclarationNode { // 10.2.1.3 RS: EvaluateBody // Initializer : `=` AssignmentExpression // ... @@ -480,7 +480,7 @@ func transformNamedEvaluationOfAssignmentExpression(emitContext *printer.EmitCon ) } -func transformNamedEvaluationOfExportAssignment(emitContext *printer.EmitContext, node *ast.ExportAssignment /*NamedEvaluation & ExportAssignment*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.Expression { +func transformNamedEvaluationOfExportAssignment(emitContext *printer.EmitContext, node *ast.ExportAssignment /*NamedEvaluation & ExportAssignment*/, ignoreEmptyStringLiteral bool, assignedNameText string) *ast.ExportAssignmentNode { // 16.2.3.7 RS: Evaluation // ExportDeclaration : `export` `default` AssignmentExpression `;` // 1. If IsAnonymousFunctionDefinition(|AssignmentExpression|) is *true*, then @@ -510,7 +510,7 @@ func transformNamedEvaluationOfExportAssignment(emitContext *printer.EmitContext } // Performs a shallow transformation of a `NamedEvaluation` node, such that a valid name will be assigned. -func transformNamedEvaluation(context *printer.EmitContext, node *ast.Node /*NamedEvaluation*/, ignoreEmptyStringLiteral bool, assignedName string) *ast.Expression { +func transformNamedEvaluation(context *printer.EmitContext, node *ast.Node /*NamedEvaluation*/, ignoreEmptyStringLiteral bool, assignedName string) *ast.Node { switch node.Kind { case ast.KindPropertyAssignment: return transformNamedEvaluationOfPropertyAssignment(context, node.AsPropertyAssignment(), ignoreEmptyStringLiteral, assignedName) From add183a06170727491952b129643330e1166830f Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:05:39 -0800 Subject: [PATCH 3/4] Allow non-identifiers in generated-name checks The type serializer checks arbitrary serialized expressions for generated-name metadata. Restricting this helper's annotation to identifiers misrepresents a supported caller. --- tsc/internal/transformers/utilities.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsc/internal/transformers/utilities.go b/tsc/internal/transformers/utilities.go index af826b85a6c20..55d6301a17444 100644 --- a/tsc/internal/transformers/utilities.go +++ b/tsc/internal/transformers/utilities.go @@ -9,7 +9,7 @@ import ( "github.com/microsoft/TypeScript/tsc/internal/scanner" ) -func IsGeneratedIdentifier(emitContext *printer.EmitContext, name *ast.IdentifierNode) bool { +func IsGeneratedIdentifier(emitContext *printer.EmitContext, name *ast.Node) bool { return emitContext.HasAutoGenerateInfo(name) } From 6703c9ce67aff6b4705d6f1f380f0573b8ef785f Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:05:39 -0800 Subject: [PATCH 4/4] Correct printer name helper result annotations Declaration names can be string literals, binding patterns, or computed names, and namespace member names are property accesses. Identifier result annotations misrepresent those node kinds even though Go accepts the node aliases interchangeably. --- tsc/internal/printer/factory.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tsc/internal/printer/factory.go b/tsc/internal/printer/factory.go index dbc9242abe400..f6db41d90c3b2 100644 --- a/tsc/internal/printer/factory.go +++ b/tsc/internal/printer/factory.go @@ -494,8 +494,8 @@ type AssignedNameOptions struct { IgnoreAssignedName bool // indicates whether the assigned name of a declaration shouldn't be considered. } -func (f *NodeFactory) getName(node *ast.Declaration, emitFlags EmitFlags, opts AssignedNameOptions) *ast.IdentifierNode { - var nodeName *ast.IdentifierNode +func (f *NodeFactory) getName(node *ast.Declaration, emitFlags EmitFlags, opts AssignedNameOptions) *ast.Node { + var nodeName *ast.Node if node != nil { if opts.IgnoreAssignedName { nodeName = ast.GetNonAssignedNameOfDeclaration(node) @@ -522,14 +522,14 @@ func (f *NodeFactory) getName(node *ast.Declaration, emitFlags EmitFlags, opts A // Gets the local name of a declaration. This is primarily used for declarations that can be referred to by name in the // declaration's immediate scope (classes, enums, namespaces). A local name will *never* be prefixed with a module or // namespace export modifier like "exports." when emitted as an expression. -func (f *NodeFactory) GetLocalName(node *ast.Declaration) *ast.IdentifierNode { +func (f *NodeFactory) GetLocalName(node *ast.Declaration) *ast.Node { return f.GetLocalNameEx(node, AssignedNameOptions{}) } // Gets the local name of a declaration. This is primarily used for declarations that can be referred to by name in the // declaration's immediate scope (classes, enums, namespaces). A local name will *never* be prefixed with a module or // namespace export modifier like "exports." when emitted as an expression. -func (f *NodeFactory) GetLocalNameEx(node *ast.Declaration, opts AssignedNameOptions) *ast.IdentifierNode { +func (f *NodeFactory) GetLocalNameEx(node *ast.Declaration, opts AssignedNameOptions) *ast.Node { return f.getName(node, EFLocalName, opts) } @@ -537,7 +537,7 @@ func (f *NodeFactory) GetLocalNameEx(node *ast.Declaration, opts AssignedNameOpt // referred to by name in the declaration's immediate scope (classes, enums, namespaces). An // export name will *always* be prefixed with an module or namespace export modifier like // `"exports."` when emitted as an expression if the name points to an exported symbol. -func (f *NodeFactory) GetExportName(node *ast.Declaration) *ast.IdentifierNode { +func (f *NodeFactory) GetExportName(node *ast.Declaration) *ast.Node { return f.GetExportNameEx(node, AssignedNameOptions{}) } @@ -545,21 +545,21 @@ func (f *NodeFactory) GetExportName(node *ast.Declaration) *ast.IdentifierNode { // referred to by name in the declaration's immediate scope (classes, enums, namespaces). An // export name will *always* be prefixed with an module or namespace export modifier like // `"exports."` when emitted as an expression if the name points to an exported symbol. -func (f *NodeFactory) GetExportNameEx(node *ast.Declaration, opts AssignedNameOptions) *ast.IdentifierNode { +func (f *NodeFactory) GetExportNameEx(node *ast.Declaration, opts AssignedNameOptions) *ast.Node { return f.getName(node, EFExportName, opts) } // Gets the name of a declaration to use during emit. -func (f *NodeFactory) GetDeclarationName(node *ast.Declaration) *ast.IdentifierNode { +func (f *NodeFactory) GetDeclarationName(node *ast.Declaration) *ast.Node { return f.GetDeclarationNameEx(node, NameOptions{}) } // Gets the name of a declaration to use during emit. -func (f *NodeFactory) GetDeclarationNameEx(node *ast.Declaration, opts NameOptions) *ast.IdentifierNode { +func (f *NodeFactory) GetDeclarationNameEx(node *ast.Declaration, opts NameOptions) *ast.Node { return f.getName(node, EFNone, AssignedNameOptions{AllowComments: opts.AllowComments, AllowSourceMaps: opts.AllowSourceMaps}) } -func (f *NodeFactory) GetNamespaceMemberName(ns *ast.IdentifierNode, name *ast.IdentifierNode, opts NameOptions) *ast.IdentifierNode { +func (f *NodeFactory) GetNamespaceMemberName(ns *ast.IdentifierNode, name *ast.IdentifierNode, opts NameOptions) *ast.PropertyAccessExpressionNode { if !f.emitContext.HasAutoGenerateInfo(name) { name = name.Clone(f) }