Skip to content

fix(renamer): keep generated top-level names off inner bindings - #11121

Merged
IWANABETHATGUY merged 4 commits into
mainfrom
refactor/hygienic-renamer
Oct 8, 2026
Merged

IWANABETHATGUY merged 4 commits into
mainfrom
refactor/hygienic-renamer

Conversation

@IWANABETHATGUY

@IWANABETHATGUY IWANABETHATGUY commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Renaming could redeclare a sibling local inside a __commonJSMin closure, or let a local capture a reference rolldown generates (require_x(), __toESM, import_x, require_<chunk>), because CJS closure locals and generated references were invisible to most renaming passes. Generated names now take the $N suffix instead of the source's locals, which is why four existing snapshots changed.

fixes #10970
refs #10971 (its fixtures are included)

@netlify

netlify Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs canceled.

Name Link
🔨 Latest commit 2d9308f
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6ac715fa32018e00085d61b7

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://refactor-hygienic-renamer-rolldown-rs.voidzero-docs.workers.dev (commit 2d9308f)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://4491b08d-rolldown-rs.voidzero-docs.workers.dev 2d9308f 2026-10-08T04:05:18.423Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c5975666-rolldown-rs.voidzero-docs.workers.dev cdf10ca 2026-10-07T17:09:16.999Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://6cc9a4f4-rolldown-rs.voidzero-docs.workers.dev dae4452 2026-10-07T13:02:36.808Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://c530e1fe-rolldown-rs.voidzero-docs.workers.dev 91ee941 2026-10-07T12:49:38.997Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://d02aa207-rolldown-rs.voidzero-docs.workers.dev 42a7e8a 2026-10-07T09:43:46.590Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://236b3a2f-rolldown-rs.voidzero-docs.workers.dev 2b4abfb 2026-10-07T09:10:58.429Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://4410ba66-rolldown-rs.voidzero-docs.workers.dev cc8ad8e 2026-10-07T08:57:10.804Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://79342f3a-rolldown-rs.voidzero-docs.workers.dev e3108d5 2026-10-07T08:14:14.801Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://7f4fa879-rolldown-rs.voidzero-docs.workers.dev 9ef0dd3 2026-10-06T17:58:45.980Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://46528830-rolldown-rs.voidzero-docs.workers.dev 2ad8ba0 2026-10-06T07:23:32.155Z Visit the dashboard ↗

View all previews: View all previews ↗

@IWANABETHATGUY
IWANABETHATGUY force-pushed the refactor/hygienic-renamer branch from 9b2caff to d114c59 Compare October 6, 2026 06:10
@IWANABETHATGUY
IWANABETHATGUY removed this pull request from stack #11124 October 6, 2026 07:19
@IWANABETHATGUY
IWANABETHATGUY force-pushed the refactor/hygienic-renamer branch from d114c59 to 2ad8ba0 Compare October 6, 2026 07:20
@IWANABETHATGUY
IWANABETHATGUY changed the base branch from main to fix/renamer-printed-name-captures October 6, 2026 07:20
@IWANABETHATGUY IWANABETHATGUY changed the title fix: avoid naming collisions with CJS closure locals and nested bindings fix(renamer): keep generated top-level names off inner bindings Oct 6, 2026
@IWANABETHATGUY
IWANABETHATGUY force-pushed the refactor/hygienic-renamer branch from 2ad8ba0 to 9ef0dd3 Compare October 6, 2026 17:56
@IWANABETHATGUY
IWANABETHATGUY force-pushed the refactor/hygienic-renamer branch from e3108d5 to cc8ad8e Compare October 7, 2026 08:55
@IWANABETHATGUY
IWANABETHATGUY force-pushed the refactor/hygienic-renamer branch 3 times, most recently from 42a7e8a to 91ee941 Compare October 7, 2026 12:46
Base automatically changed from fix/renamer-printed-name-captures to main October 7, 2026 12:58
@IWANABETHATGUY
IWANABETHATGUY force-pushed the refactor/hygienic-renamer branch 2 times, most recently from dae4452 to cdf10ca Compare October 7, 2026 17:06
@IWANABETHATGUY
IWANABETHATGUY marked this pull request as ready for review October 8, 2026 02:10
@codspeed

codspeed Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing refactor/hygienic-renamer (2d9308f) with main (f7de35f)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 (ccf2ab4) during the generation of this report, so f7de35f was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

