bun_js_parser 0.1.1

A Rust-native programmable browser runtime built on Servo and SpiderMonkey
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
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
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
#![warn(unused_must_use)]
use bun_collections::VecExt;
use std::io::Write as _;

use bstr::BStr;
use bun_core::strings;

use crate::lexer as js_lexer;
use crate::p::P;
use crate::parser::{
    ExprIn, FnOrArrowDataVisit, IdentifierOpts, PrependTempRefsOpts, ReactRefresh, Ref,
    StrictModeFeature, ThenCatchChain, TransposeState, VisitArgsOpts, float_to_int32, prefill,
};
use crate::scan::scan_side_effects::SideEffects;
use bun_alloc::ArenaVecExt as _;
use bun_ast as js_ast;
use bun_ast::flags as Flags;
use bun_ast::{E, Expr, ExprNodeIndex, ExprNodeList, G, Stmt, Symbol};

// Local short-hands so the visitor bodies read close to the Zig
// (`expr.data.e_dot`, `Expr.Data.e_binary`, `Op.Code.un_typeof`) without a
// bulk find-replace at every call-site.
use js_ast::ExprData as Data;
use js_ast::ExprTag as Tag;
use js_ast::OpCode as Op;

// Zig: `pub fn VisitExpr(comptime ts, comptime jsx, comptime scan_only) type { return struct { ... } }`
// — file-split mixin pattern. Round-C lowered `const JSX: JSXTransformType` → `J: JsxT`, so this is
// a direct `impl P` block. The 25+ per-variant `e_*` helpers are private; only `visit_expr` /
// `visit_expr_in_out` are surfaced.

impl<'a, const TYPESCRIPT: bool, const SCAN_ONLY: bool> P<'a, TYPESCRIPT, SCAN_ONLY> {
    // PERF(port:noalias): `e: &mut Expr` is lowered to a `noalias` LLVM param, so reads
    // through `e` can be cached in registers across child recursion. The by-value
    // `Expr -> Expr` shape moved 24B in + 24B out per frame; the in-place form moves 8B
    // and only writes back when the visitor produces a *different* node.
    #[inline]
    pub fn visit_expr(&mut self, e: &mut Expr) {
        // Zig: `if (only_scan_imports_and_do_not_visit) @compileError(...)` — SCAN_ONLY
        // monomorphizations must never reach the visit pass.
        debug_assert!(
            !SCAN_ONLY,
            "only_scan_imports_and_do_not_visit must not run visit_expr",
        );
        self.visit_expr_in_out(e, ExprIn::default())
    }

    pub fn visit_expr_in_out(&mut self, e: &mut Expr, in_: ExprIn) {
        if !self.stack_check.is_safe_to_recurse() || self.reported_stack_overflow.get() {
            self.report_stack_overflow(e.loc);
            return;
        }

        if in_.assign_target != js_ast::AssignTarget::None && !self.is_valid_assignment_target(e) {
            self.log()
                .add_error(Some(self.source), e.loc, b"Invalid assignment target");
        }

        // Zig dispatches via `inline else => |tag| if (comptime @hasDecl(visitors, @tagName(tag)))`.
        // Rust has no struct-decl reflection; expand to an explicit match over the tags that have
        // a visitor defined below. Any tag without a visitor leaves `*e` unchanged.
        use js_ast::ExprTag as Tag;
        match e.data.tag() {
            Tag::ENewTarget => Self::e_new_target(self, e, in_),
            Tag::EString => Self::e_string(self, e, in_),
            Tag::ENumber => Self::e_number(self, e, in_),
            Tag::EThis => Self::e_this(self, e, in_),
            Tag::EImportMeta => Self::e_import_meta(self, e, in_),
            Tag::ESpread => Self::e_spread(self, e, in_),
            Tag::EIdentifier => Self::e_identifier(self, e, in_),
            Tag::EJsxElement => Self::e_jsx_element(self, e, in_),
            Tag::ETemplate => Self::e_template(self, e, in_),
            Tag::EBinary => Self::e_binary(self, e, in_),
            Tag::EIndex => Self::e_index(self, e, in_),
            Tag::EUnary => Self::e_unary(self, e, in_),
            Tag::EDot => Self::e_dot(self, e, in_),
            Tag::EIf => Self::e_if(self, e, in_),
            Tag::EAwait => Self::e_await(self, e, in_),
            Tag::EYield => Self::e_yield(self, e, in_),
            Tag::EArray => Self::e_array(self, e, in_),
            Tag::EObject => Self::e_object(self, e, in_),
            Tag::EImport => Self::e_import(self, e, in_),
            Tag::ECall => Self::e_call(self, e, in_),
            Tag::ENew => Self::e_new(self, e, in_),
            Tag::EArrow => Self::e_arrow(self, e, in_),
            Tag::EFunction => Self::e_function(self, e, in_),
            Tag::EClass => Self::e_class(self, e, in_),
            _ => {}
        }
    }

    // ─── visitors ───────────────────────────────────────────────────────────
    // In Zig these live on a nested `const visitors = struct { ... }`; in Rust they are private
    // associated fns on this impl so they can see the const-generic feature params.

    fn e_new_target(_: &mut Self, _e: &mut Expr, _: ExprIn) {
        // this error is not necessary and it is causing breakages
        // if (!p.fn_only_data_visit.is_new_target_allowed) {
        //     p.log.addRangeError(p.source, target.range, "Cannot use \"new.target\" here") catch unreachable;
        // }
    }

    fn e_string(_: &mut Self, _e: &mut Expr, _: ExprIn) {
        // If you're using this, you're probably not using 0-prefixed legacy octal notation
        // if e.LegacyOctalLoc.Start > 0 {
    }

    fn e_number(_: &mut Self, _e: &mut Expr, _: ExprIn) {
        // idc about legacy octal loc
    }

    fn e_this(p: &mut Self, e: &mut Expr, _: ExprIn) {
        if let Some(exp) = p.value_for_this(e.loc) {
            *e = exp;
            return;
        }

        //                 // Capture "this" inside arrow functions that will be lowered into normal
        // // function expressions for older language environments
        // if p.fnOrArrowDataVisit.isArrow && p.options.unsupportedJSFeatures.Has(compat.Arrow) && p.fnOnlyDataVisit.isThisNested {
        //     return js_ast.Expr{Loc: expr.Loc, Data: &js_ast.EIdentifier{Ref: p.captureThis()}}, exprOut{}
        // }
    }

    fn e_spread(p: &mut Self, e: &mut Expr, _: ExprIn) {
        if let js_ast::ExprData::ESpread(mut exp) = e.data {
            p.visit_expr(&mut exp.value);
        }
    }

    fn e_await(p: &mut Self, e: &mut Expr, _: ExprIn) {
        if let js_ast::ExprData::EAwait(mut e_) = e.data {
            p.await_target = Some(e_.value.data);
            p.visit_expr(&mut e_.value);
        }
    }

    fn e_yield(p: &mut Self, e: &mut Expr, _: ExprIn) {
        if let js_ast::ExprData::EYield(mut e_) = e.data {
            if let Some(val) = e_.value.as_mut() {
                p.visit_expr(val);
            }
        }
    }

    // ─── heavy visitors ─────────────────────────────────────────────────────
    // e_* accessors on `expr::Data` return Option<StoreRef<T>> / Option<T>.

    fn e_import_meta(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        // TODO: delete import.meta might not work
        let is_delete_target = matches!(p.delete_target, Data::EImportMeta(..));

        // `p.define: &'a Define` is `Copy`; hoist the reference so the
        // `dots.get` borrow is tied to `'a`, not `&*p`, and `&mut self`
        // helpers below can be called while iterating without laundering.
        let defines = p.define;
        if let Some(meta) = defines.dots.get(b"meta".as_slice()) {
            for define in meta.as_slice() {
                if !p.is_dot_define_match(expr, &define.parts) {
                    continue;
                }
                // Substitute user-specified defines
                *e =
                    p.value_for_define(expr.loc, in_.assign_target, is_delete_target, &define.data);
                return;
            }
        }
    }

