Repository navigation
Commit dd6cb2b
committed
feat(minifier): fold out-of-bounds string indices to
`"a"[1]`, `"a"["1"]`, `"Γ©"[1]` and `"π"[2]` read an index past the end of the string, which finds no own property and falls through to `String.prototype`. Under the [no-monkey-patching assumption](https://github.com/oxc-project/oxc/blob/main/crates/oxc_minifier/docs/ASSUMPTIONS.md#no-monkey-patching-built-ins) that prototype has no index properties, so the access is `undefined` and now folds to `void 0`. Later folds can then use the value: `"a"[1] === void 0` becomes `!0`.
The operand of `delete` and call targets keep the access. Non-canonical keys such as `"a"["01"]` and negative indices are not index reads, so they stay as they are. esbuild keeps `"abc"[3]`, and the ported esbuild test is updated with a note.
Closes #27992.
Implemented with AI assistance.void 0 (#28004)1 parent eacffcc commit dd6cb2b
3 files changed
Lines changed: 17 additions & 7 deletions
File tree
- crates/oxc_minifier
- src/peephole
- tests/peephole
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
729 | 729 | | |
730 | 730 | | |
731 | 731 | | |
732 | | - | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
733 | 737 | | |
734 | 738 | | |
735 | 739 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
374 | | - | |
| 374 | + | |
| 375 | + | |
375 | 376 | | |
376 | 377 | | |
377 | 378 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1193 | 1193 | | |
1194 | 1194 | | |
1195 | 1195 | | |
1196 | | - | |
| 1196 | + | |
| 1197 | + | |
1197 | 1198 | | |
1198 | 1199 | | |
1199 | 1200 | | |
1200 | | - | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
1201 | 1204 | | |
1202 | | - | |
| 1205 | + | |
| 1206 | + | |
1203 | 1207 | | |
1204 | 1208 | | |
1205 | | - | |
| 1209 | + | |
1206 | 1210 | | |
1207 | 1211 | | |
1208 | 1212 | | |
| |||
1214 | 1218 | | |
1215 | 1219 | | |
1216 | 1220 | | |
1217 | | - | |
| 1221 | + | |
| 1222 | + | |
1218 | 1223 | | |
1219 | 1224 | | |
1220 | 1225 | | |
| |||
0 commit comments