fix: name the failing key on DefinePlugin typeof evaluation errors - #21503
Conversation
🦋 Changeset detectedLatest commit: 2db2154 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 (e02f566). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@e02f566
yarn add -D webpack@https://pkg.pr.new/webpack@e02f566
pnpm add -D webpack@https://pkg.pr.new/webpack@e02f566 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21503 +/- ##
==========================================
- Coverage 93.57% 93.57% -0.01%
==========================================
Files 619 619
Lines 73232 73241 +9
Branches 21105 21107 +2
==========================================
+ Hits 68526 68533 +7
- Misses 4706 4708 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ef3de25 to
1af8219
Compare
|
The ( Generated by Claude Code |
|
On the CodSpeed
Happy to re-run if a maintainer wants a same-environment comparison. Generated by Claude Code |
1af8219 to
3272dec
Compare
When DefinePlugin cannot evaluate a typeof replacement value (e.g. an invalid non-stringified string), the parse error now names the offending define key instead of a bare "Unexpected token". The original error is reused so ModuleParseError still renders its code frame; no extra parser.evaluate() calls are added and stats output is unchanged.
3272dec to
2db2154
Compare
Types CoverageCoverage after merging claude/pr-20260-review-e6cze3 into main will be
Coverage Report |
Summary
Closes #15371. When a
DefinePlugintypeofvalue cannot be evaluated (e.g. an invalid non-stringified string), webpack reported a bareModule parse failed: Unexpected tokenwith no hint of which define caused it. This prefixes the failing define key onto the error so it is actionable. The original error object is reused, soModuleParseErrorstill renders its code frame — no extraparser.evaluate()calls are added (hot paths untouched) and no stats serialization is changed. Refs #20260 (a perf-safe, narrower take on that closed PR).What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes —
test/statsCases/define-plugin-error/(snapshot of the rendered error) andtest/DefinePlugin.unittest.js(covers the string, throwing-runtimeValue, and non-Errorthrow branches).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
AI (Claude Code) was used to investigate issue #15371 and the closed PR #20260, reproduce the behavior against a source build, implement this narrower perf-safe version, and write the tests. All changes were reviewed and verified by me.