Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
20 changes: 9 additions & 11 deletions internal/transformers/tstransforms/importelision.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ func (tx *ImportElisionTransformer) visit(node *ast.Node) *ast.Node {
}
return tx.Visitor().VisitEachChild(node)
case ast.KindImportDeclaration:
if !tx.isElisionBlocked(node) {
n := node.AsImportDeclaration()
// Do not elide a side-effect only import declaration.
// import "foo";
if n.ImportClause != nil {
importClause := tx.Visitor().VisitNode(n.ImportClause)
if importClause == nil {
return nil
}
return tx.Factory().UpdateImportDeclaration(n, n.Modifiers(), importClause, n.ModuleSpecifier, tx.Visitor().VisitNode(n.Attributes))
n := node.AsImportDeclaration()
// Do not elide a side-effect only import declaration.
// import "foo";
if n.ImportClause != nil {
importClause := tx.Visitor().VisitNode(n.ImportClause)
if importClause == nil {
return nil
}
return tx.Factory().UpdateImportDeclaration(n, n.Modifiers(), importClause, n.ModuleSpecifier, tx.Visitor().VisitNode(n.Attributes))
}
return tx.Visitor().VisitEachChild(node)
Comment on lines 42 to 53
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

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

The PR description says the fix is to elide imports even when isElisionBlocked is true only when the visited ImportClause becomes nil, but the implementation removes the isElisionBlocked gate for all ImportDeclarations. This changes behavior for any import declaration that was modified earlier in the pipeline (including by custom before transforms) and may re-enable elision in cases the isElisionBlocked contract is meant to prevent. Consider restoring the isElisionBlocked check for the general case and only bypassing it for the specific scenario where the visited ImportClause becomes nil (or adjust isElisionBlocked to treat TypeEraser updates as non-blocking).

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

The PR description was not updated to reflect the later changes, unfortunately

Copy link
Member

Choose a reason for hiding this comment

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

isElisionBlocked seems to only be needed for custom transformers, which we don't have, too.

case ast.KindImportClause:
Expand All @@ -77,7 +75,7 @@ func (tx *ImportElisionTransformer) visit(node *ast.Node) *ast.Node {
}
return tx.Factory().UpdateNamedImports(n, elements)
case ast.KindImportSpecifier:
if !tx.shouldEmitAliasDeclaration(node) {
if node.IsTypeOnly() || !tx.shouldEmitAliasDeclaration(node) {
// elide type-only or unused imports
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type; // Error (cannot resolve name)
as; // Error (used in emitting position)
export {};
//// [d.js]
import "./mod.js"; // Error
export {};
//// [e.js]
import { type as type } from "./mod.js";
type;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface LocalInterface extends RequireInterface, ImportInterface {}
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// not exclusively type-only
require("pkg");


//// [index.d.ts]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface LocalInterface extends RequireInterface, ImportInterface {}
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// not exclusively type-only
require("pkg");


//// [index.d.ts]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface LocalInterface extends RequireInterface, ImportInterface {}
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// not exclusively type-only
require("pkg");


//// [index.d.ts]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface LocalInterface extends RequireInterface, ImportInterface {}
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// not exclusively type-only
require("pkg");


//// [index.d.ts]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface LocalInterface extends RequireInterface, ImportInterface {}
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// not exclusively type-only
require("pkg");


//// [index.d.ts]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface LocalInterface extends RequireInterface, ImportInterface {}
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// not exclusively type-only
require("pkg");


//// [index.d.ts]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface LocalInterface extends RequireInterface, ImportInterface {}
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// not exclusively type-only
require("pkg");


//// [index.d.ts]
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export interface LocalInterface extends RequireInterface, ImportInterface {}
//// [index.js]
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// not exclusively type-only
require("pkg");


//// [index.d.ts]
Expand Down

This file was deleted.

Loading