fix: set .name to "default" for anonymous default exports per ES spec#20773
fix: set .name to "default" for anonymous default exports per ES spec#20773alexander-akait merged 1 commit intomainfrom
Conversation
`export default class {}` and `export default function() {}` should
have `.name === "default"` per the ES specification. Webpack's renaming
to `__WEBPACK_DEFAULT_EXPORT__` caused name inference to assign the
wrong name.
🦋 Changeset detectedLatest commit: 9634b37 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 (390333f). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@390333f
yarn add -D webpack@https://pkg.pr.new/webpack@390333f
pnpm add -D webpack@https://pkg.pr.new/webpack@390333f |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your changes status has failed because you have indirect coverage changes. Learn more about Unexpected Coverage Changes and reasons for indirect coverage changes. Additional details and impacted files@@ Coverage Diff @@
## main #20773 +/- ##
=======================================
Coverage 91.42% 91.43%
=======================================
Files 559 559
Lines 55103 55150 +47
Branches 14529 14556 +27
=======================================
+ Hits 50380 50427 +47
Misses 4723 4723
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Merging this PR will degrade performance by 51.51%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "react", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
645.3 KB | 865.3 KB | -25.42% |
| ❌ | Memory | benchmark "many-chunks-commonjs", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
535.9 KB | 1,105 KB | -51.51% |
| ⚡ | Memory | benchmark "many-chunks-esm", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
1,104.8 KB | 710.4 KB | +55.52% |
Comparing fix/anonymous-default-export-name (9634b37) with main (91aa5da)
When `output.environment.const` is false and the default export slot is used, the harmony default export template assigns directly to `__webpack_exports__["default"]` without declaring any local `__WEBPACK_DEFAULT_EXPORT__` binding. The anonymous-default `.name` fix-up introduced in #20773 still referenced that undeclared binding, causing a `ReferenceError` at module load time. Reference the actual assignment target in that branch. Also add regression tests covering anonymous arrow / async arrow / class / class-extends default exports under ES5 environment, plus an anonymous function default export under module concatenation. Fixes #20793
When `output.environment.const` is false and the default export slot is used, the harmony default export template assigns directly to `__webpack_exports__["default"]` without declaring any local `__WEBPACK_DEFAULT_EXPORT__` binding. The anonymous-default `.name` fix-up introduced in #20773 still referenced that undeclared binding, causing a `ReferenceError` at module load time. Reference the actual assignment target in that branch. Also add regression tests covering anonymous arrow / async arrow / class / class-extends default exports under ES5 environment, plus an anonymous function default export under module concatenation. Fixes #20793
When `output.environment.const` is false and the default export slot is used, the harmony default export template assigns directly to `__webpack_exports__["default"]` without declaring any local `__WEBPACK_DEFAULT_EXPORT__` binding. The anonymous-default `.name` fix-up introduced in #20773 still referenced that undeclared binding, causing a `ReferenceError` at module load time. Reference the actual assignment target in that branch. Also add regression tests covering anonymous arrow / async arrow / class / class-extends default exports under ES5 environment, plus an anonymous function default export under module concatenation. Fixes #20793
When `output.environment.const` is false and the default export slot is used, the harmony default export template assigns directly to `__webpack_exports__["default"]` without declaring any local `__WEBPACK_DEFAULT_EXPORT__` binding. The anonymous-default `.name` fix-up introduced in #20773 still referenced that undeclared binding, causing a `ReferenceError` at module load time. Reference the actual assignment target in that branch. Also add regression tests covering anonymous arrow / async arrow / class / class-extends default exports under ES5 environment, plus an anonymous function default export under module concatenation. Fixes #20793
When `output.environment.const` is false and the default export slot is used, the harmony default export template assigns directly to `__webpack_exports__["default"]` without declaring any local `__WEBPACK_DEFAULT_EXPORT__` binding. The anonymous-default `.name` fix-up introduced in #20773 still referenced that undeclared binding, causing a `ReferenceError` at module load time. Also replaces `Reflect.*` with `Object.*` so the emitted code does not depend on ES2015 `Reflect` in ES5 target runtimes, and guards against an undefined descriptor so Node 10 (and other legacy V8 versions that do not set an own `name` property on anonymous class expressions assigned to a MemberExpression) does not throw. Adds regression tests covering anonymous arrow / async arrow / class / class-extends default exports under ES5 environment, plus an anonymous function default export under module concatenation. Fixes #20793
Summary
export default class {}andexport default function() {}should have.name === "default"per the ES specification. Webpack's renaming to__WEBPACK_DEFAULT_EXPORT__caused name inference to assign the wrong name.What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Existing
Does this PR introduce a breaking change?
No