A CJS-wrapped module's top-level locals are printed inside its `__commonJS`
closure, so they stay out of the chunk namespace (#7425). When one shadowed a
name rolldown generates, the root-scope loop renamed it against the chunk's
top-level names only, which could land it on a sibling local the resolver
never saw (#10970, cases 1 and 3). Every kind of generated reference (wrapper
calls, namespace objects, `import_x`, runtime helpers, `require_<chunk>`
bindings, IIFE/UMD factory params) also needed its own shadowing pass.

Names rolldown invents now never take a name that a nested-scope binding or a
CJS-closure binding of the chunk uses (`InnerBindingNames`), so no source
binding can capture a reference the finalizer prints. Source-named top-level
bindings (`RootBindingKind::Authored`) keep the old rules. CJS closure locals
are no longer named at the chunk level at all; the nested-scope passes rename
one only when it would capture a source reference.

This removes `collect_chunk_scope_captured_names`,
`rename_cjs_locals_shadowing_referenced_chunk_bindings` and
`override_root_scope_binding`. It also fixes captures the old passes missed:
a wrapper renamed onto an importer's parameter, a nested `require_dep`,
`import_dep` or `__toESM` param, a CJS local named like a runtime helper, and
a `require_<chunk>` binding under CJS output.

The four CJS-shadowing fixtures now suffix the generated wrapper or namespace
instead of the source's local.
@IWANABETHATGUY
IWANABETHATGUY force-pushed the refactor/hygienic-renamer branch from cdf10ca to 2d9308f Compare October 8, 2026 04:02
@IWANABETHATGUY
IWANABETHATGUY merged commit 40d03e6 into main Oct 8, 2026
36 of 37 checks passed
@IWANABETHATGUY
IWANABETHATGUY deleted the refactor/hygienic-renamer branch October 8, 2026 04:15
@rolldown-guard rolldown-guard Bot mentioned this pull request Oct 14, 2026
shulaoda added a commit that referenced this pull request Oct 14, 2026
## [1.2.14] - 2026-10-14

### 🚀 Features

- add `output.charset` option (#11194) by @sapphi-red
- code-splitting: route independent ESM re-exports per consumer (#11177) by @hyfdev

### 🐛 Bug Fixes

- handle `output.charset: 'ascii'` + `output.minify: false` (#11207) by @sapphi-red
- tree-shaking: preserve initialization of wrapped ESM re-exports (#11167) by @hyfdev
- sourcemap: preserve boundaries when tracing has no mapping (#11170) by @sapphi-red
- strict-execution-order: account for init imports during code splitting (#11162) by @hyfdev
- strict-execution-order: avoid eager loading through mixed re-exports (#11151) by @hyfdev
- tree-shake expression statements that coerce known constants (#10825) by @IWANABETHATGUY
- shim-missing-exports: shim deep namespace reads through default imports (#11184) by @IWANABETHATGUY
- shim-missing-exports: shim missing static namespace members (#11179) by @hyfdev
- preserve-entry-signatures: keep internal bindings out of entry exports (#11094) by @hyfdev
- report ASSIGN_TO_IMPORT for writes to re-exported namespace members (#11148) by @IWANABETHATGUY
- dev: keep files loaded by the HMR stage watched when the same task rebuilds (#11154) by @Brooooooklyn
- dev: watch lazily compiled files even when a build starts first (#11152) by @Brooooooklyn
- cjs: print a CommonJS module's top-level `this` as a wrapper parameter rolldown names (#11135) by @IWANABETHATGUY
- renamer: keep fixed names off the bindings that would capture them (#11134) by @IWANABETHATGUY
- renamer: keep an external `require()` local in a CJS module off the top-level names (#11133) by @IWANABETHATGUY
- rolldown: make a repeated `close()` a no-op (#11142) by @Brooooooklyn
- avoid renaming entry top-level bindings onto their nested bindings (#11122) by @IWANABETHATGUY
- renamer: keep generated top-level names off inner bindings (#11121) by @IWANABETHATGUY

### 🚜 Refactor

- renamer: treat a CJS-wrapped module's root scope as an inner scope (#11130) by @IWANABETHATGUY

### 📚 Documentation

- add renaming design and implementation docs (#11131) by @IWANABETHATGUY

### ⚡ Performance

- ci: overlap independent setup, checks, and artifacts (#11169) by @hyfdev

### 🧪 Testing

- dev: use dunce::canonicalize so dev engine tests pass on Windows (#11192) by @shulaoda
- preserve-entry-signatures: cover nested dynamic imports (#11164) by @hyfdev

### ⚙️ Miscellaneous Tasks

- deps: upgrade oxc to 0.154.0 (#11209) by @shulaoda
- make Security Analysis pass again (security-action v1.0.10, serde_yaml -> saphyr) (#11197) by @Brooooooklyn
- deps: update rollup submodule for tests to v4.64.5 (#11190) by @rolldown-guard[bot]
- deps: update test262 submodule for tests (#11191) by @rolldown-guard[bot]
- deps: update crate-ci/typos action to v1.51.1 (#11174) by @renovate[bot]
- vite-tests: link the workspace rolldown into the Vite clone again (#11147) by @Brooooooklyn

Co-authored-by: shulaoda <[email protected]>
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]: CJS locals renamed onto a sibling root-scope local inside __commonJSMin wrappers

2 participants