fix: preserve type modifier for export type * re-exports#216
Open
benpsnyder wants to merge 1 commit intosxzz:mainfrom
Open
fix: preserve type modifier for export type * re-exports#216benpsnyder wants to merge 1 commit intosxzz:mainfrom
type modifier for export type * re-exports#216benpsnyder wants to merge 1 commit intosxzz:mainfrom
Conversation
`export type * from './mod'` was losing its type-only semantics during bundling because `rewriteImportExport` unconditionally set `exportKind = 'value'` on all `ExportAllDeclaration` nodes without tracking which sources were type-only. The fix resolves source modules of `export type *` declarations before the modifier is stripped, then marks all of their exported bindings as type-only during chunk rendering. Closes sxzz#95 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
export type * from './mod'loses thetypemodifier during bundling, producing incorrect.d.tsoutput where re-exported names appear as value exports instead of type-only exports.For example, given:
where
./allexportsconst all = 42, the bundled output was:instead of the correct:
This only affected the bare
export type *form — the namespace form (export type * as ns from) already worked because Babel parses it asExportNamedDeclarationwithExportNamespaceSpecifier, which goes through the existing type-only tracking path.Root Cause
In
rewriteImportExport(),ExportAllDeclarationnodes had theirexportKindunconditionally set to'value'so Rolldown can process them as JavaScript. But unlikeExportNamedDeclaration(which has specifiers whose names get tracked intypeOnlyIds),ExportAllDeclarationhas no specifiers — so there was nothing to track, and the type-only information was silently discarded.Fix
rewriteImportExportruns, resolving source modules ofexport type *declarations and recording them in atypeOnlyStarSourcesset.moduleExportBindings.renderChunk, for any source module that was a target ofexport type *, add all of its exported bindings totypeOnlyIdssopatchImportExportcorrectly restores thetypemodifier.Related
export *losestypemodifiers when flattening re-exports #95declare modulespecifiers to output chunk paths #191 also maketransformasync — there will be positional merge conflicts with whichever lands second, but no semantic overlapTest plan
type-only-exportfixture now correctly outputstype all(snapshot updated)resolve-dtsfixture now correctly outputstype Foo(snapshot updated)rollup-plugin-dts/export-all-as-typecompatibility test now correctly outputstype foo(snapshot updated)