Repository navigation
fix(sourcemap): honor empty transform sourcemaps like Rollup - #11196
Closed
james-elicx wants to merge 5 commits into
Closed
james-elicx wants to merge 5 commits into
james-elicx wants to merge 5 commits into
Conversation
A transform returning `map: { mappings: '' }` declares that its output has
no mapping back to the module's previous code. Rolldown filled such a map with
the module id and pre-transform code, and collapsing the module's chain copied
`sources`/`sourcesContent` from the first map even when no token reached
them, so the original module leaked into the emitted sourcemap.
- Leave mapping-less transform maps unfilled (Rust and JS normalization).
- Add `drop_unreached_sources` and apply it to collapsed module chains and
`getCombinedSourcemap`, keeping only sources a token reaches, like Rollup's
`traceMappings()`.
closes rolldown#11176
`collapse_sourcemaps` merges the names of every map in the chain, so an
earlier transform's names (e.g. identifiers from TypeScript stripping) still
reached the emitted map after a later transform returned `{ mappings: '' }`.
Prune names along with sources, like Rollup's `traceMappings()`, and rename
the helper to `drop_unreached_sources_and_names`.
…cemap
`getCombinedSourcemap` only pruned unreached sources and names when the chain
had two or more maps. A lone `{ mappings: '' }` map that still listed the
original module and its code was returned as is.
…ap as is Like Rollup, which returns the load hook's map unchanged when no transform remapped it, only prune unreached sources and names when the chain holds a transform map.
IWANABETHATGUY
added a commit
that referenced
this pull request
Nov 3, 2026
…ps (#11270) Closes #11176 A transform that returns `{ mappings: '' }` or omits its map still shipped the module's earlier code in `sources`, `sourcesContent` and `names`. Module sourcemaps now keep only the sources and names that a traced token references, like Rollup's `traceMappings()`. The chunk-level collapse is unchanged. `this.getCombinedSourcemap()` now drops untraced sources and names too, like Rollup, so plugins can see this change. A load map that no transform has remapped still comes back as is. Names are marked inside the existing remap loop, so a map without names does no extra work. `generate` time on rome (1542 TS modules, `sourcemap: true`) is unchanged. The `combined_sourcemap_keeps_untransformed_load_map` test is based on the test of the same name in #11196. Co-authored-by: James <[email protected]>
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.
closes #11176
Why
A transform that returns
map: { mappings: '' }declares that its output has no mapping back to the module's previous code (Rollup's documented contract). Rolldown kept the original module in the emitted map'ssourcesandsourcesContentanyway. For@vitejs/plugin-rscthis publishes"use server"module source in client sourcemaps (vitejs/vite-plugin-react#1497).There were two causes:
normalize_transform_sourcemap(and its JS twinnormalizeTransformHookSourcemap) filled a map that had nosources/sourcesContentwith the module id and its pre-transform code, so{ mappings: '' }became "the original module, with its content, and no mappings".sources/sourcesContentfrom the first map, even when no token reached them. An earlier transform's map (e.g. TypeScript stripping) therefore brought the original back.What
rolldown_sourcemap::drop_unreached_sources_and_names. It keeps only the sources and names a token references, and renumbers token ids andignoreListto match, like Rollup'straceMappings(). Without the names part, identifiers from an earlier transform's map (e.g. TypeScript stripping) would still ship innames. It is applied to collapsed module chains (collapse_module_sourcemap) and tothis.getCombinedSourcemap(), including when the chain holds a single transform map. As in Rollup, a load map that no transform remapped is still returned bygetCombinedSourcemap()as is.collapse_sourcemapsitself is unchanged. I first filtered there, but the chunk-level collapse (e.g. the minify pass) then dropped modules whose code is entirely inlined away fromsources. That changed existing snapshots and three Rollupsourcemaps/ignore-list-*tests, so the filtering is scoped to the module's transform chain.Tests
drop_unreached_sources_and_namesandcollapse_module_sourcemap(empty map alone, after a real map, and after an omitted map).issues/11176) with native plugins, which checkssources,sourcesContentandnamesin both the output map andgetCombinedSourcemap. It covers an empty map alone, one after a real map that carries names, and a single empty map that still lists the original source. A further test checks thatgetCombinedSourcemap()returns an untransformed load map unchanged.fixtures/issues/11176) that goes through the binding and the JS normalization.rolldown-testsand the Rollup compat suite pass locally with no snapshot changes.