Skip to content

test: add edge case coverage for cjs require destructuring tree shaking#20596

Merged
alexander-akait merged 1 commit intowebpack:mainfrom
aryanraj45:test/cjs-destructuring-edge-cases
Mar 6, 2026
Merged

test: add edge case coverage for cjs require destructuring tree shaking#20596
alexander-akait merged 1 commit intowebpack:mainfrom
aryanraj45:test/cjs-destructuring-edge-cases

Conversation

@aryanraj45
Copy link
Copy Markdown
Contributor

Adds three missing test assertions for the feature introduced in #20548:

  • aliased destructuring ({ a: renamedA }) marks the original key as used
  • aliased context require (template literal) same behavior
  • default value destructuring ({ a = 'fallback' }) still marks the key as used
  • rest element ({ a, ...rest }) bails the analysis, all exports kept

A separate module-rest.js fixture is used for the rest element test to avoid contaminating other tests — rest bail-out affects all require() calls to the same module within a file.

Summary

#20548 added CJS require destructuring tree shaking but shipped with only two basic tests. These edge cases (aliased keys, default values, rest element bail-out) were untested and represent distinct code paths in _preWalkObjectPattern.

What kind of change does this PR introduce?

test

Did you add tests for your changes?

This PR is only tests.

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

No AI was used.

Adds three missing test assertions for the feature introduced in webpack#20548:

- aliased destructuring ({ a: renamedA }) marks the original key as used
- aliased context require (template literal) same behavior
- default value destructuring ({ a = 'fallback' }) still marks the key as used
- rest element ({ a, ...rest }) bails the analysis, all exports kept
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 5, 2026

⚠️ No Changeset found

Latest commit: 21eb8c2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 6, 2026

Merging this PR will degrade performance by 22.53%

⚡ 3 improved benchmarks
❌ 1 regressed benchmark
✅ 140 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory benchmark "lodash", scenario '{"name":"mode-development","mode":"development"}' 4.1 MB 5.3 MB -22.53%
Memory benchmark "asset-modules-source", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 388 KB 264.3 KB +46.78%
Memory benchmark "devtool-eval", scenario '{"name":"mode-production","mode":"production"}' 7.6 MB 6.2 MB +21.74%
Memory benchmark "future-defaults", scenario '{"name":"mode-production","mode":"production"}' 10 MB 7.9 MB +26.23%

Comparing aryanraj45:test/cjs-destructuring-edge-cases (21eb8c2) with main (a511177)

Open in CodSpeed

@alexander-akait alexander-akait merged commit f588954 into webpack:main Mar 6, 2026
53 of 55 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2026

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

Install it locally:

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

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.

2 participants