Fix invalid property access for escaped namespace with mangled exports#21280
Conversation
propertyAccess() expects ArrayLike<string> and iterates by index. A bare string like "zy" is array-like, so it was split into ".z.y" instead of ".zy". Wrap in [usedName] so it is treated as a single property name. Fixes #21278
🦋 Changeset detectedLatest commit: 5e624d5 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 (062aa20). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@062aa20
yarn add -D webpack@https://pkg.pr.new/webpack@062aa20
pnpm add -D webpack@https://pkg.pr.new/webpack@062aa20 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21280 +/- ##
=======================================
Coverage 92.85% 92.85%
=======================================
Files 592 592
Lines 65024 65025 +1
Branches 18163 18166 +3
=======================================
+ Hits 60379 60380 +1
Misses 4645 4645
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:
|
Merging this PR will degrade performance by 45.24%
|
Change the JSDoc type of propertyAccess from ArrayLike<string> to readonly string[] so that passing a bare string (which is ArrayLike but iterates per character) is a type error. Three call sites where the value can genuinely be a bare string are fixed with Array.isArray guards; the remaining nine sites receive a type cast since their getUsedName input is always an array.
Types CoverageCoverage after merging fix/escape-namespace-property-access into main will be
Coverage Report |
Summary
Fixes #21278
Fixes #21279
When a namespace import escapes (e.g.
const rc = ns;) and the imported module is external to the concatenation group, the escape namespace object generator passes a bare string (usedName) topropertyAccess(). Since strings areArrayLike<string>, a multi-character mangled name like"zy"is iterated per character, producing.z.yinstead of.zy, which crashes at runtime.The fix itself is a one-character change:
propertyAccess(usedName)→propertyAccess([usedName]).To prevent the same class of bug from recurring, the second commit narrows the
propertyAccessparameter type fromArrayLike<string>toreadonly string[], which makes barestringa type error. This surfaced three additional call sites (RuntimeTemplate,HarmonyExportImportedSpecifierDependency) where the value genuinely can be a bare string — fixed withArray.isArrayguards. The remaining nine call sites always receive an array, so they get a type cast.What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes —
test/configCases/mangle/mangle-escaping-namespace-external/with 60 exports to force multi-char mangled names.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 was used to investigate the issue, write the fix, and create the test case and PR.