fix(deconflict): rename CJS locals shadowing wrapped-ESM namespace objects#9970
fix(deconflict): rename CJS locals shadowing wrapped-ESM namespace objects#9970IWANABETHATGUY wants to merge 1 commit into
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
0acfd6b to
b07d5db
Compare
89d1a08 to
c3968fa
Compare
b07d5db to
7da5f84
Compare
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd the label graphite: merge-when-ready to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
7da5f84 to
22a0b55
Compare
a5f5037 to
cfad266
Compare
058482c to
c35d12a
Compare
cfad266 to
a5b2c80
Compare
c35d12a to
2e3d1cb
Compare
✅ Deploy Preview for rolldown-rs canceled.
|
2e3d1cb to
5ff4397
Compare
…jects A CJS-wrapped module that `require()`s a wrapped-ESM module reads the importee's chunk-root namespace object via `(init_x(), __toCommonJS(xxx_exports))`. An author-local sharing that namespace object's final name shadows the read, producing the self-referential `var xxx_exports = (init_x(), __toCommonJS(xxx_exports))` -> `__toCommonJS(undefined)` -> TypeError at module-eval (issue #9882, require()/namespace channel). Handle this in the precise `rename_cjs_locals_shadowing_referenced_chunk_bindings` post-pass (the same mechanism #9921 uses for named-import and star-member shadowing): for each `require()` of a non-CommonJS importee, rename a root-scope local sharing the importee namespace object''s *final* name. The post-pass runs after root-scope names are assigned, so it sees the namespace''s real name and only touches modules that actually reference it -- renaming the shadowing local, never the namespace. Adds the regression fixture cjs_shadowing_require_namespace_object: it throws `__toCommonJS(undefined)` on the base and passes with the fix.
67e3b00 to
f2d1006
Compare

Standalone PR on
main(the #9921 / #10006 stack it followed is now merged).Extends the #9882 chunk-root shadowing fix to one more channel: a CJS closure local that shadows a wrapped-ESM namespace object read via
require().Problem
When a CJS-wrapped module
require()s a wrapped-ESM module, the finalizer rewrites the require to(init_x(), __toCommonJS(xxx_exports))— reading the importee's chunk-root namespace object. An author-local sharing that namespace object's final name shadows the read, producing a self-referential declaration:→
TypeError: Cannot convert undefined or null to objectat module-eval time.Fix
Handle this in the precise
rename_cjs_locals_shadowing_referenced_chunk_bindingspost-pass — the same mechanism #9921 already uses for named-import and star-member shadowing. For eachrequire()of a non-CommonJS importee (mirroring the finalizer's gate), rename a root-scope local that shares the importee namespace object's final name.Why the post-pass rather than the chunk-root captured-name set: it runs after root-scope names are assigned, so it sees the namespace object's real (possibly renamed) name, and it only touches modules that actually reference the namespace — renaming the shadowing local, never the namespace.
Test
cjs_shadowing_require_namespace_object— throws__toCommonJS(undefined)without the fix, passes with it (the namespace keeps its bare name, the colliding local is suffixed). The shared sibling-suffix-skipping path of the renamer is already covered bycjs_shadowing_renamed_chunk_binding.Full integration suite: 1778 passed, 0 failed.