Skip to content

fix(sourcemap): preserve names when collapsing sourcemap on minify (#10839) - #10871

Closed
justonemorenight wants to merge 2 commits into
rolldown:mainfrom
justonemorenight:fix/sourcemap-names-on-minify
Closed

justonemorenight wants to merge 2 commits into
rolldown:mainfrom
justonemorenight:fix/sourcemap-names-on-minify

Conversation

@justonemorenight

Copy link
Copy Markdown
Contributor

Description

Fixes #10839

When minification and sourcemaps are enabled, oxc's codegen/mangler generates a sourcemap containing mangled identifier mapping names in last_map.names (e.g. ["greet", "personName"]), with the corresponding tokens referencing these names via name_id.

However, collapse_sourcemaps was only taking first_map.get_names() and original_token.get_name_id(). Since first_map (the pre-minification chunk map) had not mangled identifiers, its names list was empty and original_token.get_name_id() was None. As a result, the collapsed sourcemap had an empty names array and lost all token name_id references, preventing DevTools/debuggers from recovering the original symbol names.

Solution

  1. Propagate Names Across Sourcemap Chain (rolldown_sourcemap):
    • In collapse_sourcemaps, trace name starting from token.get_name_id() on last_map.
    • As tokens are traced back through the chain, if an upstream sourcemap in the chain also has a name at that location (closer to the original source), that upstream name takes precedence (aligned with Rollup's collapseSourcemaps algorithm).
    • Pre-seed the output names table with any existing names from first_map, and append new unique names encountered during token tracing using a hash map lookup.
    • Set the 5th field of the collapsed token (name_id) to the mapped index in the consolidated names array.
  2. Populate OutputAsset.names (rolldown):
    • In emit_sourcemap, populate OutputAsset.names from map.get_names() rather than hardcoding vec![].
  3. Tests:
    • Added unit test test_collapse_sourcemaps_preserves_names_from_minifier in rolldown_sourcemap.
    • Added integration test fixture crates/rolldown/tests/rolldown/sourcemap/minify_sourcemap_names with node assertions verifying that sourceMap.names in dist/main.js.map contains the renamed identifiers (greet, personName).

@codspeed

codspeed Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing justonemorenight:fix/sourcemap-names-on-minify (4ec4636) with main (a1ac2f8)2

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (096569f) during the generation of this report, so a1ac2f8 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@justonemorenight
justonemorenight force-pushed the fix/sourcemap-names-on-minify branch from 0f03201 to 554f596 Compare September 14, 2026 07:57
@sapphi-red

Copy link
Copy Markdown
Member

Fixed by #9486

@sapphi-red sapphi-red closed this Sep 25, 2026
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.

[Bug]: minify sourcemap has an empty names array — original identifiers unrecoverable

2 participants