test: add edge case coverage for cjs require destructuring tree shaking#20596
Conversation
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
|
Merging this PR will degrade performance by 22.53%
Performance Changes
Comparing |
|
This PR is packaged and the instant preview is available (f588954). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@f588954
yarn add -D webpack@https://pkg.pr.new/webpack@f588954
pnpm add -D webpack@https://pkg.pr.new/webpack@f588954 |
Adds three missing test assertions for the feature introduced in #20548:
{ a: renamedA }) marks the original key as used{ a = 'fallback' }) still marks the key as used{ a, ...rest }) bails the analysis, all exports keptA separate
module-rest.jsfixture is used for the rest element test to avoid contaminating other tests — rest bail-out affects allrequire()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.