fix: extend value binding to export default expressions#21117
Conversation
Apply value binding optimization for `export default expr` which generates `const __WEBPACK_DEFAULT_EXPORT__`. Use isCircular === false to ensure optimization only applies when CircularModulesPlugin has run.
🦋 Changeset detectedLatest commit: 77b8e54 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (b0b716e). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@b0b716e
yarn add -D webpack@https://pkg.pr.new/webpack@b0b716e
pnpm add -D webpack@https://pkg.pr.new/webpack@b0b716e |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21117 +/- ##
==========================================
- Coverage 91.99% 91.98% -0.02%
==========================================
Files 581 581
Lines 61433 61441 +8
Branches 16787 16791 +4
==========================================
- Hits 56516 56515 -1
- Misses 4917 4926 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will not alter performance
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "wasm-modules-sync", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
392.3 KB | 784.2 KB | -49.97% |
| ❌ | Memory | benchmark "many-modules-commonjs", scenario '{"name":"mode-development","mode":"development"}' |
922.2 KB | 1,825.1 KB | -49.47% |
| ❌ | Memory | benchmark "css-modules", scenario '{"name":"mode-development","mode":"development"}' |
552.9 KB | 750.8 KB | -26.36% |
| ⚡ | Memory | benchmark "react", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
330.1 KB | 152.6 KB | ×2.2 |
| ⚡ | Memory | benchmark "many-chunks-commonjs", scenario '{"name":"mode-production","mode":"production"}' |
9.2 MB | 6.7 MB | +37.49% |
| ⚡ | Memory | benchmark "many-modules-commonjs", scenario '{"name":"mode-production","mode":"production"}' |
9 MB | 7.4 MB | +21.36% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing fix/export-default-immutable-binding (77b8e54) with main (e861a84)
The default binding is always immutable per ES spec. Safety is ensured by the isCircular === false check which requires CircularModulesPlugin to have run.
Summary
Follow-up to #21021. That PR applied value binding optimization only to
HarmonyExportSpecifierDependency(named exports). This PR extends it toHarmonyExportExpressionDependencyforexport default expressionwhich generatesconst __WEBPACK_DEFAULT_EXPORT__— an immutable binding eligible for value descriptors.Also hardens the
isCircularcheck: uses=== falseinstead of!isCircular, soundefined(whenCircularModulesPluginhasn't run) prevents the optimization rather than allowing it.CircularModulesPluginnow explicitly setsisCirculartofalsefor non-circular modules.What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes — added
default-expr.js,default-fn-decl.js,default-fn-anon.jstest cases intest/configCases/optimization/static-export-bindings/.Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
Claude Code was used to draft the implementation under human review. All architectural decisions were made through interactive discussion.