Skip to content

feat: add support for logical assignment operators in environment config#21219

Merged
alexander-akait merged 6 commits into
webpack:mainfrom
bjohansebas:feat/environment-logical-assignment
Jun 20, 2026
Merged

feat: add support for logical assignment operators in environment config#21219
alexander-akait merged 6 commits into
webpack:mainfrom
bjohansebas:feat/environment-logical-assignment

Conversation

@bjohansebas

Copy link
Copy Markdown
Member

Summary

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR_assignment

What kind of change does this PR introduce?

Did you add tests for your changes?

Does this PR introduce a breaking change?

If relevant, what needs to be documented once your changes are merged or what have you already documented?

Use of AI

@changeset-bot

changeset-bot Bot commented Jun 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 292b069

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack Minor

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

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.78%. Comparing base (5ba1265) to head (292b069).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #21219   +/-   ##
=======================================
  Coverage   92.77%   92.78%           
=======================================
  Files         591      591           
  Lines       64458    64487   +29     
  Branches    17908    17920   +12     
=======================================
+ Hits        59802    59833   +31     
+ Misses       4656     4654    -2     
Flag Coverage Δ
css-parsing 28.72% <9.52%> (+<0.01%) ⬆️
html5lib 31.17% <11.76%> (+<0.01%) ⬆️
integration 88.75% <100.00%> (+<0.01%) ⬆️
test262 45.53% <20.00%> (+0.02%) ⬆️
unit 41.13% <47.05%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq

codspeed-hq Bot commented Jun 18, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 77.16%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 3 regressed benchmarks
✅ 141 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory benchmark "lodash", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 128.4 KB 858.6 KB -85.05%
Memory benchmark "side-effects-reexport", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 133.3 KB 859.1 KB -84.48%
Memory benchmark "wasm-modules-sync", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 130 KB 253 KB -48.62%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing bjohansebas:feat/environment-logical-assignment (292b069) with main (6e5bd5d)

Open in CodSpeed

@bjohansebas bjohansebas marked this pull request as ready for review June 18, 2026 19:45
Copilot AI review requested due to automatic review settings June 18, 2026 19:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the change end-to-end. The core transformation looks correct: target ||= value is semantically equivalent to the previous target = target || value for every call site here (all targets are member accesses on plain objects/arrays/globals, so the "evaluated twice" / falsy-value concerns don't bite), and the object-literal extraction in the chunk-loading modules preserves the exact emitted formatting. A couple of non-blocking observations, plus two inline notes:

  • lib/library/UmdLibraryPlugin.js (accessorAccess) still emits ${a} = ${a} || {} for the namespace walk and wasn't migrated to assignOr. Is that intentional (UMD aiming for maximal compatibility), or just missed? If intentional, fine — just flagging the inconsistency.

  • The browserslist version table and the node/esX mappings line up with the ES2021 / Chromium-85 baseline, so those look right.

Main suggestion is the missing end-to-end test for the ||= branch (see inline comment on the unit test).


Generated by Claude Code

});
});

describe("RuntimeTemplate.assignOr", () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This unit test covers assignOr in isolation, but the seven runtime modules that now call it (jsonp/import-scripts/module/read-file/require/wasm chunk loaders, share + css registry) are only exercised with the default logicalAssignment: undefined, i.e. the fallback branch. Nothing asserts that the ||= branch is actually emitted and produces valid runtime. Consider adding a configCase that builds with output.environment.logicalAssignment: true and checks the generated runtime contains ||=, so a future regression in any of those templates is caught end-to-end.


Generated by Claude Code

Comment thread lib/RuntimeTemplate.js
* @param {string} value default value expression
* @returns {string} assignment expression
*/
assignOr(target, value) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Worth noting in the JSDoc (or just keeping in mind for future callers): assignOr only models the ||/||= case, so it must never be used where target can hold a legitimate falsy value (0, "", false) — it would overwrite it. All current call sites default to objects/arrays, so this is safe today, but the helper name is generic enough that a later caller could trip on it. A one-line caveat in the doc comment would prevent that.


Generated by Claude Code

@alexander-akait

Copy link
Copy Markdown
Member

Fast review from Claude, other let’s rebase, thanks for this PR

…figuration

- Updated WebpackOptions.json schema to include `logicalAssignment` property indicating support for logical assignment operators ('a ||= b', 'a &&= b', 'a ??= b').
- Modified Defaults.unittest.js to include tests for the new `logicalAssignment` property, ensuring it is correctly handled in various scenarios.
- Enhanced RuntimeTemplate with `assignOr` method to utilize logical assignment when supported, providing a fallback for environments that do not support it.
- Updated snapshot tests to reflect changes in logical assignment handling across various configurations.
- Extended types.d.ts to declare the new `logicalAssignment` property in the Environment interface and added corresponding methods in RuntimeTemplate.
@bjohansebas bjohansebas force-pushed the feat/environment-logical-assignment branch from c4d096c to 5c1426e Compare June 19, 2026 14:57
@bjohansebas

Copy link
Copy Markdown
Member Author

done the rebase

Copilot AI review requested due to automatic review settings June 19, 2026 15:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@alexander-akait

Copy link
Copy Markdown
Member

Looks like some tests failed, let’s fix and we can merge

Copilot AI review requested due to automatic review settings June 20, 2026 03:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@alexander-akait alexander-akait left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks

@alexander-akait alexander-akait merged commit 12b8106 into webpack:main Jun 20, 2026
61 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (12b8106).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@12b8106
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@12b8106
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@12b8106

@bjohansebas bjohansebas deleted the feat/environment-logical-assignment branch June 20, 2026 15:27
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.

3 participants