Skip to content

fix(core): preserve external namespace access in esm externals#13442

Merged
JSerFeng merged 5 commits intoweb-infra-dev:mainfrom
JSerFeng:fy/fix-external-namespace-access
Mar 24, 2026
Merged

fix(core): preserve external namespace access in esm externals#13442
JSerFeng merged 5 commits intoweb-infra-dev:mainfrom
JSerFeng:fy/fix-external-namespace-access

Conversation

@JSerFeng
Copy link
Copy Markdown
Contributor

Summary

  • add an explicit ns_access flag for ESM namespace-member usage instead of inferring from direct_import
  • only disable external named-import concatenation optimization when ExternalModule::get_source() sees namespace access in exports info
  • add an esmOutputCases regression and update affected JSX/tree-shaking snapshots to match the new rendering behavior

Testing

  • cargo fmt --all --check
  • cargo clippy -p rspack_core -p rspack_plugin_javascript -- -D warnings
  • pnpm run build:binding:dev
  • pnpm run test:unit
  • cd tests/rspack-test && pnpm run test:base
  • pnpm run test:hot
  • pnpm run test:e2e

Copilot AI review requested due to automatic review settings March 24, 2026 02:55
@github-actions github-actions bot added the release: bug fix release: bug related release(mr only) label Mar 24, 2026
@JSerFeng
Copy link
Copy Markdown
Contributor Author

@codex review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_access flag 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 esmOutputCases regression 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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 24, 2026

Merging this PR will not alter performance

✅ 23 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing JSerFeng:fy/fix-external-namespace-access (011e3a6) with main (02dff5b)

Open in CodSpeed

Footnotes

  1. 3 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.

@JSerFeng JSerFeng merged commit 5548872 into web-infra-dev:main Mar 24, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants