fix(core): preserve external namespace access in esm externals#13442
fix(core): preserve external namespace access in esm externals#13442JSerFeng merged 5 commits intoweb-infra-dev:mainfrom
Conversation
|
@codex review |
There was a problem hiding this comment.
Pull request overview
This PR fixes ESM external generation to preserve namespace-member access (e.g. import * as ns from "ext"; ns.foo) by tracking namespace-member usage explicitly and only disabling the named-import concatenation optimization when that usage is detected.
Changes:
- Add an explicit
ns_accessflag to referenced export tracking and propagate it through export usage analysis. - Update
ExternalModule::get_source()to fall back to namespace import when any used named export is accessed via a namespace object. - Add an
esmOutputCasesregression test and update affected JSX / tree-shaking snapshots to match the new render behavior.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/rspack-test/treeShakingCases/issue-4637/snapshots/treeshaking.snap.txt | Snapshot update reflecting changed module ordering/rendering. |
| tests/rspack-test/esmOutputCases/externals/namespace-member-access/rspack.config.js | New regression case config for external namespace member access. |
| tests/rspack-test/esmOutputCases/externals/namespace-member-access/index.js | New regression test source using import * as + member access. |
| tests/rspack-test/esmOutputCases/externals/namespace-member-access/snapshots/esm.snap.txt | Snapshot asserting generated ESM keeps a namespace import for the external. |
| tests/rspack-test/configCases/parsing/jsx-enabled/test.js | Adjust assertion to match new JSX output patterns. |
| tests/rspack-test/configCases/parsing/jsx-enabled/snapshot/bundle0.jsx.txt | Snapshot update reflecting namespace-style access in output. |
| crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs | Propagate ns_access into ExportInfo during used-exports flagging/merging. |
| crates/rspack_plugin_javascript/src/parser_plugin/esm_import_dependency_parser_plugin.rs | Track whether an import is a namespace import and compute ns_access for member usage. |
| crates/rspack_plugin_javascript/src/dependency/esm/esm_import_specifier_dependency.rs | Store ns_access on the dependency and emit it via ReferencedExport. |
| crates/rspack_plugin_javascript/src/dependency/commonjs/common_js_export_require_dependency.rs | Initialize new ReferencedExport.ns_access field for CommonJS require-export paths. |
| crates/rspack_core/src/external_module.rs | Disable named-import concatenation optimization when ns_access is present for used named exports. |
| crates/rspack_core/src/exports/referenced_export.rs | Add ns_access to referenced export metadata. |
| crates/rspack_core/src/exports/export_info.rs | Add ns_access storage + getter/setter on export info. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
tests/rspack-test/esmOutputCases/externals/namespace-member-access/rspack.config.js
Show resolved
Hide resolved
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 89f19ad2a2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
ns_accessflag for ESM namespace-member usage instead of inferring fromdirect_importExternalModule::get_source()sees namespace access in exports infoesmOutputCasesregression and update affected JSX/tree-shaking snapshots to match the new rendering behaviorTesting
cargo fmt --all --checkcargo clippy -p rspack_core -p rspack_plugin_javascript -- -D warningspnpm run build:binding:devpnpm run test:unitcd tests/rspack-test && pnpm run test:basepnpm run test:hotpnpm run test:e2e