fix: tree-shake unused default export in dynamic-reexport mode#20557
fix: tree-shake unused default export in dynamic-reexport mode#20557shoryax wants to merge 1 commit intowebpack:mainfrom
Conversation
Fix: in dynamic-reexport mode, iterate over known exports and skip any that are in mode.ignored, so 'default' is correctly excluded and can be tree-shaken. Fixes: webpack#20537
|
|
|
@shoryax What you fixed? Your code look like AI generated, describe changes in logic |
|
I can’t see the issue based on the test case, and I don’t think this is a valid change.
|
this fixes the issue #20537, i:e,
when vue-loader generates an intermediary file that does export * from "./module", webpack falls into dynamic-reexport mode because it can't statically determine all exports. In this mode, it was returning EXPORTS_OBJECT_REFERENCED — marking ALL exports as used, including default.
But export * never re-exports default per the ES spec. The code already had mode.ignored which contains "default", but getReferencedExports wasn't checking it in the dynamic-reexport case.
What kind of change does this PR introduce?
Bug fix
Did you add tests for your changes?
Yes, added
test/cases/optimize/tree-shaking-unused-default-export/Does this PR introduce a breaking change?
Shouldn't be — this makes webpack correctly exclude default from export * re-exports, which is what the ES spec requires.