Repository navigation
fix(toExports): dedupe duplicate identifiers for class/enum declarations - #529
Conversation
When `includeType` is enabled, classes/enums/const-enums/interfaces that live in both the value and type spaces are kept as two separate entries by `dedupeImports` (since unjs#507). `toExports` then emitted them both, producing invalid output like: export { Foo, Foo } from 'src/Foo'; A single `export { Foo }` already re-exports both the value and the type for these declaration kinds, so dedupe by exported alias before stringifying, preferring the value import when both forms exist. Fixes unjs#498
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughModified Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #529 +/- ##
==========================================
- Coverage 98.73% 94.72% -4.01%
==========================================
Files 14 13 -1
Lines 1817 1005 -812
Branches 374 331 -43
==========================================
- Hits 1794 952 -842
- Misses 23 49 +26
- Partials 0 4 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
When
includeTypeis enabled,toExportscould emit invalid code:This happens because classes (and enums, const enums, interfaces) live in both the value and type spaces. Since #507,
dedupeImportsintentionally keeps both a value entry and a type-only entry for these declarations.toExportsthen stringified both, producing the duplicate.A single
export { Foo }already re-exports both the value and the type for class/enum/interface declarations, so this PR dedupes entries by their exported alias before stringifying, preferring the value import when both forms exist.Before / After
Input:
Before:
export { Foo, Foo } from 'src/Foo';❌ (SyntaxError)After:
export { Foo } from 'src/Foo';✅Test plan
pnpm vitest run— 203 tests pass (2 new: dedupe with value-then-type order, and type-then-value order)pnpm buildpnpm lintFixes #498
Summary by CodeRabbit
Bug Fixes
Tests