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. 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) } 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) 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) }