Skip to content

Commit f5c6b5e

Browse files
committed
fix: handle empty NamedImport to prevent malformed output
When disableImportRemovalOnOrganize is true or a library is in ignoredFromRemoval, an `import {} from 'lib'` would pass through the pipeline and produce `import from 'lib';` (invalid syntax). Now renders as `import 'lib';` (side-effect import) instead.
1 parent 983ff0a commit f5c6b5e

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/imports/import-manager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,12 @@ export class ImportManager {
914914
}
915915

916916
if (imp instanceof NamedImport) {
917+
// Handle empty NamedImport (import {} from 'lib') — render as side-effect import
918+
// This can happen when disableImportRemovalOnOrganize is true or library is in ignoredFromRemoval
919+
if (!imp.defaultAlias && imp.specifiers.length === 0) {
920+
return `import ${quote}${imp.libraryName}${quote}${attrs}${semi}`;
921+
}
922+
917923
const parts: string[] = [];
918924

919925
// Add 'type' keyword for type-only imports (TS 3.8+)

0 commit comments

Comments
 (0)