Skip to content

Reparse @import as synthetic type-only import declaration #831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/api/encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ func getChildrenPropertyMask(node *ast.Node) uint8 {
case ast.KindImportEqualsDeclaration:
n := node.AsImportEqualsDeclaration()
return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.Name() != nil) << 1) | (boolToByte(n.ModuleReference != nil) << 2)
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
n := node.AsImportDeclaration()
return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.ImportClause != nil) << 1) | (boolToByte(n.ModuleSpecifier != nil) << 2) | (boolToByte(n.Attributes != nil) << 3)
case ast.KindImportSpecifier:
Expand All @@ -468,7 +468,7 @@ func getChildrenPropertyMask(node *ast.Node) uint8 {
case ast.KindImportClause:
n := node.AsImportClause()
return (boolToByte(n.Name() != nil) << 0) | (boolToByte(n.NamedBindings != nil) << 1)
case ast.KindExportAssignment:
case ast.KindExportAssignment, ast.KindJSExportAssignment:
n := node.AsExportAssignment()
return (boolToByte(n.Modifiers() != nil) << 0) | (boolToByte(n.Expression != nil) << 1)
case ast.KindNamespaceExportDeclaration:
Expand Down
16 changes: 11 additions & 5 deletions internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,12 +751,10 @@ func (n *Node) Children() *NodeList {

func (n *Node) ModuleSpecifier() *Expression {
switch n.Kind {
case KindImportDeclaration:
case KindImportDeclaration, KindJSImportDeclaration:
return n.AsImportDeclaration().ModuleSpecifier
case KindExportDeclaration:
return n.AsExportDeclaration().ModuleSpecifier
case KindJSDocImportTag:
return n.AsJSDocImportTag().ModuleSpecifier
}
panic("Unhandled case in Node.ModuleSpecifier: " + n.Kind.String())
}
Expand Down Expand Up @@ -4036,13 +4034,21 @@ type ImportDeclaration struct {
Attributes *ImportAttributesNode // ImportAttributesNode. Optional
}

func (f *NodeFactory) NewImportDeclaration(modifiers *ModifierList, importClause *ImportClauseNode, moduleSpecifier *Expression, attributes *ImportAttributesNode) *Node {
func (f *NodeFactory) newImportOrJSImportDeclaration(kind Kind, modifiers *ModifierList, importClause *ImportClauseNode, moduleSpecifier *Expression, attributes *ImportAttributesNode) *Node {
data := &ImportDeclaration{}
data.modifiers = modifiers
data.ImportClause = importClause
data.ModuleSpecifier = moduleSpecifier
data.Attributes = attributes
return f.newNode(KindImportDeclaration, data)
return f.newNode(kind, data)
}

func (f *NodeFactory) NewImportDeclaration(modifiers *ModifierList, importClause *ImportClauseNode, moduleSpecifier *Expression, attributes *ImportAttributesNode) *Node {
return f.newImportOrJSImportDeclaration(KindImportDeclaration, modifiers, importClause, moduleSpecifier, attributes)
}

func (f *NodeFactory) NewJSImportDeclaration(modifiers *ModifierList, importClause *ImportClauseNode, moduleSpecifier *Expression, attributes *ImportAttributesNode) *Node {
return f.newImportOrJSImportDeclaration(KindJSImportDeclaration, modifiers, importClause, moduleSpecifier, attributes)
}

func (f *NodeFactory) UpdateImportDeclaration(node *ImportDeclaration, modifiers *ModifierList, importClause *ImportClauseNode, moduleSpecifier *Expression, attributes *ImportAttributesNode) *Node {
Expand Down
1 change: 1 addition & 0 deletions internal/ast/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ const (
KindJSTypeAliasDeclaration
KindJSExportAssignment
KindCommonJSExport
KindJSImportDeclaration
Copy link
Member

@andrewbranch andrewbranch May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don’t yet have codegen in place, can you update _packages/ast/src/syntaxKind.ts and _packages/ast/src/syntaxKind.enum.ts?

// Transformation nodes
KindNotEmittedStatement
KindPartiallyEmittedExpression
Expand Down
15 changes: 8 additions & 7 deletions internal/ast/kind_stringer_generated.go

Large diffs are not rendered by default.

36 changes: 14 additions & 22 deletions internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ func isDeclarationStatementKind(kind Kind) bool {
KindEnumDeclaration,
KindModuleDeclaration,
KindImportDeclaration,
KindJSImportDeclaration,
KindImportEqualsDeclaration,
KindExportDeclaration,
KindExportAssignment,
Expand Down Expand Up @@ -1036,7 +1037,7 @@ func CanHaveIllegalDecorators(node *Node) bool {
KindMissingDeclaration, KindVariableStatement,
KindInterfaceDeclaration, KindTypeAliasDeclaration,
KindEnumDeclaration, KindModuleDeclaration,
KindImportEqualsDeclaration, KindImportDeclaration,
KindImportEqualsDeclaration, KindImportDeclaration, KindJSImportDeclaration,
KindNamespaceExportDeclaration, KindExportDeclaration,
KindExportAssignment:
return true
Expand Down Expand Up @@ -1081,6 +1082,7 @@ func CanHaveModifiers(node *Node) bool {
KindModuleDeclaration,
KindImportEqualsDeclaration,
KindImportDeclaration,
KindJSImportDeclaration,
KindExportAssignment,
KindExportDeclaration:
return true
Expand Down Expand Up @@ -1662,7 +1664,7 @@ func IsAnyImportOrReExport(node *Node) bool {
}

func IsAnyImportSyntax(node *Node) bool {
return NodeKindIs(node, KindImportDeclaration, KindImportEqualsDeclaration)
return NodeKindIs(node, KindImportDeclaration, KindJSImportDeclaration, KindImportEqualsDeclaration)
}

func IsJsonSourceFile(file *SourceFile) bool {
Expand All @@ -1675,12 +1677,10 @@ func IsInJsonFile(node *Node) bool {

func GetExternalModuleName(node *Node) *Expression {
switch node.Kind {
case KindImportDeclaration:
case KindImportDeclaration, KindJSImportDeclaration:
return node.AsImportDeclaration().ModuleSpecifier
case KindExportDeclaration:
return node.AsExportDeclaration().ModuleSpecifier
case KindJSDocImportTag:
return node.AsJSDocImportTag().ModuleSpecifier
case KindImportEqualsDeclaration:
if node.AsImportEqualsDeclaration().ModuleReference.Kind == KindExternalModuleReference {
return node.AsImportEqualsDeclaration().ModuleReference.AsExternalModuleReference().Expression
Expand All @@ -1701,7 +1701,7 @@ func GetExternalModuleName(node *Node) *Expression {

func GetImportAttributes(node *Node) *Node {
switch node.Kind {
case KindImportDeclaration:
case KindImportDeclaration, KindJSImportDeclaration:
return node.AsImportDeclaration().Attributes
case KindExportDeclaration:
return node.AsExportDeclaration().Attributes
Expand Down Expand Up @@ -2053,6 +2053,7 @@ func GetMeaningFromDeclaration(node *Node) SemanticMeaning {
KindImportSpecifier,
KindImportEqualsDeclaration,
KindImportDeclaration,
KindJSImportDeclaration,
KindExportAssignment,
KindJSExportAssignment,
KindExportDeclaration:
Expand Down Expand Up @@ -2168,7 +2169,7 @@ func getModuleInstanceStateWorker(node *Node, ancestors []*Node, visited map[Nod
if IsEnumConst(node) {
return ModuleInstanceStateConstEnumOnly
}
case KindImportDeclaration, KindImportEqualsDeclaration:
case KindImportDeclaration, KindJSImportDeclaration, KindImportEqualsDeclaration:
if !HasSyntacticModifier(node, ModifierFlagsExport) {
return ModuleInstanceStateNonInstantiated
}
Expand Down Expand Up @@ -2339,7 +2340,7 @@ func GetFirstIdentifier(node *Node) *Node {

func GetNamespaceDeclarationNode(node *Node) *Node {
switch node.Kind {
case KindImportDeclaration:
case KindImportDeclaration, KindJSImportDeclaration:
importClause := node.AsImportDeclaration().ImportClause
if importClause != nil && importClause.AsImportClause().NamedBindings != nil && IsNamespaceImport(importClause.AsImportClause().NamedBindings) {
return importClause.AsImportClause().NamedBindings
Expand All @@ -2361,15 +2362,13 @@ func ModuleExportNameIsDefault(node *Node) bool {
return node.Text() == InternalSymbolNameDefault
}

func IsDefaultImport(node *Node /*ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration | JSDocImportTag*/) bool {
var importClause *Node
func IsDefaultImport(node *Node /*ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration*/) bool {
switch node.Kind {
case KindImportDeclaration:
importClause = node.AsImportDeclaration().ImportClause
case KindJSDocImportTag:
importClause = node.AsJSDocImportTag().ImportClause
case KindImportDeclaration, KindJSImportDeclaration:
importClause := node.AsImportDeclaration().ImportClause
return importClause != nil && importClause.AsImportClause().name != nil
}
return importClause != nil && importClause.AsImportClause().name != nil
return false
}

func GetImpliedNodeFormatForFile(path string, packageJsonType string) core.ModuleKind {
Expand Down Expand Up @@ -2554,13 +2553,6 @@ func ForEachDynamicImportOrRequireCall(
if cb(node, node.AsImportTypeNode().Argument.AsLiteralTypeNode().Literal) {
return true
}
} else if includeTypeSpaceImports && node.Kind == KindJSDocImportTag {
moduleNameExpr := GetExternalModuleName(node)
if moduleNameExpr != nil && IsStringLiteral(moduleNameExpr) && moduleNameExpr.Text() != "" {
if cb(node, moduleNameExpr) {
return true
}
}
}
// skip past import/require
lastIndex += size
Expand Down
14 changes: 5 additions & 9 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -2205,7 +2205,7 @@ func (c *Checker) checkSourceElementWorker(node *ast.Node) {
c.checkEnumMember(node)
case ast.KindModuleDeclaration:
c.checkModuleDeclaration(node)
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
c.checkImportDeclaration(node)
case ast.KindImportEqualsDeclaration:
c.checkImportEqualsDeclaration(node)
Expand Down Expand Up @@ -4898,7 +4898,7 @@ func (c *Checker) checkModuleAugmentationElement(node *ast.Node) {
break
}
fallthrough
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
c.grammarErrorOnFirstToken(node, diagnostics.Imports_are_not_permitted_in_module_augmentations_Consider_moving_them_to_the_enclosing_external_module)
case ast.KindBindingElement, ast.KindVariableDeclaration:
name := node.Name()
Expand Down Expand Up @@ -5080,14 +5080,10 @@ func isExclusivelyTypeOnlyImportOrExport(node *ast.Node) bool {
switch node.Kind {
case ast.KindExportDeclaration:
return node.AsExportDeclaration().IsTypeOnly
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
if importClause := node.AsImportDeclaration().ImportClause; importClause != nil {
return importClause.AsImportClause().IsTypeOnly
}
case ast.KindJSDocImportTag:
if importClause := node.AsJSDocImportTag().ImportClause; importClause != nil {
return importClause.AsImportClause().IsTypeOnly
}
}
return false
}
Expand Down Expand Up @@ -14173,7 +14169,7 @@ func (c *Checker) getModuleSpecifierForImportOrExport(node *ast.Node) *ast.Node

func getModuleSpecifierFromNode(node *ast.Node) *ast.Node {
switch node.Kind {
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
return node.AsImportDeclaration().ModuleSpecifier
case ast.KindExportDeclaration:
return node.AsExportDeclaration().ModuleSpecifier
Expand Down Expand Up @@ -29387,7 +29383,7 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy
// 3). Require in Javascript
// 4). type A = import("./f/*gotToDefinitionHere*/oo")
if (ast.IsExternalModuleImportEqualsDeclaration(grandParent) && getExternalModuleImportEqualsDeclarationExpression(grandParent) == node) ||
((parent.Kind == ast.KindImportDeclaration || parent.Kind == ast.KindExportDeclaration) && parent.AsImportDeclaration().ModuleSpecifier == node) ||
((parent.Kind == ast.KindImportDeclaration || parent.Kind == ast.KindJSImportDeclaration || parent.Kind == ast.KindExportDeclaration) && parent.AsImportDeclaration().ModuleSpecifier == node) ||
ast.IsVariableDeclarationInitializedToRequire(grandParent) ||
(ast.IsLiteralTypeNode(parent) && ast.IsLiteralImportTypeNode(grandParent) && grandParent.AsImportTypeNode().Argument == parent) {
return c.resolveExternalModuleName(node, node, ignoreErrors)
Expand Down
5 changes: 3 additions & 2 deletions internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func (c *Checker) checkGrammarModifiers(node *ast.Node /*Union[HasModifiers, Has
return c.grammarErrorOnNode(lastAsync, diagnostics.X_0_modifier_cannot_appear_on_a_constructor_declaration, "async")
}
return false
} else if (node.Kind == ast.KindImportDeclaration || node.Kind == ast.KindImportEqualsDeclaration) && flags&ast.ModifierFlagsAmbient != 0 {
} else if (node.Kind == ast.KindImportDeclaration || node.Kind == ast.KindJSImportDeclaration || node.Kind == ast.KindImportEqualsDeclaration) && flags&ast.ModifierFlagsAmbient != 0 {
return c.grammarErrorOnNode(lastDeclare, diagnostics.A_0_modifier_cannot_be_used_with_an_import_declaration, "declare")
} else if node.Kind == ast.KindParameter && (flags&ast.ModifierFlagsParameterPropertyModifier != 0) && ast.IsBindingPattern(node.Name()) {
return c.grammarErrorOnNode(node, diagnostics.A_parameter_property_may_not_be_declared_using_a_binding_pattern)
Expand Down Expand Up @@ -598,6 +598,7 @@ func (c *Checker) findFirstIllegalModifier(node *ast.Node) *ast.Node {
ast.KindIndexSignature,
ast.KindModuleDeclaration,
ast.KindImportDeclaration,
ast.KindJSImportDeclaration,
ast.KindImportEqualsDeclaration,
ast.KindExportDeclaration,
ast.KindExportAssignment,
Expand Down Expand Up @@ -2021,7 +2022,7 @@ func (c *Checker) checkGrammarTopLevelElementForRequiredDeclareModifier(node *as
// export_opt AmbientDeclaration
//
// TODO: The spec needs to be amended to reflect this grammar.
if node.Kind == ast.KindInterfaceDeclaration || node.Kind == ast.KindTypeAliasDeclaration || node.Kind == ast.KindImportDeclaration || node.Kind == ast.KindImportEqualsDeclaration || node.Kind == ast.KindExportDeclaration || node.Kind == ast.KindExportAssignment || node.Kind == ast.KindJSExportAssignment || node.Kind == ast.KindNamespaceExportDeclaration || ast.HasSyntacticModifier(node, ast.ModifierFlagsAmbient|ast.ModifierFlagsExport|ast.ModifierFlagsDefault) {
if node.Kind == ast.KindInterfaceDeclaration || node.Kind == ast.KindTypeAliasDeclaration || node.Kind == ast.KindImportDeclaration || node.Kind == ast.KindJSImportDeclaration || node.Kind == ast.KindImportEqualsDeclaration || node.Kind == ast.KindExportDeclaration || node.Kind == ast.KindExportAssignment || node.Kind == ast.KindJSExportAssignment || node.Kind == ast.KindNamespaceExportDeclaration || ast.HasSyntacticModifier(node, ast.ModifierFlagsAmbient|ast.ModifierFlagsExport|ast.ModifierFlagsDefault) {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion internal/ls/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func isInString(file *ast.SourceFile, position int, previousToken *ast.Node) boo

func tryGetImportFromModuleSpecifier(node *ast.StringLiteralLike) *ast.Node {
switch node.Parent.Kind {
case ast.KindImportDeclaration, ast.KindExportDeclaration, ast.KindJSDocImportTag:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration, ast.KindExportDeclaration:
return node.Parent
case ast.KindExternalModuleReference:
return node.Parent.Parent
Expand Down
11 changes: 10 additions & 1 deletion internal/parser/reparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,16 @@ func (p *Parser) reparseTags(parent *ast.Node, jsDoc []*ast.Node) {
typeAlias.Loc = core.NewTextRange(tag.Pos(), tag.End())
typeAlias.Flags = p.contextFlags | ast.NodeFlagsReparsed
p.reparseList = append(p.reparseList, typeAlias)
// !!! @overload and other unattached tags (@callback, @import et al) support goes here
case ast.KindJSDocImportTag:
importTag := tag.AsJSDocImportTag()
importClause := importTag.ImportClause.Clone(&p.factory)
importClause.Flags |= ast.NodeFlagsReparsed
importClause.AsImportClause().IsTypeOnly = true
importDeclaration := p.factory.NewJSImportDeclaration(importTag.Modifiers(), importClause, importTag.ModuleSpecifier, importTag.Attributes)
importDeclaration.Loc = core.NewTextRange(tag.Pos(), tag.End())
importDeclaration.Flags = p.contextFlags | ast.NodeFlagsReparsed
p.reparseList = append(p.reparseList, importDeclaration)
// !!! @overload and other unattached tags (@callback et al) support goes here
}
if !isLast {
continue
Expand Down
2 changes: 1 addition & 1 deletion internal/printer/namegenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (g *NameGenerator) generateNameForNode(node *ast.Node, privateName bool, fl
panic("Generated name for a module or enum cannot be private and may have neither a prefix nor suffix")
}
return g.generateNameForModuleOrEnum(node)
case ast.KindImportDeclaration, ast.KindExportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration, ast.KindExportDeclaration:
if privateName || len(prefix) > 0 || len(suffix) > 0 {
panic("Generated name for an import or export cannot be private and may have neither a prefix nor suffix")
}
Expand Down
4 changes: 2 additions & 2 deletions internal/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3953,7 +3953,7 @@ func (p *Printer) emitStatement(node *ast.Statement) {
p.emitNamespaceExportDeclaration(node.AsNamespaceExportDeclaration())
case ast.KindImportEqualsDeclaration:
p.emitImportEqualsDeclaration(node.AsImportEqualsDeclaration())
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
p.emitImportDeclaration(node.AsImportDeclaration())
case ast.KindExportAssignment, ast.KindJSExportAssignment:
p.emitExportAssignment(node.AsExportAssignment())
Expand Down Expand Up @@ -5605,7 +5605,7 @@ func (p *Printer) generateNames(node *ast.Node) {
}
case ast.KindObjectBindingPattern, ast.KindArrayBindingPattern:
p.generateAllNames(node.AsBindingPattern().Elements)
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
p.generateNames(node.AsImportDeclaration().ImportClause)
case ast.KindImportClause:
p.generateNameIfNeeded(node.AsImportClause().Name())
Expand Down
2 changes: 2 additions & 0 deletions internal/transformers/commonjsmodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func (tx *CommonJSModuleTransformer) visitTopLevel(node *ast.Node) *ast.Node {
switch node.Kind {
case ast.KindImportDeclaration:
node = tx.visitTopLevelImportDeclaration(node.AsImportDeclaration())
case ast.KindJSImportDeclaration:
node = nil
case ast.KindImportEqualsDeclaration:
node = tx.visitTopLevelImportEqualsDeclaration(node.AsImportEqualsDeclaration())
case ast.KindExportDeclaration:
Expand Down
2 changes: 2 additions & 0 deletions internal/transformers/esmodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func (tx *ESModuleTransformer) visit(node *ast.Node) *ast.Node {
node = tx.visitSourceFile(node.AsSourceFile())
case ast.KindImportDeclaration:
node = tx.visitImportDeclaration(node.AsImportDeclaration())
case ast.KindJSImportDeclaration:
node = nil
case ast.KindImportEqualsDeclaration:
node = tx.visitImportEqualsDeclaration(node.AsImportEqualsDeclaration())
case ast.KindExportAssignment:
Expand Down
1 change: 1 addition & 0 deletions internal/transformers/esnext.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ func (tx *ESNextTransformer) transformUsingDeclarations(statementsIn []*ast.Stat

switch node.Kind {
case ast.KindImportDeclaration,
ast.KindJSImportDeclaration,
ast.KindImportEqualsDeclaration,
ast.KindExportDeclaration,
ast.KindFunctionDeclaration:
Expand Down
3 changes: 2 additions & 1 deletion internal/transformers/externalmoduleinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ func (c *externalModuleInfoCollector) collect() *externalModuleInfo {
hasImportDefault := false
for _, node := range c.sourceFile.Statements.Nodes {
switch node.Kind {
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
// import "mod"
// import x from "mod"
// import * as x from "mod"
// import { x, y } from "mod"
// @import versions of above
n := node.AsImportDeclaration()
c.addExternalImport(node)
if !hasImportStar && getImportNeedsImportStarHelper(n) {
Expand Down
4 changes: 2 additions & 2 deletions internal/transformers/importelision.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (tx *ImportElisionTransformer) visit(node *ast.Node) *ast.Node {
return nil
}
return tx.visitor.VisitEachChild(node)
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
if !tx.isElisionBlocked(node) {
n := node.AsImportDeclaration()
// Do not elide a side-effect only import declaration.
Expand Down Expand Up @@ -166,7 +166,7 @@ func (tx *ImportElisionTransformer) isElisionBlocked(node *ast.Node /*ImportDecl
}

switch node.Kind {
case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
n := node.AsImportDeclaration()
p := parsed.AsImportDeclaration()
if n.ImportClause != p.ImportClause {
Expand Down
2 changes: 1 addition & 1 deletion internal/transformers/typeeraser.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (tx *TypeEraserTransformer) visit(node *ast.Node) *ast.Node {
}
return tx.visitor.VisitEachChild(node)

case ast.KindImportDeclaration:
case ast.KindImportDeclaration, ast.KindJSImportDeclaration:
n := node.AsImportDeclaration()
if n.ImportClause == nil {
// Do not elide a side-effect only import declaration.
Expand Down
Loading