Skip to content

fix(sourcemap): honor empty transform sourcemaps like Rollup - #11196

Closed
james-elicx wants to merge 5 commits into
rolldown:mainfrom
james-elicx:fix/honor-empty-transform-sourcemaps
Closed

james-elicx wants to merge 5 commits into
rolldown:mainfrom
james-elicx:fix/honor-empty-transform-sourcemaps

Conversation

@james-elicx

@james-elicx james-elicx commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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's sources and sourcesContent anyway. For @vitejs/plugin-rsc this publishes "use server" module source in client sourcemaps (vitejs/vite-plugin-react#1497).

There were two causes:

  1. normalize_transform_sourcemap (and its JS twin normalizeTransformHookSourcemap) filled a map that had no sources/sourcesContent with the module id and its pre-transform code, so { mappings: '' } became "the original module, with its content, and no mappings".
  2. Collapsing a module's sourcemap chain copied sources/sourcesContent from the first map, even when no token reached them. An earlier transform's map (e.g. TypeScript stripping) therefore brought the original back.

What

  • Leave transform maps that have no mappings unfilled, in both Rust and JS.
  • Add rolldown_sourcemap::drop_unreached_sources_and_names. It keeps only the sources and names a token references, and renumbers token ids and ignoreList to match, like Rollup's traceMappings(). Without the names part, identifiers from an earlier transform's map (e.g. TypeScript stripping) would still ship in names. It is applied to collapsed module chains (collapse_module_sourcemap) and to this.getCombinedSourcemap(), including when the chain holds a single transform map. As in Rollup, a load map that no transform remapped is still returned by getCombinedSourcemap() as is.

collapse_sourcemaps itself 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 from sources. That changed existing snapshots and three Rollup sourcemaps/ignore-list-* tests, so the filtering is scoped to the module's transform chain.

Tests

  • Unit tests for drop_unreached_sources_and_names and collapse_module_sourcemap (empty map alone, after a real map, and after an omitted map).
  • A Rust integration test (issues/11176) with native plugins, which checks sources, sourcesContent and names in both the output map and getCombinedSourcemap. 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 that getCombinedSourcemap() returns an untransformed load map unchanged.
  • A JS fixture (fixtures/issues/11176) that goes through the binding and the JS normalization.
  • Each fix was verified to be covered: reverting it makes at least one of the new tests fail.
  • rolldown-tests and the Rollup compat suite pass locally with no snapshot changes.

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]>
@james-elicx james-elicx closed this Nov 3, 2026
@james-elicx
james-elicx deleted the fix/honor-empty-transform-sourcemaps branch November 3, 2026 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request]: Honor empty transform sourcemaps ({ mappings: '' }) like Rollup

1 participant