    fn e_identifier(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        let mut e_ = expr
            .data
            .e_identifier()
            .expect("infallible: variant checked");
        let is_delete_target = matches!(p.delete_target.tag(), Tag::EIdentifier)
            && e_.ref_.eql(
                p.delete_target
                    .e_identifier()
                    .expect("infallible: variant checked")
                    .ref_,
            );

        let name = p.load_name_from_ref(e_.ref_);
        if p.is_strict_mode() && js_lexer::is_strict_mode_reserved_word(name) {
            p.mark_strict_mode_feature(
                StrictModeFeature::ReservedWord,
                js_lexer::range_of_identifier(p.source, expr.loc),
                name,
            )
            .expect("unreachable");
        }

        let result = p.find_symbol(expr.loc, name).expect("unreachable");

        // Order matters: assigning a fresh `Ref` clears the packed user-bit
        // flags (intentional — the parse-time ref carries no flags), so set
        // `ref_` first, then derive the visit-time flags into the user bits.
        e_.ref_ = result.r#ref;
        e_.set_must_keep_due_to_with_stmt(result.is_inside_with_scope);

        // Handle assigning to a constant
        if in_.assign_target != js_ast::AssignTarget::None {
            if p.symbols[result.r#ref.inner_index() as usize].kind == js_ast::symbol::Kind::Constant
            {
                // TODO: silence this for runtime transpiler
                let r = js_lexer::range_of_identifier(p.source, expr.loc);
                let notes: Box<[bun_ast::Data]> = Box::new([bun_ast::Data {
                    text: {
                        let mut v = Vec::new();
                        write!(
                            &mut v,
                            "The symbol \"{}\" was declared a constant here:",
                            BStr::new(name)
                        )
                        .unwrap();
                        std::borrow::Cow::Owned(v)
                    },
                    location: bun_ast::Location::init_or_null(
                        Some(p.source),
                        js_lexer::range_of_identifier(p.source, result.declare_loc.unwrap()),
                    ),
                    ..Default::default()
                }]);

                let is_error = p.const_values.contains_key(&result.r#ref) || p.options.bundle;
                match is_error {
                    true => p.log().add_range_error_fmt_with_notes(
                        Some(p.source),
                        r,
                        notes,
                        format_args!(
                            "Cannot assign to \"{}\" because it is a constant",
                            BStr::new(name)
                        ),
                    ),

                    false => p.log().add_range_error_fmt_with_notes(
                        Some(p.source),
                        r,
                        notes,
                        format_args!(
                            "This assignment will throw because \"{}\" is a constant",
                            BStr::new(name)
                        ),
                    ),
                }
            } else if p.exports_ref.eql(e_.ref_) {
                // Assigning to `exports` in a CommonJS module must be tracked to undo the
                // `module.exports` -> `exports` optimization.
                p.commonjs_module_exports_assigned_deoptimized = true;
            }

            p.symbols[result.r#ref.inner_index() as usize].has_been_assigned_to = true;
        }

        let mut original_name: Option<&[u8]> = None;

        // Substitute user-specified defines for unbound symbols
        if p.symbols[e_.ref_.inner_index() as usize].kind == js_ast::symbol::Kind::Unbound
            && !result.is_inside_with_scope
            && !is_delete_target
        {
            // `p.define: &'a Define` is `Copy`; hoist so the returned
            // `&DefineData` is tied to `'a`, not `&*p`, and `&mut self`
            // helpers (`value_for_define`) below need no lifetime laundering.
            let defines = p.define;
            if let Some(def) = defines.for_identifier(name) {
                if !def.valueless() {
                    let newvalue: Expr =
                        p.value_for_define(expr.loc, in_.assign_target, is_delete_target, def);

                    // Don't substitute an identifier for a non-identifier if this is an
                    // assignment target, since it'll cause a syntax error
                    if matches!(newvalue.data.tag(), Tag::EIdentifier)
                        || in_.assign_target == js_ast::AssignTarget::None
                    {
                        p.ignore_usage(e_.ref_);
                        *e = newvalue;
                        return;
                    }

                    original_name = def.original_name();
                }

                // Copy the side effect flags over in case this expression is unused
                if def.can_be_removed_if_unused() {
                    e_.set_can_be_removed_if_unused(true);
                }
                if def.call_can_be_unwrapped_if_unused() == E::CallUnwrap::IfUnused
                    && !p.options.ignore_dce_annotations
                {
                    e_.set_call_can_be_unwrapped_if_unused(true);
                }

                // If the user passed --drop=console, drop all property accesses to console.
                if def.method_call_must_be_replaced_with_undefined()
                    && in_.property_access_for_method_call_maybe_should_replace_with_undefined
                    && in_.assign_target == js_ast::AssignTarget::None
                {
                    p.method_call_must_be_replaced_with_undefined = true;
                }
            }

            // Substitute uncalled "require" for the require target
            if p.require_ref.eql(e_.ref_) && !p.is_source_runtime() {
                // mark a reference to __require only if this is not about to be used for a call target
                if !(matches!(p.call_target.tag(), Tag::EIdentifier)
                    && expr.data.e_identifier().unwrap().ref_.eql(
                        p.call_target
                            .e_identifier()
                            .expect("infallible: variant checked")
                            .ref_,
                    ))
                    && p.options.features.allow_runtime
                {
                    p.record_usage_of_runtime_require();
                }

                *e = p.value_for_require(expr.loc);
                return;
            }
        }

        *e = p.handle_identifier(
            expr.loc,
            e_,
            original_name,
            IdentifierOpts::default()
                .with_assign_target(in_.assign_target)
                .with_is_delete_target(is_delete_target)
                .with_is_call_target(
                    matches!(p.call_target.tag(), Tag::EIdentifier)
                        && expr.data.e_identifier().unwrap().ref_.eql(
                            p.call_target
                                .e_identifier()
                                .expect("infallible: variant checked")
                                .ref_,
                        ),
                )
                .with_was_originally_identifier(true),
        );
    }
    // PERF(port:frame): keep these large, infrequently-taken arms out of the
    // `visit_expr_in_out` dispatcher frame. Without `inline(never)` LLVM folds the
    // big match arms into the recursive dispatcher, inflating its stack frame to
    // ~968B; deep ASTs then thrash L1d on the spill/reload (the spill into that
    // frame is the #2 hottest bun-native instruction under `bun --bun lint`).
    // Mirrors Zig's switch-with-helper-fns layout.
    #[inline(never)]
    fn e_jsx_element(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        use crate::parser::{JSXImport, JSXTransformType, options};
        let _ = in_;
        let mut e_ = expr
            .data
            .e_jsx_element()
            .expect("infallible: variant checked");
        // Zig: `switch (comptime jsx_transform_type)`; JSX is no longer a
        // type parameter — dispatch on the runtime `P::jsx_transform` field.
        match p.jsx_transform {
            JSXTransformType::React => {
                let tag: Expr = 'tagger: {
                    if let Some(mut _tag) = e_.tag {
                        p.visit_expr(&mut _tag);
                        break 'tagger _tag;
                    }
                    if p.options.jsx.runtime == options::JSX::Runtime::Classic {
                        // PORT NOTE: `jsx_strings_to_member_expression` wants `&[&'a [u8]]`.
                        // In Zig, `options.jsx.fragment: []const string` borrows from the
                        // long-lived `transpiler.options.jsx`, so the strings outlive the
                        // AST. Here, `options.jsx.fragment: Box<[Box<[u8]>]>` is OWNED by
                        // `P` and dropped when `Parser::parse` returns — but the parts are
                        // stored in symbols / `E::Dot.name` and read later by the printer.
                        // Dupe each part into the arena (which backs the AST) to restore
                        // the spec's lifetime invariant. Build the `&[&'a [u8]]` slice
                        // directly in the AST arena instead of a throwaway global-heap
                        // `Vec` — keeps the visitor off the `#[global_allocator]`.
                        let arena = p.arena;
                        let parts: &[&'a [u8]] = arena.alloc_slice_fill_iter(
                            p.options
                                .jsx
                                .fragment
                                .iter()
                                .map(|b| -> &'a [u8] { arena.alloc_slice_copy(b) }),
                        );
                        break 'tagger p
                            .jsx_strings_to_member_expression(expr.loc, parts)
                            .expect("unreachable");
                    }
                    break 'tagger p.jsx_import(JSXImport::Fragment, expr.loc);
                };

                for property in e_.properties.slice_mut() {
                    if property.kind != G::PropertyKind::Spread {
                        p.visit_expr(property.key.as_mut().expect("infallible: prop has key"));
                    }

                    if let Some(v) = property.value.as_mut() {
                        p.visit_expr(v);
                    }

                    if let Some(v) = property.initializer.as_mut() {
                        p.visit_expr(v);
                    }
                }

                let runtime = if p.options.jsx.runtime == options::JSX::Runtime::Automatic {
                    options::JSX::Runtime::Automatic
                } else {
                    options::JSX::Runtime::Classic
                };
                let is_key_after_spread = e_.flags.contains(Flags::JSXElement::IsKeyAfterSpread);
                let children_count = e_.children.len_u32();

                // TODO: maybe we should split these into two different AST Nodes
                // That would reduce the amount of allocations a little
                if runtime == options::JSX::Runtime::Classic || is_key_after_spread {
                    // Arguments to createElement()
                    let mut args = ExprNodeList::init_capacity(2 + children_count as usize);
                    // PERF(port): was assume_capacity
                    VecExt::append(&mut args, tag);

                    let num_props = e_.properties.len_u32();
                    if num_props > 0 {
                        // PORT NOTE: Zig duped the property slice into a fresh arena allocation
                        // before wrapping in E.Object. PropertyList = Vec<Property> here is
                        // already arena-backed and the JSX node is consumed; reuse in place.
                        // PERF(port): was arena alloc + bun.copy — profile if it shows up on a hot path
                        VecExt::append(
                            &mut args,
                            p.new_expr(
                                E::Object {
                                    properties: bun_alloc::AstAlloc::take(&mut e_.properties),
                                    ..Default::default()
                                },
                                expr.loc,
                            ),
                        );
                    } else {
                        VecExt::append(&mut args, p.new_expr(E::Null {}, expr.loc));
                    }

                    let children_elements = &e_.children.slice()[0..children_count as usize];
                    for child in children_elements {
                        let mut arg = *child;
                        p.visit_expr(&mut arg);
                        if !matches!(arg.data, Data::EMissing(..)) {
                            // PERF(port): was assume_capacity
                            VecExt::append(&mut args, arg);
                        }
                    }

                    let target: Expr = if runtime == options::JSX::Runtime::Classic {
                        // PORT NOTE: see fragment note above — `options.jsx.factory` is
                        // owned by `P` and freed when the parser drops; dupe each part
                        // into the arena so the symbol/E::Dot names outlive the printer.
                        // Build the parts slice in the AST arena (no global-heap `Vec`).
                        let arena = p.arena;
                        let parts: &[&'a [u8]] = arena.alloc_slice_fill_iter(
                            p.options
                                .jsx
                                .factory
                                .iter()
                                .map(|b| -> &'a [u8] { arena.alloc_slice_copy(b) }),
                        );
                        p.jsx_strings_to_member_expression(expr.loc, parts)
                            .expect("unreachable")
                    } else {
                        // Spec (visitExpr.zig:257) calls jsxStringsToMemberExpression(factory)
                        // unconditionally before the runtime check; that has the side-effect of
                        // findSymbol(loc, factory[0]) which records usage of the factory ident.
                        // The full helper is Pragma-shape-blocked, so replicate the side-effect
                        // for the Automatic + key-after-spread path and discard the result.
                        if let Some(first) = p.options.jsx.factory.first() {
                            let name: &'a [u8] = p.arena.alloc_slice_copy(first);
                            let _ = p.find_symbol(expr.loc, name).expect("unreachable");
                        }
                        p.jsx_import(JSXImport::CreateElement, expr.loc)
                    };

                    // Call createElement()
                    *e = p.new_expr(
                        E::Call {
                            target,
                            args,
                            // Enable tree shaking
                            can_be_unwrapped_if_unused: if !p.options.ignore_dce_annotations
                                && !p.options.jsx.side_effects
                            {
                                E::CallUnwrap::IfUnused
                            } else {
                                E::CallUnwrap::Never
                            },
                            close_paren_loc: e_.close_tag_loc,
                            ..Default::default()
                        },
                        expr.loc,
                    );
                    return;
                }
                // function jsxDEV(type, config, maybeKey, source, self) {
                else if runtime == options::JSX::Runtime::Automatic {
                    // --- These must be done in all cases --
                    let maybe_key_value: Option<ExprNodeIndex> = if e_.key_prop_index > -1 {
                        let idx = e_.key_prop_index as u32 as usize;
                        e_.properties.ordered_remove(idx).value
                    } else {
                        None
                    };

                    // PORT NOTE: Zig reassigns `props` (a `*Vec(G.Property)`) to point inside
                    // a spread object's properties via raw arena pointer. Track as a
                    // `StoreRef` (safe `Deref`/`DerefMut`) so the spread-collapse walk
                    // and the `push`/`take` calls below stay in safe code.
                    let mut props_handle = js_ast::StoreRef::from_bump(&mut e_.properties);

                    // arguments needs to be like
                    // {
                    //    ...props,
                    //    children: [el1, el2]
                    // }

                    {
                        let mut last_child: u32 = 0;
                        // PORT NOTE: Zig wrote `e_.children.ptr[last_child] = p.visitExpr(child)`
                        // while iterating a slice over the same buffer. Iterate by index to avoid
                        // borrowck on `e_.children`.
                        for i in 0..children_count {
                            let mut visited = e_.children.slice()[i as usize];
                            p.visit_expr(&mut visited);
                            e_.children.slice_mut()[last_child as usize] = visited;
                            // if tree-shaking removes the element, we must also remove it here.
                            last_child += u32::from(!matches!(
                                e_.children.slice()[last_child as usize].data,
                                Data::EMissing(..)
                            ));
                        }
                        e_.children.truncate(last_child as usize);
                    }

                    // TODO(port): jsxChildrenKeyData in Zig is a mutable `var` of `Expr.Data`
                    // pointing at `Prefill.String.Children`. ExprData::EString wants a
                    // `StoreRef<EString>` (arena-backed) so a process-static won't compile (see
                    // P.rs `` ~7552). Allocate via `p.new_expr` from the const
                    // `prefill::string::CHILDREN` instead — small extra alloc.
                    // PERF(port): was process-static — profile if it shows up on a hot path
                    let children_key = p.new_expr(prefill::string::CHILDREN, expr.loc);

                    // Optimization: if the only non-child prop is a spread object
                    // we can just pass the object as the first argument
                    // this goes as deep as there are spreads
                    // <div {{...{...{...{...foo}}}}} />
                    // ->
                    // <div {{...foo}} />
                    // jsx("div", {...foo})
                    loop {
                        // `StoreRef<PropertyList>: Deref` — safe arena-backed read.
                        if !(props_handle.len_u32() == 1
                            && props_handle.slice()[0].kind == G::PropertyKind::Spread
                            && matches!(
                                props_handle.slice()[0].value.unwrap().data,
                                Data::EObject(..)
                            ))
                        {
                            break;
                        }
                        // PORT NOTE: reshaped for borrowck — Zig reassigns `props` to point
                        // inside the spread object's properties. Compute the next handle in
                        // a block so the `DerefMut` borrow of `props_handle` ends before
                        // reassignment.
                        let next = {
                            let inner = props_handle.slice_mut()[0]
                                .value
                                .as_mut()
                                .unwrap()
                                .data
                                .e_object_mut()
                                .unwrap();
                            js_ast::StoreRef::from_bump(&mut inner.properties)
                        };
                        props_handle = next;
                    }
                    // `StoreRef: DerefMut` — safe arena-backed handle; no aliasing
                    // `&mut` outstanding for the remainder of this arm.
                    let props = &mut *props_handle;

                    // Typescript defines static jsx as children.len > 1 or single spread
                    // https://github.com/microsoft/TypeScript/blob/d4fbc9b57d9aa7d02faac9b1e9bb7b37c687f6e9/src/compiler/transformers/jsx.ts#L340
                    let is_static_jsx = e_.children.len_u32() > 1
                        || (e_.children.len_u32() == 1
                            && matches!(e_.children.slice()[0].data, Data::ESpread(..)));

                    if is_static_jsx {
                        // Capture before `mem::take` zeroes `e_.children.len` (struct-literal
                        // fields evaluate in written order; spec reads original len).
                        let children_single_line = e_.children.len_u32() < 2;
                        props.push(G::Property {
                            key: Some(children_key),
                            value: Some(p.new_expr(
                                E::Array {
                                    items: bun_alloc::AstAlloc::take(&mut e_.children),
                                    is_single_line: children_single_line,
                                    ..Default::default()
                                },
                                e_.close_tag_loc,
                            )),
                            ..Default::default()
                        });
                    } else if e_.children.len_u32() == 1 {
                        props.push(G::Property {
                            key: Some(children_key),
                            value: Some(e_.children.slice()[0]),
                            ..Default::default()
                        });
                    }

                    // Either:
                    // jsxDEV(type, arguments, key, isStaticChildren, source, self)
                    // jsx(type, arguments, key)
                    let args_len = if p.options.jsx.development {
                        6usize
                    } else {
                        2usize + usize::from(maybe_key_value.is_some())
                    };
                    let mut args = ExprNodeList::init_capacity(args_len);
                    VecExt::append(&mut args, tag);

                    VecExt::append(
                        &mut args,
                        p.new_expr(
                            E::Object {
                                properties: bun_alloc::AstAlloc::take(props),
                                ..Default::default()
                            },
                            expr.loc,
                        ),
                    );

                    if let Some(key) = maybe_key_value {
                        VecExt::append(&mut args, key);
                    } else if p.options.jsx.development {
                        // if (maybeKey !== undefined)
                        VecExt::append(
                            &mut args,
                            Expr {
                                loc: expr.loc,
                                data: Data::EUndefined(E::Undefined {}),
                            },
                        );
                    }

                    if p.options.jsx.development {
                        // is the return type of the first child an array?
                        // It's dynamic
                        // Else, it's static
                        VecExt::append(
                            &mut args,
                            Expr {
                                loc: expr.loc,
                                data: Data::EBoolean(E::Boolean {
                                    value: is_static_jsx,
                                }),
                            },
                        );

                        VecExt::append(&mut args, p.new_expr(E::Undefined {}, expr.loc));
                        VecExt::append(
                            &mut args,
                            Expr {
                                data: prefill::data::THIS,
                                loc: expr.loc,
                            },
                        );
                    }

                    let jsx_target = p.jsx_import_automatic(expr.loc, is_static_jsx);
                    *e = p.new_expr(
                        E::Call {
                            target: jsx_target,
                            args,
                            // Enable tree shaking
                            can_be_unwrapped_if_unused: if !p.options.ignore_dce_annotations
                                && !p.options.jsx.side_effects
                            {
                                E::CallUnwrap::IfUnused
                            } else {
                                E::CallUnwrap::Never
                            },
                            was_jsx_element: true,
                            close_paren_loc: e_.close_tag_loc,
                            ..Default::default()
                        },
                        expr.loc,
                    );
                    return;
                } else {
                    unreachable!();
                }
            }
            _ => unreachable!(),
        }
    }
    #[inline(never)] // PERF(port:frame): see e_jsx_element.
    fn e_template(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        let _ = in_;
        let mut e_ = expr.data.e_template().expect("infallible: variant checked");
        if let Some(tag) = e_.tag {
            p.visit_expr(e_.tag.as_mut().unwrap());

            if Self::ALLOW_MACROS {
                let ref_ = match &e_.tag.unwrap().data {
                    Data::EImportIdentifier(ident) => Some(ident.ref_),
                    Data::EDot(dot) => match &dot.target.data {
                        Data::EIdentifier(id) => Some(id.ref_),
                        _ => None,
                    },
                    _ => None,
                };

                if let Some(ref_) = ref_
                    && !p.options.features.is_macro_runtime
                {
                    if let Some(macro_ref_data) = p.macro_.refs.get(&ref_).copied() {
                        p.ignore_usage(ref_);
                        if p.is_control_flow_dead {
                            *e = p.new_expr(E::Undefined {}, e_.tag.unwrap().loc);
                            return;
                        }

                        // this ordering incase someone wants to use a macro in a node_module conditionally
                        if p.options.features.no_macros {
                            p.log()
                                .add_error(Some(p.source), tag.loc, b"Macros are disabled");
                            *e = p.new_expr(E::Undefined {}, e_.tag.unwrap().loc);
                            return;
                        }

                        if p.source.path.is_node_module() {
                            p.log().add_error(
                                Some(p.source),
                                expr.loc,
                                b"For security reasons, macros cannot be run from node_modules.",
                            );
                            *e = p.new_expr(E::Undefined {}, expr.loc);
                            return;
                        }

                        p.macro_call_count += 1;
                        let name: &[u8] = macro_ref_data.name.unwrap_or_else(|| {
                            e_.tag
                                .unwrap()
                                .data
                                .e_dot()
                                .expect("infallible: variant checked")
                                .name
                                .slice()
                        });
                        let (record_path_text, record_range) = {
                            let record =
                                &p.import_records.items()[macro_ref_data.import_record_id as usize];
                            (record.path.text, record.range)
                        };
                        // We must visit it to convert inline_identifiers and record usage
                        // Reborrow via the field-disjoint `Lexer::log()` accessor
                        // so `&p.lexer` and `&mut p.options` split cleanly under
                        // borrowck — Zig held two raw `*Log`.
                        let log = p.lexer.log();
                        let source = p.source;
                        let Ok(macro_result) = p
                            .options
                            .macro_context
                            .as_deref_mut()
                            .expect("macro_context")
                            .call(
                                record_path_text,
                                source.path.source_dir(),
                                log,
                                source,
                                record_range,
                                expr,
                                name,
                            )
                        else {
                            return;
                        };

                        if !matches!(macro_result.data, Data::ETemplate(..)) {
                            *e = macro_result;
                            p.visit_expr(e);
                            return;
                        }
                    }
                }
            }
        }

        // `Template.parts` is arena-owned (Zig: `[]E.TemplatePart`).
        for part in e_.parts_mut().iter_mut() {
            p.visit_expr(&mut part.value);
        }

        // When mangling, inline string values into the template literal. Note that
        // it may no longer be a template literal after this point (it may turn into
        // a plain string literal instead).
        if p.should_fold_typescript_constant_expressions || p.options.features.inlining {
            *e = e_.fold(p.arena, expr.loc);
            return;
        }
    }
    fn e_binary(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        use crate::visit::visit_binary::BinaryExpressionVisitor;
        let e_ = expr.data.e_binary().expect("infallible: variant checked");

        // The handling of binary expressions is convoluted because we're using
        // iteration on the heap instead of recursion on the call stack to avoid
        // stack overflow for deeply-nested ASTs.
        //
        // PORT NOTE: Zig stores `*E.Binary` (arena ptr). `BinaryExpressionVisitor.e`
        // is the `StoreRef<E::Binary>` arena handle directly — `Copy` + safe
        // `Deref`/`DerefMut`, so no raw-pointer detach is needed here.
        let mut v: BinaryExpressionVisitor = BinaryExpressionVisitor {
            e: e_,
            loc: expr.loc,
            in_,
            left_in: ExprIn::default(),
            is_stmt_expr: false,
        };

        // Everything uses a single stack to reduce allocation overhead. This stack
        // should almost always be very small, and almost all visits should reuse
        // existing memory without allocating anything.
        let stack_bottom = p.binary_expression_stack.len();

        // Assigned on every `break` arm of the loop below; the initial input
        // `expr` is never read directly (Zig's `var current = expr` was a
        // pre-init habit, not load-bearing).
        let mut current;

        // Iterate down into the AST along the left node of the binary operation.
        // Continue iterating until we encounter something that's not a binary node.
        loop {
            if let Some(out) = BinaryExpressionVisitor::check_and_prepare(&mut v, p) {
                current = out;
                break;
            }

            // Grab the arguments to our nested "visitExprInOut" call for the left
            // node. We only care about deeply-nested left nodes because most binary
            // operators in JavaScript are left-associative and the problematic edge
            // cases we're trying to avoid crashing on have lots of left-associative
            // binary operators chained together without parentheses (e.g. "1+2+...").
            let left = v.e.left;
            let left_in = v.left_in;

            let left_binary: Option<js_ast::StoreRef<E::Binary>> = left.data.e_binary();

            // Stop iterating if iteration doesn't apply to the left node. This checks
            // the assignment target because "visitExprInOut" has additional behavior
            // in that case that we don't want to miss (before the top-level "switch"
            // statement).
            if left_binary.is_none() || left_in.assign_target != js_ast::AssignTarget::None {
                p.visit_expr_in_out(&mut v.e.left, left_in);
                current = BinaryExpressionVisitor::visit_right_and_finish(&mut v, p);
                break;
            }

            // Note that we only append to the stack (and therefore allocate memory
            // on the heap) when there are nested binary expressions. A single binary
            // expression doesn't add anything to the stack.
            p.binary_expression_stack.push(v);
            v = BinaryExpressionVisitor {
                e: left_binary.unwrap(),
                loc: left.loc,
                in_: left_in,
                left_in: ExprIn::default(),
                is_stmt_expr: false,
            };
        }

        // Process all binary operations from the deepest-visited node back toward
        // our original top-level binary operation.
        while p.binary_expression_stack.len() > stack_bottom {
            v = p.binary_expression_stack.pop().unwrap();
            v.e.left = current;
            current = BinaryExpressionVisitor::visit_right_and_finish(&mut v, p);
        }

        *e = current;
    }

    fn e_index(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        let mut e_ = expr.data.e_index().expect("infallible: variant checked");
        let is_call_target = matches!(p.call_target, Data::EIndex(ct) if core::ptr::eq(&raw const *e_, &raw const *ct));
        let is_delete_target = matches!(p.delete_target, Data::EIndex(dt) if core::ptr::eq(&raw const *e_, &raw const *dt));

        // "a['b']" => "a.b"
        if p.options.features.minify_syntax {
            if let Some(mut s) = e_.index.data.e_string() {
                if !s.is_utf16 && s.is_identifier(p.arena) {
                    let dot = p.new_expr(
                        E::Dot {
                            name: s.data,
                            name_loc: e_.index.loc,
                            target: e_.target,
                            optional_chain: e_.optional_chain,
                            ..Default::default()
                        },
                        expr.loc,
                    );

                    if is_call_target {
                        p.call_target = dot.data;
                    }
                    if is_delete_target {
                        p.delete_target = dot.data;
                    }

                    *e = dot;
                    p.visit_expr_in_out(e, in_);
                    return;
                }
            }
        }

        let has_chain_parent = e_.optional_chain == Some(js_ast::OptionalChain::Continuation);
        p.visit_expr_in_out(
            &mut e_.target,
            ExprIn {
                has_chain_parent,
                ..Default::default()
            },
        );

        match e_.index.data {
            Data::EPrivateIdentifier(mut private) => {
                let name = p.load_name_from_ref(private.ref_);
                let result = p.find_symbol(e_.index.loc, name).expect("unreachable");
                private.ref_ = result.r#ref;

                // Unlike regular identifiers, there are no unbound private identifiers
                let kind: js_ast::symbol::Kind =
                    p.symbols[result.r#ref.inner_index() as usize].kind;
                if !Symbol::is_kind_private(kind) {
                    let r = bun_ast::Range {
                        loc: e_.index.loc,
                        len: i32::try_from(name.len()).expect("int cast"),
                    };
                    p.log().add_range_error_fmt(
                        Some(p.source),
                        r,
                        format_args!(
                            "Private name \"{}\" must be declared in an enclosing class",
                            BStr::new(name)
                        ),
                    );
                } else {
                    if in_.assign_target != js_ast::AssignTarget::None
                        && (kind == js_ast::symbol::Kind::PrivateMethod
                            || kind == js_ast::symbol::Kind::PrivateStaticMethod)
                    {
                        let r = bun_ast::Range {
                            loc: e_.index.loc,
                            len: i32::try_from(name.len()).expect("int cast"),
                        };
                        p.log().add_range_warning_fmt(
                            Some(p.source),
                            r,
                            format_args!(
                                "Writing to read-only method \"{}\" will throw",
                                BStr::new(name)
                            ),
                        );
                    } else if in_.assign_target != js_ast::AssignTarget::None
                        && (kind == js_ast::symbol::Kind::PrivateGet
                            || kind == js_ast::symbol::Kind::PrivateStaticGet)
                    {
                        let r = bun_ast::Range {
                            loc: e_.index.loc,
                            len: i32::try_from(name.len()).expect("int cast"),
                        };
                        p.log().add_range_warning_fmt(
                            Some(p.source),
                            r,
                            format_args!(
                                "Writing to getter-only property \"{}\" will throw",
                                BStr::new(name)
                            ),
                        );
                    } else if in_.assign_target != js_ast::AssignTarget::Replace
                        && (kind == js_ast::symbol::Kind::PrivateSet
                            || kind == js_ast::symbol::Kind::PrivateStaticSet)
                    {
                        let r = bun_ast::Range {
                            loc: e_.index.loc,
                            len: i32::try_from(name.len()).expect("int cast"),
                        };
                        p.log().add_range_warning_fmt(
                            Some(p.source),
                            r,
                            format_args!(
                                "Reading from setter-only property \"{}\" will throw",
                                BStr::new(name)
                            ),
                        );
                    }
                }

                e_.index = Expr {
                    data: Data::EPrivateIdentifier(private),
                    loc: e_.index.loc,
                };
            }
            _ => {
                p.visit_expr(&mut e_.index);

                let unwrapped = e_.index.unwrap_inlined();
                if let Some(mut s) = unwrapped.data.e_string() {
                    if !s.is_utf16 {
                        // "a['b' + '']" => "a.b"
                        // "enum A { B = 'b' }; a[A.B]" => "a.b"
                        if p.options.features.minify_syntax && s.is_identifier(p.arena) {
                            let dot = p.new_expr(
                                E::Dot {
                                    name: s.data,
                                    name_loc: unwrapped.loc,
                                    target: e_.target,
                                    optional_chain: e_.optional_chain,
                                    ..Default::default()
                                },
                                expr.loc,
                            );

                            if is_call_target {
                                p.call_target = dot.data;
                            }
                            if is_delete_target {
                                p.delete_target = dot.data;
                            }

                            // don't call visitExprInOut on `dot` because we've already visited `target` above!
                            *e = dot;
                            return;
                        }

                        // Handle property rewrites to ensure things
                        // like .e_import_identifier tracking works
                        // Reminder that this can only be done after
                        // `target` is visited.
                        if let Some(rewrite) = p.maybe_rewrite_property_access(
                            expr.loc,
                            e_.target,
                            s.data.slice(),
                            unwrapped.loc,
                            IdentifierOpts::default()
                                .with_is_call_target(is_call_target)
                                // .is_template_tag = is_template_tag,
                                .with_is_delete_target(is_delete_target)
                                .with_assign_target(in_.assign_target),
                        ) {
                            *e = rewrite;
                            return;
                        }
                    }
                }
            }
        }

        let target = e_.target.unwrap_inlined();
        let index = e_.index.unwrap_inlined();

        if p.options.features.minify_syntax {
            if let Some(number) = index.data.as_e_number() {
                if number.value >= 0.0
                    && number.value < (usize::MAX as f64)
                    && number.value % 1.0 == 0.0
                {
                    // "foo"[2] -> "o"
                    if let Some(str_) = target.data.as_e_string() {
                        if !str_.is_utf16 {
                            let literal = str_.data;
                            let num: usize = index
                                .data
                                .e_number()
                                .expect("infallible: variant checked")
                                .to_usize();
                            if cfg!(debug_assertions) {
                                debug_assert!(strings::is_all_ascii(&literal));
                            }
                            if num < literal.len() {
                                *e = p.new_expr(
                                    E::String {
                                        data: E::Str::new(&literal[num..num + 1]),
                                        ..Default::default()
                                    },
                                    expr.loc,
                                );
                                return;
                            }
                        }
                    } else if let Some(array) = target.data.as_e_array() {
                        // [x][0] -> x
                        if array.items.len_u32() == 1 && number.value == 0.0 {
                            let inlined = *array.items.at(0);
                            if inlined.can_be_inlined_from_property_access() {
                                *e = inlined;
                                return;
                            }
                        }

                        // ['a', 'b', 'c'][1] -> 'b'
                        let int: usize = number.value as usize;
                        if int < array.items.len_u32() as usize
                            && p.expr_can_be_removed_if_unused(&target)
                        {
                            let inlined = *array.items.at(int);
                            // ['a', , 'c'][1] -> undefined
                            if matches!(inlined.data, Data::EMissing(..)) {
                                *e = p.new_expr(E::Undefined {}, inlined.loc);
                                return;
                            }
                            if cfg!(debug_assertions) {
                                debug_assert!(inlined.can_be_inlined_from_property_access());
                            }
                            *e = inlined;
                            return;
                        }
                    }
                }
            }
        }

        // Create an error for assigning to an import namespace when bundling. Even
        // though this is a run-time error, we make it a compile-time error when
        // bundling because scope hoisting means these will no longer be run-time
        // errors.
        if (in_.assign_target != js_ast::AssignTarget::None || is_delete_target)
            && matches!(e_.target.data.tag(), Tag::EIdentifier)
            && p.symbols[e_
                .target
                .data
                .e_identifier()
                .expect("infallible: variant checked")
                .ref_
                .inner_index() as usize]
                .kind
                == js_ast::symbol::Kind::Import
        {
            let r = js_lexer::range_of_identifier(p.source, e_.target.loc);
            p.log().add_range_error_fmt(
                Some(p.source),
                r,
                format_args!(
                    "Cannot assign to property on import \"{}\"",
                    // `original_name: StoreStr` has a safe `Deref<Target=[u8]>`.
                    BStr::new(
                        &*p.symbols[e_
                            .target
                            .data
                            .e_identifier()
                            .expect("infallible: variant checked")
                            .ref_
                            .inner_index() as usize]
                            .original_name,
                    )
                ),
            );
        }

        // PORT NOTE: `e_` is `StoreRef<E::Index>` — mutations above wrote through
        // DerefMut into the same arena slot `expr.data` already points at. Zig's
        // `p.newExpr(e_, loc)` re-wraps the same pointer; here `*e` is already that.
    }

    fn e_unary(p: &mut Self, e: &mut Expr, _: ExprIn) {
        let expr = *e;
        let mut e_ = expr.data.e_unary().expect("infallible: variant checked");
        match e_.op {
            Op::UnTypeof => {
                let id_before = matches!(e_.value.data, Data::EIdentifier(..));
                let assign_target = Op::unary_assign_target(e_.op);
                p.visit_expr_in_out(
                    &mut e_.value,
                    ExprIn {
                        assign_target,
                        ..Default::default()
                    },
                );
                let id_after = matches!(e_.value.data, Data::EIdentifier(..));

                // The expression "typeof (0, x)" must not become "typeof x" if "x"
                // is unbound because that could suppress a ReferenceError from "x"
                if !id_before
                    && id_after
                    && p.symbols[e_
                        .value
                        .data
                        .e_identifier()
                        .expect("infallible: variant checked")
                        .ref_
                        .inner_index() as usize]
                        .kind
                        == js_ast::symbol::Kind::Unbound
                {
                    e_.value = Expr {
                        loc: e_.value.loc,
                        data: prefill::data::ZERO,
                    }
                    .join_with_comma(e_.value);
                }

                if matches!(e_.value.data, Data::ERequireCallTarget) {
                    p.ignore_usage_of_runtime_require();
                    *e = p.new_expr(
                        E::String {
                            data: b"function".into(),
                            ..Default::default()
                        },
                        expr.loc,
                    );
                    return;
                }

                if let Some(typeof_) = SideEffects::typeof_(&e_.value.data) {
                    *e = p.new_expr(
                        E::String {
                            data: typeof_.into(),
                            ..Default::default()
                        },
                        expr.loc,
                    );
                    return;
                }
            }
            Op::UnDelete => {
                p.visit_expr_in_out(
                    &mut e_.value,
                    ExprIn {
                        has_chain_parent: true,
                        ..Default::default()
                    },
                );
            }
            _ => {
                let assign_target = Op::unary_assign_target(e_.op);
                p.visit_expr_in_out(
                    &mut e_.value,
                    ExprIn {
                        assign_target,
                        ..Default::default()
                    },
                );

                // Post-process the unary expression
                match e_.op {
                    Op::UnNot => {
                        if p.options.features.minify_syntax {
                            e_.value = SideEffects::simplify_boolean(p, e_.value);
                        }

                        let side_effects = SideEffects::to_boolean(p, &e_.value.data);
                        if side_effects.ok {
                            *e = p.new_expr(
                                E::Boolean {
                                    value: !side_effects.value,
                                },
                                expr.loc,
                            );
                            return;
                        }

                        if p.options.features.minify_syntax {
                            if let Some(exp) = Expr::maybe_simplify_not(&e_.value, p.arena) {
                                *e = exp;
                                return;
                            }
                            if let Data::EImportMetaMain(m) = &mut e_.value.data {
                                m.inverted = !m.inverted;
                                *e = e_.value;
                                return;
                            }
                        }
                    }
                    Op::UnCpl => {
                        if p.should_fold_typescript_constant_expressions {
                            if let Some(value) = SideEffects::to_number(&e_.value.data) {
                                *e = p.new_expr(
                                    E::Number {
                                        value: f64::from(!float_to_int32(value)),
                                    },
                                    expr.loc,
                                );
                                return;
                            }
                        }
                    }
                    Op::UnVoid => {
                        if p.expr_can_be_removed_if_unused(&e_.value) {
                            *e = p.new_expr(E::Undefined {}, e_.value.loc);
                            return;
                        }
                    }
                    Op::UnPos => {
                        if let Some(num) = SideEffects::to_number(&e_.value.data) {
                            *e = p.new_expr(E::Number { value: num }, expr.loc);
                            return;
                        }
                    }
                    Op::UnNeg => {
                        if let Some(num) = SideEffects::to_number(&e_.value.data) {
                            *e = p.new_expr(E::Number { value: -num }, expr.loc);
                            return;
                        }
                    }

                    ////////////////////////////////////////////////////////////////////////////////
                    Op::UnPreDec => {
                        // TODO: private fields
                    }
                    Op::UnPreInc => {
                        // TODO: private fields
                    }
                    Op::UnPostDec => {
                        // TODO: private fields
                    }
                    Op::UnPostInc => {
                        // TODO: private fields
                    }
                    _ => {}
                }

                if p.options.features.minify_syntax {
                    // "-(a, b)" => "a, -b"
                    if !matches!(e_.op, Op::UnDelete | Op::UnTypeof) {
                        if let Data::EBinary(comma) = &e_.value.data {
                            if comma.op == Op::BinComma {
                                *e = comma.left.join_with_comma(p.new_expr(
                                    E::Unary {
                                        op: e_.op,
                                        value: comma.right,
                                        flags: e_.flags,
                                    },
                                    comma.right.loc,
                                ));
                                return;
                            }
                        }
                    }
                }
            }
        }
    }
    fn e_dot(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        let mut e_ = expr.data.e_dot().expect("infallible: variant checked");
        let is_delete_target = matches!(p.delete_target, Data::EDot(dt) if core::ptr::eq(&raw const *e_, &raw const *dt));
        let is_call_target = matches!(p.call_target, Data::EDot(ct) if core::ptr::eq(&raw const *e_, &raw const *ct));

        // `p.define: &'a Define` is `Copy`; hoist so the `dots.get` borrow is
        // tied to `'a`, not `&*p`, and `&mut self` helpers below can be called
        // while iterating without laundering.
        let defines = p.define;
        if let Some(parts) = defines.dots.get(e_.name.slice()) {
            for define in parts.as_slice() {
                if p.is_dot_define_match(expr, &define.parts) {
                    if in_.assign_target == js_ast::AssignTarget::None {
                        // Substitute user-specified defines
                        if !define.data.valueless() {
                            *e = p.value_for_define(
                                expr.loc,
                                in_.assign_target,
                                is_delete_target,
                                &define.data,
                            );
                            return;
                        }

                        if define.data.method_call_must_be_replaced_with_undefined()
                            && in_
                                .property_access_for_method_call_maybe_should_replace_with_undefined
                        {
                            p.method_call_must_be_replaced_with_undefined = true;
                        }
                    }

                    // Copy the side effect flags over in case this expression is unused
                    if define.data.can_be_removed_if_unused() {
                        e_.can_be_removed_if_unused = true;
                    }

                    if define.data.call_can_be_unwrapped_if_unused() != E::CallUnwrap::Never
                        && !p.options.ignore_dce_annotations
                    {
                        e_.call_can_be_unwrapped_if_unused =
                            define.data.call_can_be_unwrapped_if_unused();
                    }

                    break;
                }
            }
        }

        // Track ".then().catch()" chains
        if is_call_target
            && matches!(p.then_catch_chain.next_target, Data::EDot(nt) if core::ptr::eq(&raw const *e_, &raw const *nt))
        {
            if e_.name == b"catch" {
                p.then_catch_chain = ThenCatchChain {
                    next_target: e_.target.data,
                    has_catch: true,
                    has_multiple_args: false,
                };
            } else if e_.name == b"then" {
                p.then_catch_chain = ThenCatchChain {
                    next_target: e_.target.data,
                    has_catch: p.then_catch_chain.has_catch || p.then_catch_chain.has_multiple_args,
                    has_multiple_args: false,
                };
            }
        }

        p.visit_expr_in_out(
            &mut e_.target,
            ExprIn {
                property_access_for_method_call_maybe_should_replace_with_undefined: in_
                    .property_access_for_method_call_maybe_should_replace_with_undefined,
                ..Default::default()
            },
        );

        // 'require.resolve' -> .e_require_resolve_call_target
        if matches!(e_.target.data, Data::ERequireCallTarget) && e_.name == b"resolve" {
            // we do not need to call p.recordUsageOfRuntimeRequire(); because `require`
            // was not a call target. even if the call target is `require.resolve`, it should be set.
            *e = Expr {
                data: Data::ERequireResolveCallTarget,
                loc: expr.loc,
            };
            return;
        }

        if e_.optional_chain.is_none() {
            if let Some(_expr) = p.maybe_rewrite_property_access(
                expr.loc,
                e_.target,
                e_.name.slice(),
                e_.name_loc,
                IdentifierOpts::default()
                    .with_is_call_target(is_call_target)
                    .with_assign_target(in_.assign_target)
                    .with_is_delete_target(is_delete_target),
                // .is_template_tag = p.template_tag != null,
            ) {
                *e = _expr;
                return;
            }

            if Self::ALLOW_MACROS {
                if !p.options.features.is_macro_runtime {
                    if p.macro_call_count > 0
                        && matches!(e_.target.data, Data::EObject(..))
                        && e_
                            .target
                            .data
                            .e_object()
                            .expect("infallible: variant checked")
                            .was_originally_macro
                    {
                        if let Some(obj) = e_.target.get(&e_.name) {
                            *e = obj;
                            return;
                        }
                    }
                }
            }
        }
    }

    fn e_if(p: &mut Self, e: &mut Expr, _: ExprIn) {
        let mut e_ = e.data.e_if().expect("infallible: variant checked");
        let is_call_target =
            matches!(p.call_target, Data::EIf(ct) if core::ptr::eq(&raw const *e_, &raw const *ct));

        let prev_in_branch = p.in_branch_condition;
        p.in_branch_condition = true;
        p.visit_expr(&mut e_.test_);
        p.in_branch_condition = prev_in_branch;

        e_.test_ = SideEffects::simplify_boolean(p, e_.test_);

        let side_effects = SideEffects::to_boolean(p, &e_.test_.data);

        if !side_effects.ok {
            p.visit_expr(&mut e_.yes);
            p.visit_expr(&mut e_.no);
        } else {
            // Mark the control flow as dead if the branch is never taken
            if side_effects.value {
                // "true ? live : dead"
                p.visit_expr(&mut e_.yes);
                let old = p.is_control_flow_dead;
                p.is_control_flow_dead = true;
                p.visit_expr(&mut e_.no);
                p.is_control_flow_dead = old;

                if side_effects.side_effects == SideEffects::CouldHaveSideEffects {
                    *e = SideEffects::simplify_unused_expr(p, e_.test_)
                        .unwrap_or_else(|| p.new_expr(E::Missing {}, e_.test_.loc))
                        .join_with_comma(e_.yes);
                    return;
                }

                // "(1 ? fn : 2)()" => "fn()"
                // "(1 ? this.fn : 2)" => "this.fn"
                // "(1 ? this.fn : 2)()" => "(0, this.fn)()"
                if is_call_target && e_.yes.has_value_for_this_in_call() {
                    *e = p
                        .new_expr(E::Number { value: 0.0 }, e_.test_.loc)
                        .join_with_comma(e_.yes);
                    return;
                }

                *e = e_.yes;
                return;
            } else {
                // "false ? dead : live"
                let old = p.is_control_flow_dead;
                p.is_control_flow_dead = true;
                p.visit_expr(&mut e_.yes);
                p.is_control_flow_dead = old;
                p.visit_expr(&mut e_.no);

                // "(a, false) ? b : c" => "a, c"
                if side_effects.side_effects == SideEffects::CouldHaveSideEffects {
                    *e = SideEffects::simplify_unused_expr(p, e_.test_)
                        .unwrap_or_else(|| p.new_expr(E::Missing {}, e_.test_.loc))
                        .join_with_comma(e_.no);
                    return;
                }

                // "(1 ? fn : 2)()" => "fn()"
                // "(1 ? this.fn : 2)" => "this.fn"
                // "(1 ? this.fn : 2)()" => "(0, this.fn)()"
                if is_call_target && e_.no.has_value_for_this_in_call() {
                    *e = p
                        .new_expr(E::Number { value: 0.0 }, e_.test_.loc)
                        .join_with_comma(e_.no);
                    return;
                }
                *e = e_.no;
                return;
            }
        }
    }

    #[inline(never)] // PERF(port:frame): see e_jsx_element.
    fn e_array(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let mut e_ = e.data.e_array().expect("infallible: variant checked");
        if in_.assign_target != js_ast::AssignTarget::None {
            p.maybe_comma_spread_error(e_.comma_after_spread);
        }
        let items = e_.items.slice_mut();
        let mut spread_item_count: usize = 0;
        for item in items {
            match &mut item.data {
                Data::EMissing(..) => {}
                Data::ESpread(spread) => {
                    p.visit_expr_in_out(
                        &mut spread.value,
                        ExprIn {
                            assign_target: in_.assign_target,
                            ..Default::default()
                        },
                    );

                    spread_item_count += if let Data::EArray(arr) = &spread.value.data {
                        arr.items.len_u32() as usize
                    } else {
                        0
                    };
                }
                Data::EBinary(e2) => {
                    if in_.assign_target != js_ast::AssignTarget::None && e2.op == Op::BinAssign {
                        let was_anonymous_named_expr = e2.right.is_anonymous_named();
                        // Propagate name for anonymous decorated class expressions
                        if was_anonymous_named_expr
                            && matches!(e2.right.data, Data::EClass(..))
                            && e2
                                .right
                                .data
                                .e_class()
                                .expect("infallible: variant checked")
                                .should_lower_standard_decorators
                            && matches!(e2.left.data.tag(), Tag::EIdentifier)
                        {
                            p.decorator_class_name = Some(
                                p.load_name_from_ref(
                                    e2.left
                                        .data
                                        .e_identifier()
                                        .expect("infallible: variant checked")
                                        .ref_,
                                ),
                            );
                        }
                        p.visit_expr_in_out(
                            &mut e2.left,
                            ExprIn {
                                assign_target: js_ast::AssignTarget::Replace,
                                ..Default::default()
                            },
                        );
                        p.visit_expr(&mut e2.right);
                        p.decorator_class_name = None;

                        if matches!(e2.left.data.tag(), Tag::EIdentifier) {
                            let name = p.symbols[e2
                                .left
                                .data
                                .e_identifier()
                                .expect("infallible: variant checked")
                                .ref_
                                .inner_index()
                                as usize]
                                .original_name;
                            e2.right = p.maybe_keep_expr_symbol_name(
                                e2.right,
                                name.slice(),
                                was_anonymous_named_expr,
                            );
                        }
                    } else {
                        p.visit_expr_in_out(
                            item,
                            ExprIn {
                                assign_target: in_.assign_target,
                                ..Default::default()
                            },
                        );
                    }
                }
                _ => {
                    p.visit_expr_in_out(
                        item,
                        ExprIn {
                            assign_target: in_.assign_target,
                            ..Default::default()
                        },
                    );
                }
            }
        }

        // "[1, ...[2, 3], 4]" => "[1, 2, 3, 4]"
        if p.options.features.minify_syntax
            && spread_item_count > 0
            && in_.assign_target == js_ast::AssignTarget::None
        {
            if let Ok(items) = e_.inline_spread_of_array_literals(p.arena, spread_item_count) {
                e_.items = items;
            }
        }
    }

    #[inline(never)] // PERF(port:frame): see e_jsx_element.
    fn e_object(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let mut e_ = e.data.e_object().expect("infallible: variant checked");
        if in_.assign_target != js_ast::AssignTarget::None {
            p.maybe_comma_spread_error(e_.comma_after_spread);
        }

        let mut has_spread = false;
        let mut has_proto = false;
        for property in e_.properties.slice_mut() {
            if property.kind != G::PropertyKind::Spread {
                p.visit_expr(
                    property
                        .key
                        .as_mut()
                        .unwrap_or_else(|| panic!("Expected property key")),
                );
                let key = property.key.expect("infallible: prop has key");
                // Forbid duplicate "__proto__" properties according to the specification
                if !property.flags.contains(Flags::Property::IsComputed)
                    && !property.flags.contains(Flags::Property::WasShorthand)
                    && !property.flags.contains(Flags::Property::IsMethod)
                    && in_.assign_target == js_ast::AssignTarget::None
                    && key.data.is_string_value()
                    && key
                        .data
                        .e_string()
                        .expect("infallible: variant checked")
                        .data
                        == b"__proto__"
                // __proto__ is utf8, assume it lives in refs
                {
                    if has_proto {
                        let r = js_lexer::range_of_identifier(p.source, key.loc);
                        p.log().add_range_error(
                            Some(p.source),
                            r,
                            b"Cannot specify the \"__proto__\" property more than once per object",
                        );
                    }
                    has_proto = true;
                }
            } else {
                has_spread = true;
            }

            // Extract the initializer for expressions like "({ a: b = c } = d)"
            if in_.assign_target != js_ast::AssignTarget::None
                && property.initializer.is_none()
                && property.value.is_some()
            {
                if let Data::EBinary(bin) =
                    &property.value.expect("infallible: prop has value").data
                {
                    if bin.op == Op::BinAssign {
                        property.initializer = Some(bin.right);
                        property.value = Some(bin.left);
                    }
                }
            }

            if let Some(value) = &mut property.value {
                // Propagate name from property key for decorated anonymous class expressions
                // e.g., { Foo: @dec class {} } should give the class .name = "Foo"
                if in_.assign_target == js_ast::AssignTarget::None
                    && matches!(value.data, Data::EClass(..))
                    && value
                        .data
                        .e_class()
                        .unwrap()
                        .should_lower_standard_decorators
                    && value
                        .data
                        .e_class()
                        .expect("infallible: variant checked")
                        .class_name
                        .is_none()
                    && let Some(key) = property.key
                    && matches!(key.data, Data::EString(..))
                {
                    let key_str = key.data.e_string().expect("infallible: variant checked");
                    // PORT NOTE: Zig `string(arena)` transcodes UTF-16; while
                    // E.rs has duplicate impls (E0034), reach the bytes directly
                    // — class-name keys are parser-produced (UTF-8, no rope).
                    p.decorator_class_name = if !key_str.is_utf16 {
                        Some(key_str.data.slice())
                    } else {
                        None
                    };
                }
                p.visit_expr_in_out(
                    value,
                    ExprIn {
                        assign_target: in_.assign_target,
                        ..Default::default()
                    },
                );
                p.decorator_class_name = None;
            }

            if property.initializer.is_some() {
                let was_anonymous_named_expr = property.initializer.unwrap().is_anonymous_named();
                if was_anonymous_named_expr
                    && matches!(property.initializer.unwrap().data, Data::EClass(..))
                    && property
                        .initializer
                        .unwrap()
                        .data
                        .e_class()
                        .unwrap()
                        .should_lower_standard_decorators
                {
                    if let Some(val) = property.value {
                        if matches!(val.data.tag(), Tag::EIdentifier) {
                            p.decorator_class_name = Some(
                                p.load_name_from_ref(
                                    val.data
                                        .e_identifier()
                                        .expect("infallible: variant checked")
                                        .ref_,
                                ),
                            );
                        }
                    }
                }
                p.visit_expr(property.initializer.as_mut().unwrap());
                p.decorator_class_name = None;

                if let Some(val) = property.value {
                    if matches!(val.data.tag(), Tag::EIdentifier) {
                        let name = p.symbols[val
                            .data
                            .e_identifier()
                            .expect("infallible: variant checked")
                            .ref_
                            .inner_index() as usize]
                            .original_name;
                        property.initializer = Some(p.maybe_keep_expr_symbol_name(
                            property.initializer.expect("unreachable"),
                            name.slice(),
                            was_anonymous_named_expr,
                        ));
                    }
                }
            }
        }
        let _ = has_spread;
    }
    #[inline(never)] // PERF(port:frame): see e_jsx_element.
    fn e_import(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let _ = in_;
        let mut e_ = e.data.e_import().expect("infallible: variant checked");
        // We want to forcefully fold constants inside of imports
        // even when minification is disabled, so that if we have an
        // import based on a string template, it does not cause a
        // bundle error. This is especially relevant for bundling NAPI
        // modules with 'bun build --compile':
        //
        // const binding = await import(`./${process.platform}-${process.arch}.node`);
        //
        // PORT NOTE: Zig `defer` restores at scope exit; restored manually before each return.
        let prev_should_fold_typescript_constant_expressions = true;
        p.should_fold_typescript_constant_expressions = true;

        p.visit_expr(&mut e_.expr);
        p.visit_expr(&mut e_.options);

        // Import transposition is able to duplicate the options structure, so
        // only perform it if the expression is side effect free.
        //
        // TODO: make this more like esbuild by emitting warnings that explain
        // why this import was not analyzed. (see esbuild 'unsupported-dynamic-import')
        if p.expr_can_be_removed_if_unused(&e_.options) {
            let state = TransposeState {
                is_await_target: matches!(
                    p.await_target,
                    Some(Data::EImport(at)) if core::ptr::eq(&raw const *e_, &raw const *at)
                ),
                is_then_catch_target: p.then_catch_chain.has_catch
                    && matches!(
                        p.then_catch_chain.next_target,
                        Data::EImport(nt) if core::ptr::eq(&raw const *e_, &raw const *nt)
                    ),
                import_options: e_.options,
                loc: e_.expr.loc,
                import_loader: e_.import_record_loader(),
                ..Default::default()
            };

            p.should_fold_typescript_constant_expressions =
                prev_should_fold_typescript_constant_expressions;
            *e = p.maybe_transpose_if_import(e_.expr, &state);
            return;
        }
        p.should_fold_typescript_constant_expressions =
            prev_should_fold_typescript_constant_expressions;
    }
    fn e_call(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        let mut e_ = expr.data.e_call().expect("infallible: variant checked");
        p.call_target = e_.target.data;

        p.then_catch_chain = ThenCatchChain {
            next_target: e_.target.data,
            has_multiple_args: e_.args.len_u32() >= 2,
            has_catch: matches!(
                p.then_catch_chain.next_target,
                Data::ECall(nt) if core::ptr::eq(&raw const *e_, &raw const *nt)
            ) && p.then_catch_chain.has_catch,
        };

        let target_was_identifier_before_visit = matches!(e_.target.data, Data::EIdentifier(..));
        let has_chain_parent = e_.optional_chain == Some(js_ast::OptionalChain::Continuation);
        p.visit_expr_in_out(
            &mut e_.target,
            ExprIn {
                has_chain_parent,
                property_access_for_method_call_maybe_should_replace_with_undefined: true,
                ..Default::default()
            },
        );

        // Copy the call side effect flag over if this is a known target
        // PORT NOTE: copy the small inline payloads out first so the `match &e_.target.data`
        // borrow doesn't overlap the `e_.can_be_unwrapped_if_unused = …` write below.
        match e_.target.data {
            Data::EIdentifier(ident) => {
                if ident.call_can_be_unwrapped_if_unused()
                    && e_.can_be_unwrapped_if_unused == E::CallUnwrap::Never
                {
                    e_.can_be_unwrapped_if_unused = E::CallUnwrap::IfUnused;
                }

                // Detect if this is a direct eval. Note that "(1 ? eval : 0)(x)" will
                // become "eval(x)" after we visit the target due to dead code elimination,
                // but that doesn't mean it should become a direct eval.
                //
                // Note that "eval?.(x)" is considered an indirect eval. There was debate
                // about this after everyone implemented it as a direct eval, but the
                // language committee said it was indirect and everyone had to change it:
                // https://github.com/tc39/ecma262/issues/2062.
                if e_.optional_chain.is_none()
                    && target_was_identifier_before_visit
                    && p.symbols[ident.ref_.inner_index() as usize]
                        .original_name
                        .slice()
                        == b"eval"
                {
                    e_.is_direct_eval = true;

                    // Pessimistically assume that if this looks like a CommonJS module
                    // (e.g. no "export" keywords), a direct call to "eval" means that
                    // code could potentially access "module" or "exports".
                    if p.options.bundle && !p.is_file_considered_to_have_esm_exports {
                        p.record_usage(p.module_ref);
                        p.record_usage(p.exports_ref);
                    }

                    // PORT NOTE: `Scope.parent: ?*Scope` in Zig is `Option<StoreRef<Scope>>` here;
                    // walk via the safe arena back-pointer.
                    let mut scope_iter: Option<js_ast::StoreRef<js_ast::Scope>> =
                        Some(p.current_scope);
                    while let Some(mut scope) = scope_iter {
                        scope.contains_direct_eval = true;
                        scope_iter = scope.parent;
                    }

                    // TODO: Log a build note for this like esbuild does
                }
            }
            Data::EDot(dot) => {
                if dot.call_can_be_unwrapped_if_unused != E::CallUnwrap::Never
                    && e_.can_be_unwrapped_if_unused == E::CallUnwrap::Never
                {
                    e_.can_be_unwrapped_if_unused = dot.call_can_be_unwrapped_if_unused;
                }
            }
            _ => {}
        }

        let is_macro_ref: bool = if Self::ALLOW_MACROS {
            let possible_macro_ref = match &e_.target.data {
                Data::EImportIdentifier(ident) => Some(ident.ref_),
                Data::EDot(dot) => {
                    if let Data::EIdentifier(id) = &dot.target.data {
                        Some(id.ref_)
                    } else {
                        None
                    }
                }
                _ => None,
            };

            possible_macro_ref.is_some() && p.macro_.refs.contains_key(&possible_macro_ref.unwrap())
        } else {
            false
        };

        {
            let old_ce = p.options.ignore_dce_annotations;
            // PORT NOTE: Zig `defer` restores at scope exit; do it manually below.
            let old_should_fold_typescript_constant_expressions =
                p.should_fold_typescript_constant_expressions;
            let old_is_control_flow_dead = p.is_control_flow_dead;

            // We want to forcefully fold constants inside of
            // certain calls even when minification is disabled, so
            // that if we have an import based on a string template,
            // it does not cause a bundle error. This is relevant for
            // macros, as they require constant known values, but also
            // for `require` and `require.resolve`, as they go through
            // the module resolver.
            if is_macro_ref
                || matches!(e_.target.data, Data::ERequireCallTarget)
                || matches!(e_.target.data, Data::ERequireResolveCallTarget)
            {
                p.options.ignore_dce_annotations = true;
                p.should_fold_typescript_constant_expressions = true;
            }

            // When a value is targeted by `--drop`, it will be removed.
            // The HMR APIs in `import.meta.hot` are implicitly dropped when HMR is disabled.
            let mut method_call_should_be_replaced_with_undefined =
                p.method_call_must_be_replaced_with_undefined;
            if method_call_should_be_replaced_with_undefined {
                p.method_call_must_be_replaced_with_undefined = false;
                match &e_.target.data {
                    // If we're removing this call, don't count any arguments as symbol uses
                    Data::EIndex(..) | Data::EDot(..) | Data::EIdentifier(..) => {
                        p.is_control_flow_dead = true;
                    }
                    // Special case from `import.meta.hot.*` functions.
                    Data::EUndefined(..) => {
                        p.is_control_flow_dead = true;
                    }
                    _ => {
                        method_call_should_be_replaced_with_undefined = false;
                    }
                }
            }

            for arg in e_.args.slice_mut() {
                p.visit_expr(arg);
            }

            // Restore deferred state (Zig `defer`).
            p.options.ignore_dce_annotations = old_ce;
            p.should_fold_typescript_constant_expressions =
                old_should_fold_typescript_constant_expressions;

            if method_call_should_be_replaced_with_undefined {
                p.is_control_flow_dead = old_is_control_flow_dead;
                *e = Expr {
                    data: Data::EUndefined(E::Undefined {}),
                    loc: expr.loc,
                };
                return;
            }
        }

        // Handle `feature("FLAG_NAME")` calls from `import { feature } from "bun:bundle"`
        // Check if the bundler_feature_flag_ref is set before calling the function
        // to avoid stack memory usage from copying values back and forth.
        if p.bundler_feature_flag_ref.is_valid() {
            if let Some(result) = Self::maybe_replace_bundler_feature_call(p, &mut *e_, expr.loc) {
                *e = result;
                return;
            }
        }

        if matches!(e_.target.data, Data::ERequireCallTarget) {
            e_.can_be_unwrapped_if_unused = E::CallUnwrap::Never;

            // Heuristic: omit warnings inside try/catch blocks because presumably
            // the try/catch statement is there to handle the potential run-time
            // error from the unbundled require() call failing.
            if e_.args.len_u32() == 1 {
                let first = e_.args.slice()[0];
                let state = TransposeState {
                    is_require_immediately_assigned_to_decl: in_.is_immediately_assigned_to_decl
                        && matches!(first.data, Data::EString(..)),
                    ..Default::default()
                };
                match &first.data {
                    Data::EString(..) => {
                        // require(FOO) => require(FOO)
                        *e = p.transpose_require(first, &state);
                        return;
                    }
                    Data::EIf(..) => {
                        // require(FOO  ? '123' : '456') => FOO ? require('123') : require('456')
                        // This makes static analysis later easier
                        *e = p.transpose_known_to_be_if_require(first, &state);
                        return;
                    }
                    _ => {}
                }
            }

            // Ignore calls to require() if the control flow is provably
            // dead here. We don't want to spend time scanning the required files
            // if they will never be used.
            if p.is_control_flow_dead {
                *e = p.new_expr(E::Null {}, expr.loc);
                return;
            }

            if p.options.warn_about_unbundled_modules {
                let r = js_lexer::range_of_identifier(p.source, e_.target.loc);
                p.log()
                    .add_range_debug(
                        Some(p.source),
                        r,
                        b"This call to \"require\" will not be bundled because it has multiple arguments",
                    );
            }

            if e_.args.len_u32() >= 1 {
                p.check_dynamic_specifier(e_.args.slice()[0], e_.target.loc, "require()")
                    .expect("unreachable");
            }

            if p.options.features.allow_runtime {
                p.record_usage_of_runtime_require();
            }

            return;
        } else if matches!(e_.target.data, Data::ERequireResolveCallTarget) {
            // Ignore calls to require.resolve() if the control flow is provably
            // dead here. We don't want to spend time scanning the required files
            // if they will never be used.
            if p.is_control_flow_dead {
                *e = p.new_expr(E::Null {}, expr.loc);
                return;
            }

            if e_.args.len_u32() == 1 {
                let first = e_.args.slice()[0];
                match &first.data {
                    Data::EString(..) => {
                        // require.resolve(FOO) => require.resolve(FOO)
                        // (this will register dependencies)
                        *e = p.transpose_require_resolve_known_string(first);
                        return;
                    }
                    Data::EIf(..) => {
                        // require.resolve(FOO  ? '123' : '456')
                        //  =>
                        // FOO ? require.resolve('123') : require.resolve('456')
                        // This makes static analysis later easier
                        *e = p.transpose_known_to_be_if_require_resolve(first, e_.target);
                        return;
                    }
                    _ => {}
                }
            }

            if e_.args.len_u32() >= 1 {
                p.check_dynamic_specifier(e_.args.slice()[0], e_.target.loc, "require.resolve()")
                    .expect("unreachable");
            }

            return;
        } else if let Some(special) = e_.target.data.e_special() {
            match special {
                E::Special::HotAccept => {
                    p.handle_import_meta_hot_accept_call(&mut *e_);
                    // After validating that the import.meta.hot
                    // code is correct, discard the entire
                    // expression in production.
                    if !p.options.features.hot_module_reloading {
                        *e = Expr {
                            data: Data::EUndefined(E::Undefined {}),
                            loc: expr.loc,
                        };
                        return;
                    }
                }
                _ => {}
            }
        }

        if Self::ALLOW_MACROS {
            if is_macro_ref && !p.options.features.is_macro_runtime {
                let ref_ = match &e_.target.data {
                    Data::EImportIdentifier(ident) => ident.ref_,
                    Data::EDot(dot) => {
                        dot.target
                            .data
                            .e_identifier()
                            .expect("infallible: variant checked")
                            .ref_
                    }
                    _ => unreachable!(),
                };

                let macro_ref_data = *p.macro_.refs.get(&ref_).unwrap();
                p.ignore_usage(ref_);
                if p.is_control_flow_dead {
                    *e = p.new_expr(E::Undefined {}, e_.target.loc);
                    return;
                }

                if p.options.features.no_macros {
                    p.log()
                        .add_error(Some(p.source), expr.loc, b"Macros are disabled");
                    *e = p.new_expr(E::Undefined {}, expr.loc);
                    return;
                }

                if p.source.path.is_node_module() {
                    p.log().add_error(
                        Some(p.source),
                        expr.loc,
                        b"For security reasons, macros cannot be run from node_modules.",
                    );
                    *e = p.new_expr(E::Undefined {}, expr.loc);
                    return;
                }

                let name: &[u8] = macro_ref_data.name.unwrap_or_else(|| {
                    e_.target
                        .data
                        .e_dot()
                        .expect("infallible: variant checked")
                        .name
                        .slice()
                });
                let (record_path_text, record_range) = {
                    let record =
                        &p.import_records.items()[macro_ref_data.import_record_id as usize];
                    (record.path.text, record.range)
                };
                let copied = Expr {
                    loc: expr.loc,
                    data: expr.data,
                };
                let start_error_count = p.log().msgs.len();
                p.macro_call_count += 1;
                // Reborrow via the field-disjoint `Lexer::log()` accessor
                // so `&p.lexer` and `&mut p.options` split cleanly under
                // borrowck — Zig held two raw `*Log`.
                let log = p.lexer.log();
                let source = p.source;
                let macro_result = match p
                    .options
                    .macro_context
                    .as_deref_mut()
                    .expect("macro_context")
                    .call(
                        record_path_text,
                        source.path.source_dir(),
                        log,
                        source,
                        record_range,
                        copied,
                        name,
                    ) {
                    Ok(r) => r,
                    Err(err) => {
                        if err == bun_core::err!("MacroFailed") {
                            if p.log().msgs.len() == start_error_count {
                                p.log().add_error(
                                    Some(p.source),
                                    expr.loc,
                                    b"macro threw exception",
                                );
                            }
                        } else {
                            p.log().add_error_fmt(
                                Some(p.source),
                                expr.loc,
                                format_args!("\"{}\" error in macro", err.name()),
                            );
                        }
                        return;
                    }
                };

                if !matches!(macro_result.data, Data::ECall(..)) {
                    *e = macro_result;
                    p.visit_expr(e);
                    return;
                }
            }
        }

        // In fast refresh, any function call that looks like a hook (/^use[A-Z]/) is a
        // hook, even if it is not the value of `SExpr` or `SLocal`. It can be anywhere
        // in the function call. This makes sense for some weird situations with `useCallback`,
        // where it is not assigned to a variable.
        //
        // When we see a hook call, we need to hash it, and then mark a flag so that if
        // it is assigned to a variable, that variable also get's hashed.
        //
        // PORT NOTE: `Runtime::Features.server_components` is a `bool` stub; the
        // full Zig type is `enum { off, client, server }` with `.isServerSide()`. Treat
        // `true` as server-side until the enum lands.
        if p.options.features.react_fast_refresh
            || p.options.features.server_components.is_server_side()
        {
            'try_record_hook: {
                let original_name: &[u8] = match &e_.target.data {
                    Data::EIdentifier(id) => p.symbols[id.ref_.inner_index() as usize]
                        .original_name
                        .slice(),
                    Data::EImportIdentifier(id) => p.symbols[id.ref_.inner_index() as usize]
                        .original_name
                        .slice(),
                    Data::ECommonjsExportIdentifier(id) => p.symbols
                        [id.ref_.inner_index() as usize]
                        .original_name
                        .slice(),
                    Data::EDot(dot) => dot.name.slice(),
                    _ => break 'try_record_hook,
                };
                if !ReactRefresh::is_hook_name(original_name) {
                    break 'try_record_hook;
                }
                if p.options.features.react_fast_refresh {
                    p.handle_react_refresh_hook_call(&mut *e_, original_name);
                } else if
                // If we're here it means we're in server component.
                // Error if the user is using the `useState` hook as it
                // is disallowed in server components.
                //
                // We're also specifically checking that the target is
                // `.e_import_identifier`.
                //
                // Why? Because we *don't* want to check for uses of
                // `useState` _inside_ React, and we know React uses
                // commonjs so it will never be `.e_import_identifier`.
                'check_for_usestate: {
                    if matches!(e_.target.data, Data::EImportIdentifier(..)) {
                        break 'check_for_usestate true;
                    }
                    // Also check for `React.useState(...)`
                    if let Data::EDot(dot) = &e_.target.data {
                        if let Data::EImportIdentifier(id) = &dot.target.data {
                            let name = p.symbols[id.ref_.inner_index() as usize]
                                .original_name
                                .slice();
                            break 'check_for_usestate name == b"React";
                        }
                    }
                    break 'check_for_usestate false;
                } {
                    debug_assert!(p.options.features.server_components.is_server_side());
                    if !strings::starts_with(p.source.path.pretty, b"node_modules")
                        && original_name == b"useState"
                    {
                        p.log()
                            .add_error(
                                Some(p.source),
                                expr.loc,
                                b"\"useState\" is not available in a server component. If you need interactivity, consider converting part of this to a Client Component (by adding `\"use client\";` to the top of the file).",
                            );
                    }
                }
            }
        }

        // Implement constant folding for 'string'.charCodeAt(n)
        if e_.args.len_u32() == 1 {
            if let Some(dot) = e_.target.data.e_dot() {
                if let Some(target_str) = dot.target.data.e_string() {
                    if !target_str.is_utf16 && dot.name == b"charCodeAt" {
                        let str_ = target_str.data;
                        let arg1 = e_.args.at(0).unwrap_inlined();
                        if let Data::ENumber(n) = &arg1.data {
                            let float = n.value;
                            if float % 1.0 == 0.0 && float < (str_.len() as f64) && float >= 0.0 {
                                let char_ = str_[float as usize];
                                if char_ < 0x80 {
                                    *e = p.new_expr(
                                        E::Number {
                                            value: f64::from(char_),
                                        },
                                        expr.loc,
                                    );
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    #[inline(never)] // PERF(port:frame): see e_jsx_element.
    fn e_new(p: &mut Self, e: &mut Expr, _: ExprIn) {
        let expr = *e;
        let mut e_ = expr.data.e_new().expect("infallible: variant checked");
        p.visit_expr(&mut e_.target);

        for arg in e_.args.slice_mut() {
            p.visit_expr(arg);
        }

        if p.options.features.minify_syntax {
            if let Some(minified) = js_ast::known_global::KnownGlobal::minify_global_constructor(
                p.arena,
                &mut *e_,
                &p.symbols,
                expr.loc,
                p.options.features.minify_whitespace,
            ) {
                *e = minified;
                return;
            }
        }
    }

    /// Note: Caller must check `p.bundler_feature_flag_ref.is_valid()` before calling.
    fn maybe_replace_bundler_feature_call(
        p: &mut Self,
        e_: &mut E::Call,
        loc: bun_ast::Loc,
    ) -> Option<Expr> {
        // Check if the target is the `feature` function from "bun:bundle"
        // It could be e_identifier (for unbound) or e_import_identifier (for imports)
        let target_ref: Option<Ref> = match &e_.target.data {
            Data::EIdentifier(ident) => Some(ident.ref_),
            Data::EImportIdentifier(ident) => Some(ident.ref_),
            _ => None,
        };

        if target_ref.is_none() || !target_ref.unwrap().eql(p.bundler_feature_flag_ref) {
            return None;
        }

        // If control flow is dead, just return false without validation errors
        if p.is_control_flow_dead {
            return Some(p.new_expr(E::Boolean { value: false }, loc));
        }

        // Validate: exactly one argument required
        if e_.args.len_u32() != 1 {
            p.log().add_error(
                Some(p.source),
                loc,
                b"feature() requires exactly one string argument",
            );
            return Some(p.new_expr(E::Boolean { value: false }, loc));
        }

        let arg = e_.args.slice()[0];

        // Validate: argument must be a string literal
        if !matches!(arg.data, Data::EString(..)) {
            p.log().add_error(
                Some(p.source),
                arg.loc,
                b"feature() argument must be a string literal",
            );
            return Some(p.new_expr(E::Boolean { value: false }, loc));
        }

        // Check if the feature flag is enabled
        // Use the underlying string data directly without allocation.
        // Feature flag names should be ASCII identifiers, so UTF-16 is unexpected.
        let flag_string = arg.data.e_string().expect("infallible: variant checked");
        if flag_string.is_utf16 {
            p.log().add_error(
                Some(p.source),
                arg.loc,
                b"feature() flag name must be an ASCII string",
            );
            return Some(p.new_expr(E::Boolean { value: false }, loc));
        }

        // feature() can only be used directly in an if statement or ternary condition
        if !p.in_branch_condition {
            p.log()
                .add_error(
                    Some(p.source),
                    loc,
                    b"feature() from \"bun:bundle\" can only be used directly in an if statement or ternary condition",
                );
            return Some(p.new_expr(E::Boolean { value: false }, loc));
        }

        let is_enabled: bool = p
            .options
            .features
            .bundler_feature_flags
            .as_ref()
            .is_some_and(|flags| flags.contains(&flag_string.data));
        Some(Expr {
            data: Data::EBranchBoolean(E::Boolean { value: is_enabled }),
            loc,
        })
    }
    #[inline(never)] // PERF(port:frame): see e_jsx_element.
    fn e_arrow(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        let _ = in_;
        let mut e_ = expr.data.e_arrow().expect("infallible: variant checked");
        if p.is_revisit_for_substitution {
            return;
        }

        // Zig: `std.mem.toBytes(...)` then `bytesToValue(...)` to save/restore. In Rust the struct
        // is `Copy`/`Clone`, so just copy it.
        // PORT NOTE: reshaped — toBytes/bytesToValue → plain copy.
        let old_fn_or_arrow_data = p.fn_or_arrow_data_visit;
        p.fn_or_arrow_data_visit = FnOrArrowDataVisit {
            is_arrow: true,
            is_async: e_.is_async,
            ..Default::default()
        };

        // Mark if we're inside an async arrow function. This value should be true
        // even if we're inside multiple arrow functions and the closest inclosing
        // arrow function isn't async, as long as at least one enclosing arrow
        // function within the current enclosing function is async.
        let old_inside_async_arrow_fn = p.fn_only_data_visit.is_inside_async_arrow_fn;
        p.fn_only_data_visit.is_inside_async_arrow_fn =
            e_.is_async || p.fn_only_data_visit.is_inside_async_arrow_fn;

        p.push_scope_for_visit_pass(js_ast::scope::Kind::FunctionArgs, expr.loc)
            .expect("unreachable");
        // PERF(port): was arena dupe — profile if it shows up on a hot path
        let dupe: &'a mut [Stmt] = p.arena.alloc_slice_copy(e_.body.stmts.slice());

        let args_mut: &mut [G::Arg] = e_.args.slice_mut();
        p.visit_args(
            args_mut,
            &VisitArgsOpts {
                has_rest_arg: e_.has_rest_arg,
                body: dupe,
                is_unique_formal_parameters: true,
            },
        );
        p.push_scope_for_visit_pass(js_ast::scope::Kind::FunctionBody, e_.body.loc)
            .expect("unreachable");

        // Zig: `const prev = p.react_refresh.hook_ctx_storage; defer ... = prev; ... = &react_hook_data;`
        // hook_ctx_storage is a raw NonNull so a stack local is fine; we manually restore `prev`
        // on every exit path below (Zig used `defer`).
        let mut react_hook_data: Option<crate::parser::HookContext> = None;
        let prev_hook_ctx = p.react_refresh.hook_ctx_storage;
        p.react_refresh.hook_ctx_storage = Some(core::ptr::NonNull::from(&mut react_hook_data));

        // TODO(port): Zig `ListManaged(Stmt).fromOwnedSlice(p.arena, dupe)` takes ownership of
        // the arena slice without copying. bumpalo Vec cannot adopt an existing slice; a custom
        // arena Vec that can would avoid this copy. Left as a copy with PERF note.
        // PERF(port): was fromOwnedSlice (no copy) — profile if it shows up on a hot path
        let mut stmts_list = bun_alloc::vec_from_iter_in(dupe.iter().copied(), p.arena);
        let mut temp_opts = PrependTempRefsOpts {
            kind: crate::parser::StmtsKind::FnBody,
            ..Default::default()
        };
        p.visit_stmts_and_prepend_temp_refs(&mut stmts_list, &mut temp_opts)
            .expect("unreachable");
        // Zig: `p.arena.free(e_.body.stmts)` — arena-backed, no individual free in Rust.
        p.pop_scope();
        p.pop_scope();

        p.fn_only_data_visit.is_inside_async_arrow_fn = old_inside_async_arrow_fn;
        p.fn_or_arrow_data_visit = old_fn_or_arrow_data;

        // Zig: defer p.react_refresh.hook_ctx_storage = prev — restore before any further `p.*`
        // call so the stack-local pointer never escapes this frame.
        p.react_refresh.hook_ctx_storage = prev_hook_ctx;

        if let Some(hook) = react_hook_data.as_mut() {
            'try_mark_hook: {
                if p.nearest_stmt_list.is_none() {
                    break 'try_mark_hook;
                }
                let decl = p.get_react_refresh_hook_signal_decl(hook.signature_cb);
                p.nearest_stmt_list_mut().unwrap().push(decl);

                p.handle_react_refresh_post_visit_function_body(&mut stmts_list, hook);
                e_.body.stmts = bun_ast::StoreSlice::new_mut(stmts_list.into_bump_slice_mut());

                *e = p.get_react_refresh_hook_signal_init(hook, expr);
                return;
            }
        }
        e_.body.stmts = bun_ast::StoreSlice::new_mut(stmts_list.into_bump_slice_mut());
    }
    #[inline(never)] // PERF(port:frame): see e_jsx_element.
    fn e_function(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        let _ = in_;
        let mut e_ = expr.data.e_function().expect("infallible: variant checked");
        if p.is_revisit_for_substitution {
            return;
        }

        // Zig: `const prev = p.react_refresh.hook_ctx_storage; defer ... = prev; ... = &react_hook_data;`
        let mut react_hook_data: Option<crate::parser::HookContext> = None;
        let prev_hook_ctx = p.react_refresh.hook_ctx_storage;
        p.react_refresh.hook_ctx_storage = Some(core::ptr::NonNull::from(&mut react_hook_data));

        // Spec (visitExpr.zig e_function): visitFunc(e_.func, expr.loc) — for function
        // *expressions* the .function_args scope is pushed at the `function` keyword loc
        // (parseFn.zig:364), not at open_parens_loc. (s_function correctly uses open_parens_loc.)
        e_.func = p.visit_func(core::mem::take(&mut e_.func), expr.loc);

        // Zig: defer p.react_refresh.hook_ctx_storage = prev — restore now so the stack-local
        // pointer never escapes this frame.
        p.react_refresh.hook_ctx_storage = prev_hook_ctx;

        // Remove unused function names when minifying (only when bundling is enabled)
        // unless --keep-names is specified
        if p.options.features.minify_syntax
            && p.options.bundle
            && !p.options.features.minify_keep_names
            // SAFETY: current_scope is a live arena ptr while the parser exists.
            && !p.current_scope().contains_direct_eval
            && e_.func.name.is_some()
            && e_.func.name.unwrap().ref_.is_some()
            && p.symbols[e_.func.name.unwrap().ref_.expect("infallible: ref bound").inner_index() as usize]
                .use_count_estimate
                == 0
        {
            e_.func.name = None;
        }

        let mut final_expr = expr;
        let mut replaced = false;

        if let Some(hook) = react_hook_data.as_mut() {
            'try_mark_hook: {
                if p.nearest_stmt_list.is_none() {
                    break 'try_mark_hook;
                }
                let decl = p.get_react_refresh_hook_signal_decl(hook.signature_cb);
                p.nearest_stmt_list_mut().unwrap().push(decl);
                final_expr = p.get_react_refresh_hook_signal_init(hook, expr);
                replaced = true;
            }
        }

        if let Some(name) = e_.func.name {
            final_expr = p.keep_expr_symbol_name(
                final_expr,
                // SAFETY: original_name is arena-owned, valid for 'a.
                p.symbols[name.ref_.expect("infallible: ref bound").inner_index() as usize]
                    .original_name
                    .slice(),
            );
            replaced = true;
        }

        // Only write back through &mut when one of the wrapping branches fired; on the
        // common fall-through `final_expr` is the entry snapshot and the 24B store is dead.
        if replaced {
            *e = final_expr;
        }
    }
    #[inline(never)] // PERF(port:frame): see e_jsx_element.
    fn e_class(p: &mut Self, e: &mut Expr, in_: ExprIn) {
        let expr = *e;
        let _ = in_;
        let mut e_ = expr.data.e_class().expect("infallible: variant checked");
        if p.is_revisit_for_substitution {
            return;
        }

        // Save name from assignment context before visiting (nested visits may overwrite it)
        let decorator_name_from_context = p.decorator_class_name;
        p.decorator_class_name = None;

        // Zig: `p.visitClass(expr.loc, e_, Ref.None)`
        let _ = p.visit_class(expr.loc, &mut e_, Ref::NONE);

        // Lower standard decorators for class expressions
        if e_.should_lower_standard_decorators {
            *e = p.lower_standard_decorators_expr(&mut e_, expr.loc, decorator_name_from_context);
            return;
        }

        // Remove unused class names when minifying (only when bundling is enabled)
        // unless --keep-names is specified
        if p.options.features.minify_syntax
            && p.options.bundle
            && !p.options.features.minify_keep_names
            // SAFETY: current_scope is a live arena ptr while the parser exists.
            && !p.current_scope().contains_direct_eval
            && e_.class_name.is_some()
            && e_.class_name.unwrap().ref_.is_some()
            && p.symbols[e_.class_name.unwrap().ref_.expect("infallible: ref bound").inner_index() as usize]
                .use_count_estimate
                == 0
        {
            e_.class_name = None;
        }
    }
}