Commit 74c9ddd
fix(ecmascript): treat collection constructor with variable arg as side-effectful
`new Map(x)`, `new Set(x)`, `new WeakMap(x)`, `new WeakSet(x)` were
incorrectly considered side-effect-free when the argument is a variable
reference. These constructors iterate their argument via
`Symbol.iterator`, which can execute arbitrary user code.
Now only provably safe arguments are considered pure: no arguments,
`null`, `undefined`, or array literals (for Map/WeakMap, entries must
also be array literals). This matches esbuild and Rollup behavior.
Co-Authored-By: Claude Opus 4.6 <[email protected]>1 parent 618a598 commit 74c9ddd
File tree
2 files changed
+70
-2
lines changed- crates
- oxc_ecmascript/src/side_effects
- oxc_minifier/tests/ecmascript
2 files changed
+70
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
| 298 | + | |
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
306 | 342 | | |
307 | 343 | | |
308 | 344 | | |
| |||
998 | 1034 | | |
999 | 1035 | | |
1000 | 1036 | | |
1001 | | - | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
1002 | 1040 | | |
1003 | 1041 | | |
1004 | 1042 | | |
| |||
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
957 | 957 | | |
958 | 958 | | |
959 | 959 | | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
960 | 990 | | |
961 | 991 | | |
962 | 992 | | |
| |||
0 commit comments