Source file flow_ast_mapper.ml
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
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
module Ast = Flow_ast
let map_opt : 'node. ('node -> 'node) -> 'node option -> 'node option =
fun map opt ->
match opt with
| Some item ->
let item' = map item in
if item == item' then
opt
else
Some item'
| None -> opt
let id_loc : 'node 'a. ('loc -> 'node -> 'node) -> 'loc -> 'node -> 'a -> ('node -> 'a) -> 'a =
fun map loc item same diff ->
let item' = map loc item in
if item == item' then
same
else
diff item'
let id : 'node 'a. ('node -> 'node) -> 'node -> 'a -> ('node -> 'a) -> 'a =
fun map item same diff ->
let item' = map item in
if item == item' then
same
else
diff item'
let map_loc : 'node. ('loc -> 'node -> 'node) -> 'loc * 'node -> 'loc * 'node =
fun map same ->
let (loc, item) = same in
id_loc map loc item same (fun diff -> (loc, diff))
let map_loc_opt : 'node. ('loc -> 'node -> 'node) -> ('loc * 'node) option -> ('loc * 'node) option
=
fun map same ->
map_opt
(fun same ->
let (loc, item) = same in
id_loc map loc item same (fun diff -> (loc, diff)))
same
let map_list map lst =
let (rev_lst, changed) =
List.fold_left
(fun (lst', changed) item ->
let item' = map item in
(item' :: lst', changed || item' != item))
([], false)
lst
in
if changed then
List.rev rev_lst
else
lst
let map_list_multiple map lst =
let (rev_lst, changed) =
List.fold_left
(fun (lst', changed) item ->
match map item with
| [] -> (lst', true)
| [item'] -> (item' :: lst', changed || item != item')
| items' -> (List.rev_append items' lst', true))
([], false)
lst
in
if changed then
List.rev rev_lst
else
lst
class ['loc] mapper =
object (this)
method program (program : ('loc, 'loc) Ast.Program.t) =
let open Ast.Program in
let (loc, { statements; interpreter; ; }) = program in
let statements' = this#toplevel_statement_list statements in
let = this#syntax_opt comments in
let = map_list this#comment all_comments in
if statements == statements' && comments == comments' && all_comments == all_comments' then
program
else
( loc,
{
statements = statements';
interpreter;
comments = comments';
all_comments = all_comments';
}
)
method statement (stmt : ('loc, 'loc) Ast.Statement.t) =
let open Ast.Statement in
match stmt with
| (loc, Block block) -> id_loc this#block loc block stmt (fun block -> (loc, Block block))
| (loc, Break break) -> id_loc this#break loc break stmt (fun break -> (loc, Break break))
| (loc, ClassDeclaration cls) ->
id_loc this#class_declaration loc cls stmt (fun cls -> (loc, ClassDeclaration cls))
| (loc, ComponentDeclaration component) ->
id_loc this#component_declaration loc component stmt (fun component ->
(loc, ComponentDeclaration component)
)
| (loc, Continue cont) -> id_loc this#continue loc cont stmt (fun cont -> (loc, Continue cont))
| (loc, Debugger dbg) -> id_loc this#debugger loc dbg stmt (fun dbg -> (loc, Debugger dbg))
| (loc, DeclareClass stuff) ->
id_loc this#declare_class loc stuff stmt (fun stuff -> (loc, DeclareClass stuff))
| (loc, DeclareComponent stuff) ->
id_loc this#declare_component loc stuff stmt (fun stuff -> (loc, DeclareComponent stuff))
| (loc, DeclareEnum enum) ->
id_loc this#declare_enum loc enum stmt (fun enum -> (loc, DeclareEnum enum))
| (loc, DeclareExportDeclaration decl) ->
id_loc this#declare_export_declaration loc decl stmt (fun decl ->
(loc, DeclareExportDeclaration decl)
)
| (loc, DeclareFunction stuff) ->
id_loc this#declare_function loc stuff stmt (fun stuff -> (loc, DeclareFunction stuff))
| (loc, DeclareInterface stuff) ->
id_loc this#declare_interface loc stuff stmt (fun stuff -> (loc, DeclareInterface stuff))
| (loc, DeclareModule m) ->
id_loc this#declare_module loc m stmt (fun m -> (loc, DeclareModule m))
| (loc, DeclareModuleExports annot) ->
id_loc this#declare_module_exports loc annot stmt (fun annot ->
(loc, DeclareModuleExports annot)
)
| (loc, DeclareOpaqueType otype) ->
id_loc this#opaque_type loc otype stmt (fun otype -> (loc, DeclareOpaqueType otype))
| (loc, DeclareTypeAlias stuff) ->
id_loc this#declare_type_alias loc stuff stmt (fun stuff -> (loc, DeclareTypeAlias stuff))
| (loc, DeclareVariable stuff) ->
id_loc this#declare_variable loc stuff stmt (fun stuff -> (loc, DeclareVariable stuff))
| (loc, DoWhile stuff) ->
id_loc this#do_while loc stuff stmt (fun stuff -> (loc, DoWhile stuff))
| (loc, Empty empty) -> id_loc this#empty loc empty stmt (fun empty -> (loc, Empty empty))
| (loc, EnumDeclaration enum) ->
id_loc this#enum_declaration loc enum stmt (fun enum -> (loc, EnumDeclaration enum))
| (loc, ExportDefaultDeclaration decl) ->
id_loc this#export_default_declaration loc decl stmt (fun decl ->
(loc, ExportDefaultDeclaration decl)
)
| (loc, ExportNamedDeclaration decl) ->
id_loc this#export_named_declaration loc decl stmt (fun decl ->
(loc, ExportNamedDeclaration decl)
)
| (loc, Expression expr) ->
id_loc this#expression_statement loc expr stmt (fun expr -> (loc, Expression expr))
| (loc, For for_stmt) ->
id_loc this#for_statement loc for_stmt stmt (fun for_stmt -> (loc, For for_stmt))
| (loc, ForIn stuff) ->
id_loc this#for_in_statement loc stuff stmt (fun stuff -> (loc, ForIn stuff))
| (loc, ForOf stuff) ->
id_loc this#for_of_statement loc stuff stmt (fun stuff -> (loc, ForOf stuff))
| (loc, FunctionDeclaration func) ->
id_loc this#function_declaration loc func stmt (fun func -> (loc, FunctionDeclaration func))
| (loc, If if_stmt) ->
id_loc this#if_statement loc if_stmt stmt (fun if_stmt -> (loc, If if_stmt))
| (loc, ImportDeclaration decl) ->
id_loc this#import_declaration loc decl stmt (fun decl -> (loc, ImportDeclaration decl))
| (loc, InterfaceDeclaration stuff) ->
id_loc this#interface_declaration loc stuff stmt (fun stuff ->
(loc, InterfaceDeclaration stuff)
)
| (loc, Labeled label) ->
id_loc this#labeled_statement loc label stmt (fun label -> (loc, Labeled label))
| (loc, OpaqueType otype) ->
id_loc this#opaque_type loc otype stmt (fun otype -> (loc, OpaqueType otype))
| (loc, Return ret) -> id_loc this#return loc ret stmt (fun ret -> (loc, Return ret))
| (loc, Switch switch) ->
id_loc this#switch loc switch stmt (fun switch -> (loc, Switch switch))
| (loc, Throw throw) -> id_loc this#throw loc throw stmt (fun throw -> (loc, Throw throw))
| (loc, Try try_stmt) ->
id_loc this#try_catch loc try_stmt stmt (fun try_stmt -> (loc, Try try_stmt))
| (loc, VariableDeclaration decl) ->
id_loc this#variable_declaration loc decl stmt (fun decl -> (loc, VariableDeclaration decl))
| (loc, While stuff) -> id_loc this#while_ loc stuff stmt (fun stuff -> (loc, While stuff))
| (loc, With stuff) -> id_loc this#with_ loc stuff stmt (fun stuff -> (loc, With stuff))
| (loc, TypeAlias stuff) ->
id_loc this#type_alias loc stuff stmt (fun stuff -> (loc, TypeAlias stuff))
method comment (c : 'loc Ast.Comment.t) = c
method syntax_opt
: 'internal. ('loc, 'internal) Ast.Syntax.t option -> ('loc, 'internal) Ast.Syntax.t option
=
map_opt this#syntax
method syntax : 'internal. ('loc, 'internal) Ast.Syntax.t -> ('loc, 'internal) Ast.Syntax.t =
fun attached ->
let open Ast.Syntax in
let { leading; trailing; internal } = attached in
let leading' = map_list this#comment leading in
let trailing' = map_list this#comment trailing in
if leading == leading' && trailing == trailing' then
attached
else
{ leading = leading'; trailing = trailing'; internal }
method expression (expr : ('loc, 'loc) Ast.Expression.t) =
let open Ast.Expression in
match expr with
| (loc, Array x) -> id_loc this#array loc x expr (fun x -> (loc, Array x))
| (loc, ArrowFunction x) ->
id_loc this#arrow_function loc x expr (fun x -> (loc, ArrowFunction x))
| (loc, AsExpression x) ->
id_loc this#as_expression loc x expr (fun x -> (loc, AsExpression x))
| (loc, Assignment x) -> id_loc this#assignment loc x expr (fun x -> (loc, Assignment x))
| (loc, Binary x) -> id_loc this#binary loc x expr (fun x -> (loc, Binary x))
| (loc, Call x) -> id_loc this#call loc x expr (fun x -> (loc, Call x))
| (loc, Class x) -> id_loc this#class_expression loc x expr (fun x -> (loc, Class x))
| (loc, Conditional x) -> id_loc this#conditional loc x expr (fun x -> (loc, Conditional x))
| (loc, Function x) -> id_loc this#function_expression loc x expr (fun x -> (loc, Function x))
| (loc, Identifier x) -> id this#identifier x expr (fun x -> (loc, Identifier x))
| (loc, Import x) -> id (this#import loc) x expr (fun x -> (loc, Import x))
| (loc, JSXElement x) -> id_loc this#jsx_element loc x expr (fun x -> (loc, JSXElement x))
| (loc, JSXFragment x) -> id_loc this#jsx_fragment loc x expr (fun x -> (loc, JSXFragment x))
| (loc, StringLiteral x) ->
id_loc this#string_literal loc x expr (fun x -> (loc, StringLiteral x))
| (loc, BooleanLiteral x) ->
id_loc this#boolean_literal loc x expr (fun x -> (loc, BooleanLiteral x))
| (loc, NullLiteral x) -> id_loc this#null_literal loc x expr (fun x -> (loc, NullLiteral x))
| (loc, NumberLiteral x) ->
id_loc this#number_literal loc x expr (fun x -> (loc, NumberLiteral x))
| (loc, BigIntLiteral x) ->
id_loc this#bigint_literal loc x expr (fun x -> (loc, BigIntLiteral x))
| (loc, RegExpLiteral x) ->
id_loc this#regexp_literal loc x expr (fun x -> (loc, RegExpLiteral x))
| (loc, ModuleRefLiteral x) ->
id_loc this#module_ref_literal loc x expr (fun x -> (loc, ModuleRefLiteral x))
| (loc, Logical x) -> id_loc this#logical loc x expr (fun x -> (loc, Logical x))
| (loc, Member x) -> id_loc this#member loc x expr (fun x -> (loc, Member x))
| (loc, MetaProperty x) ->
id_loc this#meta_property loc x expr (fun x -> (loc, MetaProperty x))
| (loc, New x) -> id_loc this#new_ loc x expr (fun x -> (loc, New x))
| (loc, Object x) -> id_loc this#object_ loc x expr (fun x -> (loc, Object x))
| (loc, OptionalCall x) -> id (this#optional_call loc) x expr (fun x -> (loc, OptionalCall x))
| (loc, OptionalMember x) ->
id_loc this#optional_member loc x expr (fun x -> (loc, OptionalMember x))
| (loc, Sequence x) -> id_loc this#sequence loc x expr (fun x -> (loc, Sequence x))
| (loc, Super x) -> id_loc this#super_expression loc x expr (fun x -> (loc, Super x))
| (loc, TaggedTemplate x) ->
id_loc this#tagged_template loc x expr (fun x -> (loc, TaggedTemplate x))
| (loc, TemplateLiteral x) ->
id_loc this#template_literal loc x expr (fun x -> (loc, TemplateLiteral x))
| (loc, This x) -> id_loc this#this_expression loc x expr (fun x -> (loc, This x))
| (loc, TypeCast x) -> id_loc this#type_cast loc x expr (fun x -> (loc, TypeCast x))
| (loc, TSTypeCast x) -> id_loc this#ts_type_cast loc x expr (fun x -> (loc, TSTypeCast x))
| (loc, Unary x) -> id_loc this#unary_expression loc x expr (fun x -> (loc, Unary x))
| (loc, Update x) -> id_loc this#update_expression loc x expr (fun x -> (loc, Update x))
| (loc, Yield x) -> id_loc this#yield loc x expr (fun x -> (loc, Yield x))
method array _loc (expr : ('loc, 'loc) Ast.Expression.Array.t) =
let open Ast.Expression in
let { Array.elements; } = expr in
let elements' = map_list this#array_element elements in
let = this#syntax_opt comments in
if elements == elements' && comments == comments' then
expr
else
{ Array.elements = elements'; comments = comments' }
method array_element element =
let open Ast.Expression.Array in
match element with
| Expression expr -> id this#expression expr element (fun expr -> Expression expr)
| Spread spread -> id this#spread_element spread element (fun spread -> Spread spread)
| Hole _ -> element
method arrow_function loc (expr : ('loc, 'loc) Ast.Function.t) = this#function_ loc expr
method as_expression _loc (expr : ('loc, 'loc) Ast.Expression.AsExpression.t) =
let open Ast.Expression.AsExpression in
let { expression; annot; } = expr in
let expression' = this#expression expression in
let annot' = this#type_annotation annot in
let = this#syntax_opt comments in
if expression' == expression && annot' == annot && comments' == comments then
expr
else
{ expression = expression'; annot = annot'; comments = comments' }
method assignment _loc (expr : ('loc, 'loc) Ast.Expression.Assignment.t) =
let open Ast.Expression.Assignment in
let { operator = _; left; right; } = expr in
let left' = this#assignment_pattern left in
let right' = this#expression right in
let = this#syntax_opt comments in
if left == left' && right == right' && comments == comments' then
expr
else
{ expr with left = left'; right = right'; comments = comments' }
method binary _loc (expr : ('loc, 'loc) Ast.Expression.Binary.t) =
let open Ast.Expression.Binary in
let { operator = _; left; right; } = expr in
let left' = this#expression left in
let right' = this#expression right in
let = this#syntax_opt comments in
if left == left' && right == right' && comments == comments' then
expr
else
{ expr with left = left'; right = right'; comments = comments' }
method block _loc (stmt : ('loc, 'loc) Ast.Statement.Block.t) =
let open Ast.Statement.Block in
let { body; } = stmt in
let body' = this#statement_list body in
let = this#syntax_opt comments in
if body == body' && comments == comments' then
stmt
else
{ body = body'; comments = comments' }
method break _loc (break : 'loc Ast.Statement.Break.t) =
let open Ast.Statement.Break in
let { label; } = break in
let label' = map_opt this#label_identifier label in
let = this#syntax_opt comments in
if label == label' && comments == comments' then
break
else
{ label = label'; comments = comments' }
method call _loc (expr : ('loc, 'loc) Ast.Expression.Call.t) =
let open Ast.Expression.Call in
let { callee; targs; arguments; } = expr in
let callee' = this#expression callee in
let targs' = map_opt this#call_type_args targs in
let arguments' = this#arg_list arguments in
let = this#syntax_opt comments in
if callee == callee' && targs == targs' && arguments == arguments' && comments == comments'
then
expr
else
{ callee = callee'; targs = targs'; arguments = arguments'; comments = comments' }
method arg_list (arg_list : ('loc, 'loc) Ast.Expression.ArgList.t) =
let open Ast.Expression.ArgList in
let (loc, { arguments; }) = arg_list in
let arguments' = map_list this#expression_or_spread arguments in
let = this#syntax_opt comments in
if arguments == arguments' && comments == comments' then
arg_list
else
(loc, { arguments = arguments'; comments = comments' })
method optional_call loc (expr : ('loc, 'loc) Ast.Expression.OptionalCall.t) =
let open Ast.Expression.OptionalCall in
let { call; optional = _; filtered_out = _ } = expr in
let call' = this#call loc call in
if call == call' then
expr
else
{ expr with call = call' }
method call_type_args (targs : ('loc, 'loc) Ast.Expression.CallTypeArgs.t) =
let open Ast.Expression.CallTypeArgs in
let (loc, { arguments; }) = targs in
let arguments' = map_list this#call_type_arg arguments in
let = this#syntax_opt comments in
if arguments == arguments' && comments == comments' then
targs
else
(loc, { arguments = arguments'; comments = comments' })
method call_type_arg t =
let open Ast.Expression.CallTypeArg in
match t with
| Explicit x ->
let x' = this#type_ x in
if x' == x then
t
else
Explicit x'
| Implicit (loc, { }) ->
let = this#syntax_opt comments in
if comments == comments' then
t
else
Implicit (loc, { Implicit.comments = comments' })
method catch_body (body : 'loc * ('loc, 'loc) Ast.Statement.Block.t) = map_loc this#block body
method catch_clause _loc (clause : ('loc, 'loc) Ast.Statement.Try.CatchClause.t') =
let open Ast.Statement.Try.CatchClause in
let { param; body; } = clause in
let param' = map_opt this#catch_clause_pattern param in
let body' = this#catch_body body in
let = this#syntax_opt comments in
if param == param' && body == body' && comments == comments' then
clause
else
{ param = param'; body = body'; comments = comments' }
method class_declaration loc (cls : ('loc, 'loc) Ast.Class.t) = this#class_ loc cls
method class_expression loc (cls : ('loc, 'loc) Ast.Class.t) = this#class_ loc cls
method class_ _loc (cls : ('loc, 'loc) Ast.Class.t) =
let open Ast.Class in
let { id; body; tparams; extends; implements; class_decorators; } = cls in
let id' = map_opt this#class_identifier id in
let tparams' = map_opt this#type_params tparams in
let body' = this#class_body body in
let extends' = map_opt (map_loc this#class_extends) extends in
let implements' = map_opt this#class_implements implements in
let class_decorators' = map_list this#class_decorator class_decorators in
let = this#syntax_opt comments in
if
id == id'
&& body == body'
&& extends == extends'
&& implements == implements'
&& class_decorators == class_decorators'
&& comments == comments'
&& tparams == tparams'
then
cls
else
{
id = id';
body = body';
extends = extends';
implements = implements';
class_decorators = class_decorators';
comments = comments';
tparams = tparams';
}
method class_extends _loc (extends : ('loc, 'loc) Ast.Class.Extends.t') =
let open Ast.Class.Extends in
let { expr; targs; } = extends in
let expr' = this#expression expr in
let targs' = map_opt this#type_args targs in
let = this#syntax_opt comments in
if expr == expr' && targs == targs' && comments == comments' then
extends
else
{ expr = expr'; targs = targs'; comments = comments' }
method class_identifier (ident : ('loc, 'loc) Ast.Identifier.t) =
this#pattern_identifier ~kind:Ast.Variable.Let ident
method class_body (cls_body : ('loc, 'loc) Ast.Class.Body.t) =
let open Ast.Class.Body in
let (loc, { body; }) = cls_body in
let body' = map_list this#class_element body in
let = this#syntax_opt comments in
if body == body' && comments == comments' then
cls_body
else
(loc, { body = body'; comments = comments' })
method class_decorator (dec : ('loc, 'loc) Ast.Class.Decorator.t) =
let open Ast.Class.Decorator in
let (loc, { expression; }) = dec in
let expression' = this#expression expression in
let = this#syntax_opt comments in
if expression == expression' && comments == comments' then
dec
else
(loc, { expression = expression'; comments = comments' })
method class_element (elem : ('loc, 'loc) Ast.Class.Body.element) =
let open Ast.Class.Body in
match elem with
| Method (loc, meth) -> id_loc this#class_method loc meth elem (fun meth -> Method (loc, meth))
| Property (loc, prop) ->
id_loc this#class_property loc prop elem (fun prop -> Property (loc, prop))
| PrivateField (loc, field) ->
id_loc this#class_private_field loc field elem (fun field -> PrivateField (loc, field))
method class_implements (implements : ('loc, 'loc) Ast.Class.Implements.t) =
let open Ast.Class.Implements in
let (loc, { interfaces; }) = implements in
let interfaces' = map_list this#class_implements_interface interfaces in
let = this#syntax_opt comments in
if interfaces == interfaces' && comments == comments' then
implements
else
(loc, { interfaces = interfaces'; comments = comments' })
method class_implements_interface (interface : ('loc, 'loc) Ast.Class.Implements.Interface.t) =
let open Ast.Class.Implements.Interface in
let (loc, { id; targs }) = interface in
let id' = this#type_identifier_reference id in
let targs' = map_opt this#type_args targs in
if id == id' && targs == targs' then
interface
else
(loc, { id = id'; targs = targs' })
method class_method _loc (meth : ('loc, 'loc) Ast.Class.Method.t') =
let open Ast.Class.Method in
let { kind = _; key; value; static = _; decorators; } = meth in
let key' = this#object_key key in
let value' = map_loc this#function_expression_or_method value in
let decorators' = map_list this#class_decorator decorators in
let = this#syntax_opt comments in
if key == key' && value == value' && decorators == decorators' && comments == comments' then
meth
else
{ meth with key = key'; value = value'; decorators = decorators'; comments = comments' }
method class_property _loc (prop : ('loc, 'loc) Ast.Class.Property.t') =
let open Ast.Class.Property in
let { key; value; annot; static = _; variance; decorators; } = prop in
let key' = this#object_key key in
let value' = this#class_property_value value in
let annot' = this#type_annotation_hint annot in
let variance' = this#variance_opt variance in
let decorators' = map_list this#class_decorator decorators in
let = this#syntax_opt comments in
if
key == key'
&& value == value'
&& annot' == annot
&& variance' == variance
&& decorators' == decorators
&& comments' == comments
then
prop
else
{
prop with
key = key';
value = value';
annot = annot';
variance = variance';
decorators = decorators';
comments = comments';
}
method class_property_value (value : ('loc, 'loc) Ast.Class.Property.value) =
let open Ast.Class.Property in
match value with
| Declared -> value
| Uninitialized -> value
| Initialized x ->
let x' = this#expression x in
if x == x' then
value
else
Initialized x'
method class_private_field _loc (prop : ('loc, 'loc) Ast.Class.PrivateField.t') =
let open Ast.Class.PrivateField in
let { key; value; annot; static = _; variance; decorators; } = prop in
let key' = this#private_name key in
let value' = this#class_property_value value in
let annot' = this#type_annotation_hint annot in
let variance' = this#variance_opt variance in
let decorators' = map_list this#class_decorator decorators in
let = this#syntax_opt comments in
if
key == key'
&& value == value'
&& annot' == annot
&& variance' == variance
&& decorators' == decorators
&& comments' == comments
then
prop
else
{
prop with
key = key';
value = value';
annot = annot';
variance = variance';
decorators = decorators';
comments = comments';
}
method default_opt (default : ('loc, 'loc) Ast.Expression.t option) =
map_opt this#expression default
method component_declaration _loc (component : ('loc, 'loc) Ast.Statement.ComponentDeclaration.t)
=
let open Ast.Statement.ComponentDeclaration in
let { id = ident; tparams; params; body; renders; ; sig_loc } = component in
let ident' = this#component_identifier ident in
let tparams' = map_opt this#type_params tparams in
let params' = this#component_params params in
let body' = this#component_body body in
let renders' = this#component_renders_annotation renders in
let = this#syntax_opt comments in
if
ident == ident'
&& tparams == tparams'
&& params == params'
&& body == body'
&& renders == renders'
&& comments == comments'
then
component
else
{
id = ident';
tparams = tparams';
params = params';
body = body';
renders = renders';
comments = comments';
sig_loc;
}
method component_identifier (ident : ('loc, 'loc) Ast.Identifier.t) =
this#pattern_identifier ~kind:Ast.Variable.Var ident
method component_params (params : ('loc, 'loc) Ast.Statement.ComponentDeclaration.Params.t) =
let open Ast.Statement.ComponentDeclaration in
let (loc, { Params.params = params_list; rest; }) = params in
let params_list' = map_list this#component_param params_list in
let rest' = map_opt this#component_rest_param rest in
let = this#syntax_opt comments in
if params_list == params_list' && rest == rest' && comments == comments' then
params
else
(loc, { Params.params = params_list'; rest = rest'; comments = comments' })
method component_param (param : ('loc, 'loc) Ast.Statement.ComponentDeclaration.Param.t) =
let open Ast.Statement.ComponentDeclaration.Param in
let (loc, { name; local; default; shorthand }) = param in
let name' = this#component_param_name name in
let local' = this#component_param_pattern local in
let default' = this#default_opt default in
if name == name' && local == local' && default == default' then
param
else
(loc, { name = name'; local = local'; default = default'; shorthand })
method component_param_name
(param_name : ('loc, 'loc) Ast.Statement.ComponentDeclaration.Param.param_name) =
let open Ast.Statement.ComponentDeclaration.Param in
match param_name with
| Identifier ident -> Identifier (this#identifier ident)
| StringLiteral (str_loc, str) -> StringLiteral (str_loc, this#string_literal str_loc str)
method component_param_pattern (expr : ('loc, 'loc) Ast.Pattern.t) =
this#binding_pattern ~kind:Ast.Variable.Let expr
method component_rest_param (expr : ('loc, 'loc) Ast.Statement.ComponentDeclaration.RestParam.t)
=
let open Ast.Statement.ComponentDeclaration.RestParam in
let (loc, { argument; }) = expr in
let argument' = this#component_param_pattern argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
expr
else
(loc, { argument = argument'; comments = comments' })
method component_body (body : 'loc * ('loc, 'loc) Ast.Statement.Block.t) =
let (loc, block) = body in
id_loc this#block loc block body (fun block -> (loc, block))
method conditional _loc (expr : ('loc, 'loc) Ast.Expression.Conditional.t) =
let open Ast.Expression.Conditional in
let { test; consequent; alternate; } = expr in
let test' = this#predicate_expression test in
let consequent' = this#expression consequent in
let alternate' = this#expression alternate in
let = this#syntax_opt comments in
if
test == test'
&& consequent == consequent'
&& alternate == alternate'
&& comments == comments'
then
expr
else
{ test = test'; consequent = consequent'; alternate = alternate'; comments = comments' }
method continue _loc (cont : 'loc Ast.Statement.Continue.t) =
let open Ast.Statement.Continue in
let { label; } = cont in
let label' = map_opt this#label_identifier label in
let = this#syntax_opt comments in
if label == label' && comments == comments' then
cont
else
{ label = label'; comments = comments' }
method debugger _loc (dbg : 'loc Ast.Statement.Debugger.t) =
let open Ast.Statement.Debugger in
let { } = dbg in
let = this#syntax_opt comments in
if comments == comments' then
dbg
else
{ comments = comments' }
method declare_class _loc (decl : ('loc, 'loc) Ast.Statement.DeclareClass.t) =
let open Ast.Statement.DeclareClass in
let { id = ident; tparams; body; extends; mixins; implements; } = decl in
let id' = this#class_identifier ident in
let tparams' = map_opt this#type_params tparams in
let body' = map_loc this#object_type body in
let extends' = map_opt (map_loc this#generic_type) extends in
let mixins' = map_list (map_loc this#generic_type) mixins in
let implements' = map_opt this#class_implements implements in
let = this#syntax_opt comments in
if
id' == ident
&& tparams' == tparams
&& body' == body
&& extends' == extends
&& mixins' == mixins
&& implements' == implements
&& comments' == comments
then
decl
else
{
id = id';
tparams = tparams';
body = body';
extends = extends';
mixins = mixins';
implements = implements';
comments = comments';
}
method declare_component _loc (decl : ('loc, 'loc) Ast.Statement.DeclareComponent.t) =
let open Ast.Statement.DeclareComponent in
let { id = ident; tparams; params; renders; } = decl in
let ident' = this#component_identifier ident in
let tparams' = map_opt this#type_params tparams in
let params' = this#component_type_params params in
let renders' = this#component_renders_annotation renders in
let = this#syntax_opt comments in
if
ident == ident'
&& tparams == tparams'
&& params == params'
&& renders == renders'
&& comments == comments'
then
decl
else
{
id = ident';
tparams = tparams';
params = params';
renders = renders';
comments = comments';
}
method component_type _loc (t : ('loc, 'loc) Ast.Type.Component.t) =
let open Ast.Type.Component in
let { tparams; params; renders; } = t in
let tparams' = map_opt this#type_params tparams in
let params' = this#component_type_params params in
let renders' = this#component_renders_annotation renders in
let = this#syntax_opt comments in
if tparams == tparams' && params == params' && renders == renders' && comments == comments'
then
t
else
{ tparams = tparams'; params = params'; renders = renders'; comments = comments' }
method component_type_params (params : ('loc, 'loc) Ast.Type.Component.Params.t) =
let open Ast.Type.Component in
let (loc, { Params.params = params_list; rest; }) = params in
let params_list' = map_list this#component_type_param params_list in
let rest' = map_opt this#component_type_rest_param rest in
let = this#syntax_opt comments in
if params_list == params_list' && rest == rest' && comments == comments' then
params
else
(loc, { Params.params = params_list'; rest = rest'; comments = comments' })
method component_type_param (param : ('loc, 'loc) Ast.Type.Component.Param.t) =
let open Ast.Type.Component.Param in
let (loc, { name; annot; optional }) = param in
let name' = this#component_param_name name in
let annot' = this#type_annotation annot in
if name == name' && annot == annot' then
param
else
(loc, { name = name'; annot = annot'; optional })
method component_type_rest_param (expr : ('loc, 'loc) Ast.Type.Component.RestParam.t) =
let open Ast.Type.Component.RestParam in
let (loc, { argument; annot; optional; }) = expr in
let argument' = map_opt this#identifier argument in
let annot' = this#type_ annot in
let = this#syntax_opt comments in
if argument == argument' && annot == annot' && comments == comments' then
expr
else
(loc, { argument = argument'; annot = annot'; comments = comments'; optional })
method declare_enum loc (enum : ('loc, 'loc) Ast.Statement.EnumDeclaration.t) =
this#enum_declaration loc enum
method declare_export_declaration
_loc (decl : ('loc, 'loc) Ast.Statement.DeclareExportDeclaration.t) =
let open Ast.Statement.DeclareExportDeclaration in
let { default; source; specifiers; declaration; } = decl in
let source' = map_loc_opt this#export_source source in
let specifiers' = map_opt this#export_named_specifier specifiers in
let declaration' = map_opt this#declare_export_declaration_decl declaration in
let = this#syntax_opt comments in
if
source == source'
&& specifiers == specifiers'
&& declaration == declaration'
&& comments == comments'
then
decl
else
{
default;
source = source';
specifiers = specifiers';
declaration = declaration';
comments = comments';
}
method declare_export_declaration_decl
(decl : ('loc, 'loc) Ast.Statement.DeclareExportDeclaration.declaration) =
let open Ast.Statement.DeclareExportDeclaration in
match decl with
| Variable (loc, dv) ->
let dv' = this#declare_variable loc dv in
if dv' == dv then
decl
else
Variable (loc, dv')
| Function (loc, df) ->
let df' = this#declare_function loc df in
if df' == df then
decl
else
Function (loc, df')
| Class (loc, dc) ->
let dc' = this#declare_class loc dc in
if dc' == dc then
decl
else
Class (loc, dc')
| Component (loc, dc) ->
let dc' = this#declare_component loc dc in
if dc' == dc then
decl
else
Component (loc, dc')
| DefaultType t ->
let t' = this#type_ t in
if t' == t then
decl
else
DefaultType t'
| NamedType (loc, ta) ->
let ta' = this#type_alias loc ta in
if ta' == ta then
decl
else
NamedType (loc, ta')
| NamedOpaqueType (loc, ot) ->
let ot' = this#opaque_type loc ot in
if ot' == ot then
decl
else
NamedOpaqueType (loc, ot')
| Interface (loc, i) ->
let i' = this#interface loc i in
if i' == i then
decl
else
Interface (loc, i')
| Enum (loc, enum) ->
let enum' = this#enum_declaration loc enum in
if enum' == enum then
decl
else
Enum (loc, enum')
method declare_function _loc (decl : ('loc, 'loc) Ast.Statement.DeclareFunction.t) =
let open Ast.Statement.DeclareFunction in
let { id = ident; annot; predicate; } = decl in
let id' = this#function_identifier ident in
let annot' = this#type_annotation annot in
let predicate' = map_opt this#predicate predicate in
let = this#syntax_opt comments in
if id' == ident && annot' == annot && predicate' == predicate && comments' == comments then
decl
else
{ id = id'; annot = annot'; predicate = predicate'; comments = comments' }
method declare_interface loc (decl : ('loc, 'loc) Ast.Statement.Interface.t) =
this#interface loc decl
method declare_module _loc (m : ('loc, 'loc) Ast.Statement.DeclareModule.t) =
let open Ast.Statement.DeclareModule in
let { id; body; kind; } = m in
let body' = map_loc this#block body in
let = this#syntax_opt comments in
if body' == body && comments == comments' then
m
else
{ id; body = body'; kind; comments = comments' }
method declare_module_exports _loc (exports : ('loc, 'loc) Ast.Statement.DeclareModuleExports.t)
=
let open Ast.Statement.DeclareModuleExports in
let { annot; } = exports in
let annot' = this#type_annotation annot in
let = this#syntax_opt comments in
if annot == annot' && comments == comments' then
exports
else
{ annot = annot'; comments = comments' }
method declare_type_alias loc (decl : ('loc, 'loc) Ast.Statement.TypeAlias.t) =
this#type_alias loc decl
method declare_variable _loc (decl : ('loc, 'loc) Ast.Statement.DeclareVariable.t) =
let open Ast.Statement.DeclareVariable in
let { id = ident; annot; kind; } = decl in
let id' = this#pattern_identifier ~kind ident in
let annot' = this#type_annotation annot in
let = this#syntax_opt comments in
if id' == ident && annot' == annot && comments' == comments then
decl
else
{ id = id'; annot = annot'; kind; comments = comments' }
method do_while _loc (stuff : ('loc, 'loc) Ast.Statement.DoWhile.t) =
let open Ast.Statement.DoWhile in
let { body; test; } = stuff in
let body' = this#statement body in
let test' = this#predicate_expression test in
let = this#syntax_opt comments in
if body == body' && test == test' && comments == comments' then
stuff
else
{ body = body'; test = test'; comments = comments' }
method empty _loc empty =
let open Ast.Statement.Empty in
let { } = empty in
let = this#syntax_opt comments in
if comments == comments' then
empty
else
{ comments = comments' }
method enum_declaration _loc (enum : ('loc, 'loc) Ast.Statement.EnumDeclaration.t) =
let open Ast.Statement.EnumDeclaration in
let { id = ident; body; } = enum in
let id' = this#pattern_identifier ~kind:Ast.Variable.Const ident in
let body' = this#enum_body body in
let = this#syntax_opt comments in
if ident == id' && body == body' && comments == comments' then
enum
else
{ id = id'; body = body'; comments = comments' }
method enum_body (body : 'loc Ast.Statement.EnumDeclaration.body) =
let open Ast.Statement.EnumDeclaration in
match body with
| (loc, BooleanBody boolean_body) ->
id this#enum_boolean_body boolean_body body (fun body -> (loc, BooleanBody body))
| (loc, NumberBody number_body) ->
id this#enum_number_body number_body body (fun body -> (loc, NumberBody body))
| (loc, StringBody string_body) ->
id this#enum_string_body string_body body (fun body -> (loc, StringBody body))
| (loc, SymbolBody symbol_body) ->
id this#enum_symbol_body symbol_body body (fun body -> (loc, SymbolBody body))
| (loc, BigIntBody bigint_body) ->
id this#enum_bigint_body bigint_body body (fun body -> (loc, BigIntBody body))
method enum_boolean_body (body : 'loc Ast.Statement.EnumDeclaration.BooleanBody.t) =
let open Ast.Statement.EnumDeclaration.BooleanBody in
let { members; explicit_type = _; has_unknown_members = _; } = body in
let members' = map_list this#enum_boolean_member members in
let = this#syntax_opt comments in
if members == members' && comments == comments' then
body
else
{ body with members = members'; comments = comments' }
method enum_number_body (body : 'loc Ast.Statement.EnumDeclaration.NumberBody.t) =
let open Ast.Statement.EnumDeclaration.NumberBody in
let { members; explicit_type = _; has_unknown_members = _; } = body in
let members' = map_list this#enum_number_member members in
let = this#syntax_opt comments in
if members == members' && comments == comments' then
body
else
{ body with members = members'; comments = comments' }
method enum_string_body (body : 'loc Ast.Statement.EnumDeclaration.StringBody.t) =
let open Ast.Statement.EnumDeclaration.StringBody in
let { members; explicit_type = _; has_unknown_members = _; } = body in
let members' =
match members with
| Defaulted m -> id (map_list this#enum_defaulted_member) m members (fun m -> Defaulted m)
| Initialized m -> id (map_list this#enum_string_member) m members (fun m -> Initialized m)
in
let = this#syntax_opt comments in
if members == members' && comments == comments' then
body
else
{ body with members = members'; comments = comments' }
method enum_symbol_body (body : 'loc Ast.Statement.EnumDeclaration.SymbolBody.t) =
let open Ast.Statement.EnumDeclaration.SymbolBody in
let { members; has_unknown_members = _; } = body in
let members' = map_list this#enum_defaulted_member members in
let = this#syntax_opt comments in
if members == members' && comments == comments' then
body
else
{ body with members = members'; comments = comments' }
method enum_bigint_body (body : 'loc Ast.Statement.EnumDeclaration.BigIntBody.t) =
let open Ast.Statement.EnumDeclaration.BigIntBody in
let { members; explicit_type = _; has_unknown_members = _; } = body in
let members' = map_list this#enum_bigint_member members in
let = this#syntax_opt comments in
if members == members' && comments == comments' then
body
else
{ body with members = members'; comments = comments' }
method enum_defaulted_member (member : 'loc Ast.Statement.EnumDeclaration.DefaultedMember.t) =
let open Ast.Statement.EnumDeclaration.DefaultedMember in
let (loc, { id = ident }) = member in
let id' = this#enum_member_identifier ident in
if ident == id' then
member
else
(loc, { id = id' })
method enum_boolean_member
(member :
('loc Ast.BooleanLiteral.t, 'loc) Ast.Statement.EnumDeclaration.InitializedMember.t
) =
let open Ast.Statement.EnumDeclaration.InitializedMember in
let (loc, { id = ident; init }) = member in
let id' = this#enum_member_identifier ident in
if ident == id' then
member
else
(loc, { id = id'; init })
method enum_number_member
(member : ('loc Ast.NumberLiteral.t, 'loc) Ast.Statement.EnumDeclaration.InitializedMember.t)
=
let open Ast.Statement.EnumDeclaration.InitializedMember in
let (loc, { id = ident; init }) = member in
let id' = this#enum_member_identifier ident in
if ident == id' then
member
else
(loc, { id = id'; init })
method enum_string_member
(member : ('loc Ast.StringLiteral.t, 'loc) Ast.Statement.EnumDeclaration.InitializedMember.t)
=
let open Ast.Statement.EnumDeclaration.InitializedMember in
let (loc, { id = ident; init }) = member in
let id' = this#enum_member_identifier ident in
if ident == id' then
member
else
(loc, { id = id'; init })
method enum_bigint_member
(member : ('loc Ast.BigIntLiteral.t, 'loc) Ast.Statement.EnumDeclaration.InitializedMember.t)
=
let open Ast.Statement.EnumDeclaration.InitializedMember in
let (loc, { id = ident; init }) = member in
let id' = this#enum_member_identifier ident in
if ident == id' then
member
else
(loc, { id = id'; init })
method enum_member_identifier (id : ('loc, 'loc) Ast.Identifier.t) = this#identifier id
method export_default_declaration
_loc (decl : ('loc, 'loc) Ast.Statement.ExportDefaultDeclaration.t) =
let open Ast.Statement.ExportDefaultDeclaration in
let { default; declaration; } = decl in
let declaration' = this#export_default_declaration_decl declaration in
let = this#syntax_opt comments in
if declaration' == declaration && comments' == comments then
decl
else
{ default; declaration = declaration'; comments = comments' }
method export_default_declaration_decl
(decl : ('loc, 'loc) Ast.Statement.ExportDefaultDeclaration.declaration) =
let open Ast.Statement.ExportDefaultDeclaration in
match decl with
| Declaration stmt -> id this#statement stmt decl (fun stmt -> Declaration stmt)
| Expression expr -> id this#expression expr decl (fun expr -> Expression expr)
method export_named_declaration _loc (decl : ('loc, 'loc) Ast.Statement.ExportNamedDeclaration.t)
=
let open Ast.Statement.ExportNamedDeclaration in
let { export_kind; source; specifiers; declaration; } = decl in
let source' = map_loc_opt this#export_source source in
let specifiers' = map_opt this#export_named_specifier specifiers in
let declaration' = map_opt this#statement declaration in
let = this#syntax_opt comments in
if
source == source'
&& specifiers == specifiers'
&& declaration == declaration'
&& comments == comments'
then
decl
else
{
export_kind;
source = source';
specifiers = specifiers';
declaration = declaration';
comments = comments';
}
method export_named_declaration_specifier
(spec : ('loc, 'loc) Ast.Statement.ExportNamedDeclaration.ExportSpecifier.t) =
let open Ast.Statement.ExportNamedDeclaration.ExportSpecifier in
let (loc, { local; exported }) = spec in
let local' = this#identifier local in
let exported' = map_opt this#identifier exported in
if local == local' && exported == exported' then
spec
else
(loc, { local = local'; exported = exported' })
method export_batch_specifier
(spec : ('loc, 'loc) Ast.Statement.ExportNamedDeclaration.ExportBatchSpecifier.t) =
let (loc, id_opt) = spec in
let id_opt' = map_opt this#identifier id_opt in
if id_opt == id_opt' then
spec
else
(loc, id_opt')
method export_named_specifier
(spec : ('loc, 'loc) Ast.Statement.ExportNamedDeclaration.specifier) =
let open Ast.Statement.ExportNamedDeclaration in
match spec with
| ExportSpecifiers spec_list ->
let spec_list' = map_list this#export_named_declaration_specifier spec_list in
if spec_list == spec_list' then
spec
else
ExportSpecifiers spec_list'
| ExportBatchSpecifier batch ->
let batch' = this#export_batch_specifier batch in
if batch == batch' then
spec
else
ExportBatchSpecifier batch'
method export_source _loc (source : 'loc Ast.StringLiteral.t) =
let open Ast.StringLiteral in
let { value; raw; } = source in
let = this#syntax_opt comments in
if comments == comments' then
source
else
{ value; raw; comments = comments' }
method expression_statement _loc (stmt : ('loc, 'loc) Ast.Statement.Expression.t) =
let open Ast.Statement.Expression in
let { expression = expr; directive; } = stmt in
let expr' = this#expression expr in
let = this#syntax_opt comments in
if expr == expr' && comments == comments' then
stmt
else
{ expression = expr'; directive; comments = comments' }
method expression_or_spread expr_or_spread =
let open Ast.Expression in
match expr_or_spread with
| Expression expr -> id this#expression expr expr_or_spread (fun expr -> Expression expr)
| Spread spread -> id this#spread_element spread expr_or_spread (fun spread -> Spread spread)
method for_in_statement _loc (stmt : ('loc, 'loc) Ast.Statement.ForIn.t) =
let open Ast.Statement.ForIn in
let { left; right; body; each; } = stmt in
let left' = this#for_in_statement_lhs left in
let right' = this#expression right in
let body' = this#statement body in
let = this#syntax_opt comments in
if left == left' && right == right' && body == body' && comments == comments' then
stmt
else
{ left = left'; right = right'; body = body'; each; comments = comments' }
method for_in_statement_lhs (left : ('loc, 'loc) Ast.Statement.ForIn.left) =
let open Ast.Statement.ForIn in
match left with
| LeftDeclaration decl ->
id this#for_in_left_declaration decl left (fun decl -> LeftDeclaration decl)
| LeftPattern patt ->
id this#for_in_assignment_pattern patt left (fun patt -> LeftPattern patt)
method for_in_left_declaration left =
let (loc, decl) = left in
id_loc this#variable_declaration loc decl left (fun decl -> (loc, decl))
method for_of_statement _loc (stuff : ('loc, 'loc) Ast.Statement.ForOf.t) =
let open Ast.Statement.ForOf in
let { left; right; body; await; } = stuff in
let left' = this#for_of_statement_lhs left in
let right' = this#expression right in
let body' = this#statement body in
let = this#syntax_opt comments in
if left == left' && right == right' && body == body' && comments == comments' then
stuff
else
{ left = left'; right = right'; body = body'; await; comments = comments' }
method for_of_statement_lhs (left : ('loc, 'loc) Ast.Statement.ForOf.left) =
let open Ast.Statement.ForOf in
match left with
| LeftDeclaration decl ->
id this#for_of_left_declaration decl left (fun decl -> LeftDeclaration decl)
| LeftPattern patt ->
id this#for_of_assignment_pattern patt left (fun patt -> LeftPattern patt)
method for_of_left_declaration left =
let (loc, decl) = left in
id_loc this#variable_declaration loc decl left (fun decl -> (loc, decl))
method for_statement _loc (stmt : ('loc, 'loc) Ast.Statement.For.t) =
let open Ast.Statement.For in
let { init; test; update; body; } = stmt in
let init' = map_opt this#for_statement_init init in
let test' = map_opt this#predicate_expression test in
let update' = map_opt this#expression update in
let body' = this#statement body in
let = this#syntax_opt comments in
if
init == init'
&& test == test'
&& update == update'
&& body == body'
&& comments == comments'
then
stmt
else
{ init = init'; test = test'; update = update'; body = body'; comments = comments' }
method for_statement_init (init : ('loc, 'loc) Ast.Statement.For.init) =
let open Ast.Statement.For in
match init with
| InitDeclaration decl ->
id this#for_init_declaration decl init (fun decl -> InitDeclaration decl)
| InitExpression expr -> id this#expression expr init (fun expr -> InitExpression expr)
method for_init_declaration init =
let (loc, decl) = init in
id_loc this#variable_declaration loc decl init (fun decl -> (loc, decl))
method function_param_type (fpt : ('loc, 'loc) Ast.Type.Function.Param.t) =
let open Ast.Type.Function.Param in
let (loc, { annot; name; optional }) = fpt in
let annot' = this#type_ annot in
let name' = map_opt this#identifier name in
if annot' == annot && name' == name then
fpt
else
(loc, { annot = annot'; name = name'; optional })
method function_rest_param_type (frpt : ('loc, 'loc) Ast.Type.Function.RestParam.t) =
let open Ast.Type.Function.RestParam in
let (loc, { argument; }) = frpt in
let argument' = this#function_param_type argument in
let = this#syntax_opt comments in
if argument' == argument && comments' == comments then
frpt
else
(loc, { argument = argument'; comments = comments' })
method function_this_param_type (this_param : ('loc, 'loc) Ast.Type.Function.ThisParam.t) =
let open Ast.Type.Function.ThisParam in
let (loc, { annot; }) = this_param in
let annot' = this#type_annotation annot in
let = this#syntax_opt comments in
if annot' == annot && comments' == comments then
this_param
else
(loc, { annot = annot'; comments = comments' })
method function_type_return_annotation
(return : ('loc, 'loc) Ast.Type.Function.return_annotation) =
let open Ast.Type.Function in
match return with
| TypeAnnotation t -> id this#type_ t return (fun rt -> TypeAnnotation rt)
| TypeGuard g -> id this#type_guard g return (fun tg -> TypeGuard tg)
method function_type _loc (ft : ('loc, 'loc) Ast.Type.Function.t) =
let open Ast.Type.Function in
let {
params = (params_loc, { Params.this_; params = ps; rest = rpo; comments = });
return;
tparams;
comments = ;
} =
ft
in
let tparams' = map_opt this#type_params tparams in
let this_' = map_opt this#function_this_param_type this_ in
let ps' = map_list this#function_param_type ps in
let rpo' = map_opt this#function_rest_param_type rpo in
let return' = this#function_type_return_annotation return in
let = this#syntax_opt func_comments in
let = this#syntax_opt params_comments in
if
ps' == ps
&& rpo' == rpo
&& return' == return
&& tparams' == tparams
&& func_comments' == func_comments
&& params_comments' == params_comments
&& this_' == this_
then
ft
else
{
params =
( params_loc,
{ Params.this_ = this_'; params = ps'; rest = rpo'; comments = params_comments' }
);
return = return';
tparams = tparams';
comments = func_comments';
}
method label_identifier (ident : ('loc, 'loc) Ast.Identifier.t) = this#identifier ident
method object_property_value_type (opvt : ('loc, 'loc) Ast.Type.Object.Property.value) =
let open Ast.Type.Object.Property in
match opvt with
| Init t -> id this#type_ t opvt (fun t -> Init t)
| Get t -> id this#object_type_property_getter t opvt (fun t -> Get t)
| Set t -> id this#object_type_property_setter t opvt (fun t -> Set t)
method object_type_property_getter getter =
let (loc, ft) = getter in
id_loc this#function_type loc ft getter (fun ft -> (loc, ft))
method object_type_property_setter setter =
let (loc, ft) = setter in
id_loc this#function_type loc ft setter (fun ft -> (loc, ft))
method object_property_type (opt : ('loc, 'loc) Ast.Type.Object.Property.t) =
let open Ast.Type.Object.Property in
let (loc, { key; value; optional; static; proto; _method; variance; }) = opt in
let key' = this#object_key key in
let value' = this#object_property_value_type value in
let variance' = this#variance_opt variance in
let = this#syntax_opt comments in
if key' == key && value' == value && variance' == variance && comments' == comments then
opt
else
( loc,
{
key = key';
value = value';
optional;
static;
proto;
_method;
variance = variance';
comments = comments';
}
)
method object_spread_property_type (opt : ('loc, 'loc) Ast.Type.Object.SpreadProperty.t) =
let open Ast.Type.Object.SpreadProperty in
let (loc, { argument; }) = opt in
let argument' = this#type_ argument in
let = this#syntax_opt comments in
if argument' == argument && comments == comments' then
opt
else
(loc, { argument = argument'; comments = comments' })
method object_indexer_property_type (opt : ('loc, 'loc) Ast.Type.Object.Indexer.t) =
let open Ast.Type.Object.Indexer in
let (loc, { id; key; value; static; variance; }) = opt in
let key' = this#type_ key in
let value' = this#type_ value in
let variance' = this#variance_opt variance in
let = this#syntax_opt comments in
if key' == key && value' == value && variance' == variance && comments' == comments then
opt
else
(loc, { id; key = key'; value = value'; static; variance = variance'; comments = comments' })
method object_internal_slot_property_type (slot : ('loc, 'loc) Ast.Type.Object.InternalSlot.t) =
let open Ast.Type.Object.InternalSlot in
let (loc, { id; value; optional; static; _method; }) = slot in
let id' = this#identifier id in
let value' = this#type_ value in
let = this#syntax_opt comments in
if id == id' && value == value' && comments == comments' then
slot
else
(loc, { id = id'; value = value'; optional; static; _method; comments = comments' })
method object_call_property_type (call : ('loc, 'loc) Ast.Type.Object.CallProperty.t) =
let open Ast.Type.Object.CallProperty in
let (loc, { value = (value_loc, value); static; }) = call in
let value' = this#function_type value_loc value in
let = this#syntax_opt comments in
if value == value' && comments == comments' then
call
else
(loc, { value = (value_loc, value'); static; comments = comments' })
method object_mapped_type_property (mt : ('loc, 'loc) Ast.Type.Object.MappedType.t) =
let open Ast.Type.Object.MappedType in
let (loc, { key_tparam; prop_type; source_type; variance; ; optional }) = mt in
let key_tparam' = this#type_param key_tparam in
let prop_type' = this#type_ prop_type in
let source_type' = this#type_ source_type in
let variance' = this#variance_opt variance in
let = this#syntax_opt comments in
if
key_tparam' == key_tparam
&& prop_type' == prop_type
&& source_type' == source_type
&& variance' == variance
&& comments' == comments
then
mt
else
( loc,
{
key_tparam = key_tparam';
prop_type = prop_type';
source_type = source_type';
variance = variance';
comments = comments';
optional;
}
)
method object_type _loc (ot : ('loc, 'loc) Ast.Type.Object.t) =
let open Ast.Type.Object in
let { properties; exact; inexact; } = ot in
let properties' = map_list this#object_type_property properties in
let = this#syntax_opt comments in
if properties' == properties && comments == comments' then
ot
else
{ properties = properties'; exact; inexact; comments = comments' }
method object_type_property (p : ('loc, 'loc) Ast.Type.Object.property) =
let open Ast.Type.Object in
match p with
| Property p' -> id this#object_property_type p' p (fun p' -> Property p')
| SpreadProperty p' -> id this#object_spread_property_type p' p (fun p' -> SpreadProperty p')
| Indexer p' -> id this#object_indexer_property_type p' p (fun p' -> Indexer p')
| InternalSlot p' ->
id this#object_internal_slot_property_type p' p (fun p' -> InternalSlot p')
| CallProperty p' -> id this#object_call_property_type p' p (fun p' -> CallProperty p')
| MappedType p' -> id this#object_mapped_type_property p' p (fun p' -> MappedType p')
method interface_type _loc (i : ('loc, 'loc) Ast.Type.Interface.t) =
let open Ast.Type.Interface in
let { extends; body; } = i in
let extends' = map_list (map_loc this#generic_type) extends in
let body' = map_loc this#object_type body in
let = this#syntax_opt comments in
if extends' == extends && body' == body && comments == comments' then
i
else
{ extends = extends'; body = body'; comments = comments' }
method generic_identifier_type (git : ('loc, 'loc) Ast.Type.Generic.Identifier.t) =
let open Ast.Type.Generic.Identifier in
match git with
| Unqualified i -> id this#type_identifier_reference i git (fun i -> Unqualified i)
| Qualified i -> id this#generic_qualified_identifier_type i git (fun i -> Qualified i)
method generic_qualified_identifier_type qual =
let open Ast.Type.Generic.Identifier in
let (loc, { qualification; id }) = qual in
let qualification' = this#generic_identifier_type qualification in
let id' = this#member_type_identifier id in
if qualification' == qualification && id' == id then
qual
else
(loc, { qualification = qualification'; id = id' })
method member_type_identifier id = this#identifier id
method variance (variance : 'loc Ast.Variance.t) =
let (loc, { Ast.Variance.kind; }) = variance in
let = this#syntax_opt comments in
if comments == comments' then
variance
else
(loc, { Ast.Variance.kind; comments = comments' })
method variance_opt (opt : 'loc Ast.Variance.t option) = map_opt this#variance opt
method type_args (targs : ('loc, 'loc) Ast.Type.TypeArgs.t) =
let open Ast.Type.TypeArgs in
let (loc, { arguments; }) = targs in
let arguments' = map_list this#type_ arguments in
let = this#syntax_opt comments in
if arguments == arguments' && comments == comments' then
targs
else
(loc, { arguments = arguments'; comments = comments' })
method type_params (tparams : ('loc, 'loc) Ast.Type.TypeParams.t) =
let open Ast.Type.TypeParams in
let (loc, { params = tps; }) = tparams in
let tps' = map_list this#type_param tps in
let = this#syntax_opt comments in
if tps' == tps && comments' == comments then
tparams
else
(loc, { params = tps'; comments = comments' })
method type_param (tparam : ('loc, 'loc) Ast.Type.TypeParam.t) =
let open Ast.Type.TypeParam in
let (loc, { name; bound; bound_kind; variance; default }) = tparam in
let bound' = this#type_annotation_hint bound in
let variance' = this#variance_opt variance in
let default' = map_opt this#type_ default in
let name' = this#binding_type_identifier name in
if name' == name && bound' == bound && variance' == variance && default' == default then
tparam
else
(loc, { name = name'; bound = bound'; bound_kind; variance = variance'; default = default' })
method generic_type _loc (gt : ('loc, 'loc) Ast.Type.Generic.t) =
let open Ast.Type.Generic in
let { id; targs; } = gt in
let id' = this#generic_identifier_type id in
let targs' = map_opt this#type_args targs in
let = this#syntax_opt comments in
if id' == id && targs' == targs && comments' == comments then
gt
else
{ id = id'; targs = targs'; comments = comments' }
method indexed_access_type _loc (ia : ('loc, 'loc) Ast.Type.IndexedAccess.t) =
let open Ast.Type.IndexedAccess in
let { _object; index; } = ia in
let _object' = this#type_ _object in
let index' = this#type_ index in
let = this#syntax_opt comments in
if _object' == _object && index' == index && comments' == comments then
ia
else
{ _object = _object'; index = index'; comments = comments' }
method optional_indexed_access_type loc (ia : ('loc, 'loc) Ast.Type.OptionalIndexedAccess.t) =
let open Ast.Type.OptionalIndexedAccess in
let { indexed_access; optional } = ia in
let indexed_access' = this#indexed_access_type loc indexed_access in
if indexed_access' == indexed_access then
ia
else
{ indexed_access = indexed_access'; optional }
method string_literal _loc (lit : 'loc Ast.StringLiteral.t) =
let open Ast.StringLiteral in
let { value; raw; } = lit in
let = this#syntax_opt comments in
if comments == comments' then
lit
else
{ value; raw; comments = comments' }
method number_literal _loc (lit : 'loc Ast.NumberLiteral.t) =
let open Ast.NumberLiteral in
let { value; raw; } = lit in
let = this#syntax_opt comments in
if comments == comments' then
lit
else
{ value; raw; comments = comments' }
method bigint_literal _loc (lit : 'loc Ast.BigIntLiteral.t) =
let open Ast.BigIntLiteral in
let { value; raw; } = lit in
let = this#syntax_opt comments in
if comments == comments' then
lit
else
{ value; raw; comments = comments' }
method boolean_literal _loc (lit : 'loc Ast.BooleanLiteral.t) =
let open Ast.BooleanLiteral in
let { value; } = lit in
let = this#syntax_opt comments in
if comments == comments' then
lit
else
{ value; comments = comments' }
method null_literal _loc = this#syntax_opt comments
method regexp_literal _loc (lit : 'loc Ast.RegExpLiteral.t) =
let open Ast.RegExpLiteral in
let { pattern; flags; raw; } = lit in
let = this#syntax_opt comments in
if comments == comments' then
lit
else
{ pattern; flags; raw; comments = comments' }
method module_ref_literal _loc (lit : ('loc, 'loc) Ast.ModuleRefLiteral.t) =
let open Ast.ModuleRefLiteral in
let { value; require_out; prefix_len; legacy_interop; raw; } = lit in
let = this#syntax_opt comments in
if comments == comments' then
lit
else
{ value; require_out; prefix_len; legacy_interop; raw; comments }
method nullable_type (t : ('loc, 'loc) Ast.Type.Nullable.t) =
let open Ast.Type.Nullable in
let { argument; } = t in
let argument' = this#type_ argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
t
else
{ argument = argument'; comments = comments' }
method conditional_type (t : ('loc, 'loc) Ast.Type.Conditional.t) =
let open Ast.Type.Conditional in
let { check_type; extends_type; true_type; false_type; } = t in
let check_type' = this#type_ check_type in
let extends_type' = this#type_ extends_type in
let true_type' = this#type_ true_type in
let false_type' = this#type_ false_type in
let = this#syntax_opt comments in
if
check_type == check_type'
&& extends_type == extends_type'
&& true_type == true_type'
&& false_type == false_type'
&& comments == comments'
then
t
else
{
check_type = check_type';
extends_type = extends_type';
true_type = true_type';
false_type = false_type';
comments = comments';
}
method infer_type (t : ('loc, 'loc) Ast.Type.Infer.t) =
let open Ast.Type.Infer in
let { tparam; } = t in
let tparam' = this#type_param tparam in
let = this#syntax_opt comments in
if tparam == tparam' && comments == comments' then
t
else
{ tparam = tparam'; comments = comments' }
method typeof_type (t : ('loc, 'loc) Ast.Type.Typeof.t) =
let open Ast.Type.Typeof in
let { argument; targs; } = t in
let argument' = this#typeof_expression argument in
let targs' = map_opt this#type_args targs in
let = this#syntax_opt comments in
if argument == argument' && targs = targs' && comments == comments' then
t
else
{ argument = argument'; targs = targs'; comments = comments' }
method typeof_expression (git : ('loc, 'loc) Ast.Type.Typeof.Target.t) =
let open Ast.Type.Typeof.Target in
match git with
| Unqualified i -> id this#typeof_identifier i git (fun i -> Unqualified i)
| Qualified i -> id this#typeof_qualified_identifier i git (fun i -> Qualified i)
method typeof_identifier id = this#identifier id
method typeof_member_identifier id = this#identifier id
method typeof_qualified_identifier qual =
let open Ast.Type.Typeof.Target in
let (loc, { qualification; id }) = qual in
let qualification' = this#typeof_expression qualification in
let id' = this#typeof_member_identifier id in
if qualification' == qualification && id' == id then
qual
else
(loc, { qualification = qualification'; id = id' })
method keyof_type (t : ('loc, 'loc) Ast.Type.Keyof.t) =
let open Ast.Type.Keyof in
let { argument; } = t in
let argument' = this#type_ argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
t
else
{ argument = argument'; comments = comments' }
method render_type (t : ('loc, 'loc) Ast.Type.Renders.t) =
let open Ast.Type.Renders in
let { operator_loc; argument; variant; } = t in
let argument' = this#type_ argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
t
else
{ operator_loc; argument = argument'; comments = comments'; variant }
method readonly_type (t : ('loc, 'loc) Ast.Type.ReadOnly.t) =
let open Ast.Type.ReadOnly in
let { argument; } = t in
let argument' = this#type_ argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
t
else
{ argument = argument'; comments = comments' }
method tuple_type (t : ('loc, 'loc) Ast.Type.Tuple.t) =
let open Ast.Type.Tuple in
let { elements; } = t in
let elements' = map_list this#tuple_element elements in
let = this#syntax_opt comments in
if elements == elements' && comments == comments' then
t
else
{ elements = elements'; comments = comments' }
method tuple_element (el : ('loc, 'loc) Ast.Type.Tuple.element) =
let open Ast.Type.Tuple in
match el with
| (loc, UnlabeledElement t) -> id this#type_ t el (fun t -> (loc, UnlabeledElement t))
| (loc, LabeledElement e) ->
id this#tuple_labeled_element e el (fun e -> (loc, LabeledElement e))
| (loc, SpreadElement e) -> id this#tuple_spread_element e el (fun e -> (loc, SpreadElement e))
method tuple_labeled_element (t : ('loc, 'loc) Ast.Type.Tuple.LabeledElement.t) =
let open Ast.Type.Tuple.LabeledElement in
let { annot; name; variance; optional } = t in
let annot' = this#type_ annot in
let variance' = this#variance_opt variance in
if annot' == annot && variance' == variance then
t
else
{ annot = annot'; name; variance = variance'; optional }
method tuple_spread_element (t : ('loc, 'loc) Ast.Type.Tuple.SpreadElement.t) =
let open Ast.Type.Tuple.SpreadElement in
let { annot; name } = t in
let annot' = this#type_ annot in
if annot' == annot then
t
else
{ annot = annot'; name }
method array_type (t : ('loc, 'loc) Ast.Type.Array.t) =
let open Ast.Type.Array in
let { argument; } = t in
let argument' = this#type_ argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
t
else
{ argument = argument'; comments = comments' }
method union_type _loc (t : ('loc, 'loc) Ast.Type.Union.t) =
let open Ast.Type.Union in
let { types = (t0, t1, ts); } = t in
let t0' = this#type_ t0 in
let t1' = this#type_ t1 in
let ts' = map_list this#type_ ts in
let = this#syntax_opt comments in
if t0' == t0 && t1' == t1 && ts' == ts && comments' == comments then
t
else
{ types = (t0', t1', ts'); comments = comments' }
method intersection_type _loc (t : ('loc, 'loc) Ast.Type.Intersection.t) =
let open Ast.Type.Intersection in
let { types = (t0, t1, ts); } = t in
let t0' = this#type_ t0 in
let t1' = this#type_ t1 in
let ts' = map_list this#type_ ts in
let = this#syntax_opt comments in
if t0' == t0 && t1' == t1 && ts' == ts && comments' == comments then
t
else
{ types = (t0', t1', ts'); comments = comments' }
method type_ (t : ('loc, 'loc) Ast.Type.t) =
let open Ast.Type in
match t with
| (loc, Any ) -> id this#syntax_opt comments t (fun -> (loc, Any comments))
| (loc, Mixed ) ->
id this#syntax_opt comments t (fun -> (loc, Mixed comments))
| (loc, Empty ) ->
id this#syntax_opt comments t (fun -> (loc, Empty comments))
| (loc, Void ) -> id this#syntax_opt comments t (fun -> (loc, Void comments))
| (loc, Null ) -> id this#syntax_opt comments t (fun -> (loc, Null comments))
| (loc, Symbol ) ->
id this#syntax_opt comments t (fun -> (loc, Symbol comments))
| (loc, Number ) ->
id this#syntax_opt comments t (fun -> (loc, Number comments))
| (loc, BigInt ) ->
id this#syntax_opt comments t (fun -> (loc, BigInt comments))
| (loc, String ) ->
id this#syntax_opt comments t (fun -> (loc, String comments))
| (loc, Boolean { raw; }) ->
id this#syntax_opt comments t (fun -> (loc, Boolean { raw; comments }))
| (loc, Exists ) ->
id this#syntax_opt comments t (fun -> (loc, Exists comments))
| (loc, Unknown ) ->
id this#syntax_opt comments t (fun -> (loc, Unknown comments))
| (loc, Never ) ->
id this#syntax_opt comments t (fun -> (loc, Never comments))
| (loc, Undefined ) ->
id this#syntax_opt comments t (fun -> (loc, Undefined comments))
| (loc, Nullable t') -> id this#nullable_type t' t (fun t' -> (loc, Nullable t'))
| (loc, Array t') -> id this#array_type t' t (fun t' -> (loc, Array t'))
| (loc, Conditional t') -> id this#conditional_type t' t (fun t' -> (loc, Conditional t'))
| (loc, Infer t') -> id this#infer_type t' t (fun t' -> (loc, Infer t'))
| (loc, Typeof t') -> id this#typeof_type t' t (fun t' -> (loc, Typeof t'))
| (loc, Keyof t') -> id this#keyof_type t' t (fun t' -> (loc, Keyof t'))
| (loc, Renders t') -> id this#render_type t' t (fun t' -> (loc, Renders t'))
| (loc, ReadOnly t') -> id this#readonly_type t' t (fun t' -> (loc, ReadOnly t'))
| (loc, Function ft) -> id_loc this#function_type loc ft t (fun ft -> (loc, Function ft))
| (loc, Component ct) -> id_loc this#component_type loc ct t (fun ct -> (loc, Component ct))
| (loc, Object ot) -> id_loc this#object_type loc ot t (fun ot -> (loc, Object ot))
| (loc, Interface i) -> id_loc this#interface_type loc i t (fun i -> (loc, Interface i))
| (loc, Generic gt) -> id_loc this#generic_type loc gt t (fun gt -> (loc, Generic gt))
| (loc, IndexedAccess ia) ->
id_loc this#indexed_access_type loc ia t (fun ia -> (loc, IndexedAccess ia))
| (loc, OptionalIndexedAccess ia) ->
id_loc this#optional_indexed_access_type loc ia t (fun ia -> (loc, OptionalIndexedAccess ia))
| (loc, StringLiteral lit) ->
id_loc this#string_literal loc lit t (fun lit -> (loc, StringLiteral lit))
| (loc, NumberLiteral lit) ->
id_loc this#number_literal loc lit t (fun lit -> (loc, NumberLiteral lit))
| (loc, BigIntLiteral lit) ->
id_loc this#bigint_literal loc lit t (fun lit -> (loc, BigIntLiteral lit))
| (loc, BooleanLiteral lit) ->
id_loc this#boolean_literal loc lit t (fun lit -> (loc, BooleanLiteral lit))
| (loc, Union t') -> id_loc this#union_type loc t' t (fun t' -> (loc, Union t'))
| (loc, Intersection t') ->
id_loc this#intersection_type loc t' t (fun t' -> (loc, Intersection t'))
| (loc, Tuple t') -> id this#tuple_type t' t (fun t' -> (loc, Tuple t'))
method type_annotation (annot : ('loc, 'loc) Ast.Type.annotation) =
let (loc, a) = annot in
id this#type_ a annot (fun a -> (loc, a))
method type_annotation_hint (return : ('M, 'T) Ast.Type.annotation_or_hint) =
let open Ast.Type in
match return with
| Available annot -> id this#type_annotation annot return (fun a -> Available a)
| Missing _loc -> return
method component_renders_annotation (renders : ('M, 'T) Ast.Type.component_renders_annotation) =
let open Ast.Type in
match renders with
| AvailableRenders (loc, render_type) ->
let render_type' = this#render_type render_type in
if render_type' == render_type then
renders
else
AvailableRenders (loc, render_type')
| MissingRenders _loc -> renders
method function_declaration loc (stmt : ('loc, 'loc) Ast.Function.t) = this#function_ loc stmt
method function_expression loc (stmt : ('loc, 'loc) Ast.Function.t) =
this#function_expression_or_method loc stmt
(** previously, we conflated [function_expression] and [class_method]. callers should be
updated to override those individually. *)
method function_expression_or_method loc (stmt : ('loc, 'loc) Ast.Function.t) =
this#function_ loc stmt
method function_ _loc (expr : ('loc, 'loc) Ast.Function.t) =
let open Ast.Function in
let {
id = ident;
params;
body;
async;
generator;
predicate;
return;
tparams;
sig_loc;
;
} =
expr
in
let ident' = map_opt this#function_identifier ident in
let tparams' = map_opt this#type_params tparams in
let params' = this#function_params params in
let return' = this#function_return_annotation return in
let body' = this#function_body_any body in
let predicate' = map_opt this#predicate predicate in
let = this#syntax_opt comments in
if
ident == ident'
&& params == params'
&& body == body'
&& predicate == predicate'
&& return == return'
&& tparams == tparams'
&& comments == comments'
then
expr
else
{
id = ident';
params = params';
return = return';
body = body';
async;
generator;
predicate = predicate';
tparams = tparams';
sig_loc;
comments = comments';
}
method function_params (params : ('loc, 'loc) Ast.Function.Params.t) =
let open Ast.Function in
let (loc, { Params.params = params_list; rest; ; this_ }) = params in
let params_list' = map_list this#function_param params_list in
let rest' = map_opt this#function_rest_param rest in
let this_' = map_opt this#function_this_param this_ in
let = this#syntax_opt comments in
if params_list == params_list' && rest == rest' && comments == comments' && this_ == this_'
then
params
else
(loc, { Params.params = params_list'; rest = rest'; comments = comments'; this_ = this_' })
method function_this_param (this_param : ('loc, 'loc) Ast.Function.ThisParam.t) =
let open Ast.Function.ThisParam in
let (loc, { annot; }) = this_param in
let annot' = this#type_annotation annot in
let = this#syntax_opt comments in
if annot' == annot && comments' == comments then
this_param
else
(loc, { annot = annot'; comments = comments' })
method function_param (param : ('loc, 'loc) Ast.Function.Param.t) =
let open Ast.Function.Param in
let (loc, { argument; default }) = param in
let argument' = this#function_param_pattern argument in
let default' = this#default_opt default in
if argument == argument' && default == default' then
param
else
(loc, { argument = argument'; default = default' })
method function_return_annotation (return : ('loc, 'loc) Ast.Function.ReturnAnnot.t) =
let open Ast.Function.ReturnAnnot in
match return with
| Missing _loc -> return
| Available t -> id this#type_annotation t return (fun rt -> Available rt)
| TypeGuard g -> id this#type_guard_annotation g return (fun tg -> TypeGuard tg)
method function_body_any (body : ('loc, 'loc) Ast.Function.body) =
match body with
| Ast.Function.BodyBlock block ->
id this#function_body block body (fun block -> Ast.Function.BodyBlock block)
| Ast.Function.BodyExpression expr ->
id this#body_expression expr body (fun expr -> Ast.Function.BodyExpression expr)
method function_body (body : 'loc * ('loc, 'loc) Ast.Statement.Block.t) =
let (loc, block) = body in
id_loc this#block loc block body (fun block -> (loc, block))
method body_expression (expr : ('loc, 'loc) Ast.Expression.t) = this#expression expr
method function_identifier (ident : ('loc, 'loc) Ast.Identifier.t) =
this#pattern_identifier ~kind:Ast.Variable.Var ident
method identifier (id : ('loc, 'loc) Ast.Identifier.t) =
let open Ast.Identifier in
let (loc, { name; }) = id in
let = this#syntax_opt comments in
if comments == comments' then
id
else
(loc, { name; comments = comments' })
method type_identifier (id : ('loc, 'loc) Ast.Identifier.t) = this#identifier id
method type_identifier_reference (id : ('loc, 'loc) Ast.Identifier.t) = this#type_identifier id
method binding_type_identifier (id : ('loc, 'loc) Ast.Identifier.t) = this#type_identifier id
method interface _loc (interface : ('loc, 'loc) Ast.Statement.Interface.t) =
let open Ast.Statement.Interface in
let { id = ident; tparams; extends; body; } = interface in
let id' = this#binding_type_identifier ident in
let tparams' = map_opt this#type_params tparams in
let extends' = map_list (map_loc this#generic_type) extends in
let body' = map_loc this#object_type body in
let = this#syntax_opt comments in
if
id' == ident
&& tparams' == tparams
&& extends' == extends
&& body' == body
&& comments' == comments
then
interface
else
{ id = id'; tparams = tparams'; extends = extends'; body = body'; comments = comments' }
method interface_declaration loc (decl : ('loc, 'loc) Ast.Statement.Interface.t) =
this#interface loc decl
method private_name (id : 'loc Ast.PrivateName.t) =
let open Ast.PrivateName in
let (loc, { name; }) = id in
let = this#syntax_opt comments in
if comments == comments' then
id
else
(loc, { name; comments = comments' })
method computed_key (key : ('loc, 'loc) Ast.ComputedKey.t) =
let open Ast.ComputedKey in
let (loc, { expression; }) = key in
let expression' = this#expression expression in
let = this#syntax_opt comments in
if expression == expression' && comments == comments' then
key
else
(loc, { expression = expression'; comments = comments' })
method import _loc (expr : ('loc, 'loc) Ast.Expression.Import.t) =
let open Ast.Expression.Import in
let { argument; } = expr in
let argument' = this#expression argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
expr
else
{ argument = argument'; comments = comments' }
method if_consequent_statement ~has_else (stmt : ('loc, 'loc) Ast.Statement.t) =
ignore has_else;
this#statement stmt
method if_alternate_statement _loc (altern : ('loc, 'loc) Ast.Statement.If.Alternate.t') =
let open Ast.Statement.If.Alternate in
let { body; } = altern in
let body' = this#statement body in
let = this#syntax_opt comments in
if body == body' && comments == comments' then
altern
else
{ body = body'; comments = comments' }
method if_statement _loc (stmt : ('loc, 'loc) Ast.Statement.If.t) =
let open Ast.Statement.If in
let { test; consequent; alternate; } = stmt in
let test' = this#predicate_expression test in
let consequent' = this#if_consequent_statement ~has_else:(alternate <> None) consequent in
let alternate' = map_opt (map_loc this#if_alternate_statement) alternate in
let = this#syntax_opt comments in
if
test == test'
&& consequent == consequent'
&& alternate == alternate'
&& comments == comments'
then
stmt
else
{ test = test'; consequent = consequent'; alternate = alternate'; comments = comments' }
method import_declaration _loc (decl : ('loc, 'loc) Ast.Statement.ImportDeclaration.t) =
let open Ast.Statement.ImportDeclaration in
let { import_kind; source; specifiers; default; } = decl in
let source' = map_loc this#import_source source in
let specifiers' = map_opt (this#import_specifier ~import_kind) specifiers in
let default' =
map_opt
(fun ({ identifier; remote_default_name_def_loc } as id) ->
let identifier' = this#import_default_specifier ~import_kind identifier in
if identifier' == identifier then
id
else
{ identifier = identifier'; remote_default_name_def_loc })
default
in
let = this#syntax_opt comments in
if
source == source'
&& specifiers == specifiers'
&& default == default'
&& comments == comments'
then
decl
else
{
import_kind;
source = source';
specifiers = specifiers';
default = default';
comments = comments';
}
method import_source _loc (source : 'loc Ast.StringLiteral.t) =
let open Ast.StringLiteral in
let { value; raw; } = source in
let = this#syntax_opt comments in
if comments == comments' then
source
else
{ value; raw; comments = comments' }
method import_specifier
~import_kind (specifier : ('loc, 'loc) Ast.Statement.ImportDeclaration.specifier) =
let open Ast.Statement.ImportDeclaration in
match specifier with
| ImportNamedSpecifiers named_specifiers ->
let named_specifiers' =
map_list (this#import_named_specifier ~import_kind) named_specifiers
in
if named_specifiers == named_specifiers' then
specifier
else
ImportNamedSpecifiers named_specifiers'
| ImportNamespaceSpecifier (loc, ident) ->
id_loc (this#import_namespace_specifier ~import_kind) loc ident specifier (fun ident ->
ImportNamespaceSpecifier (loc, ident)
)
method remote_identifier id = this#identifier id
method import_named_specifier
~(import_kind : Ast.Statement.ImportDeclaration.import_kind)
(specifier : ('loc, 'loc) Ast.Statement.ImportDeclaration.named_specifier) =
let open Ast.Statement.ImportDeclaration in
let { kind; local; remote; remote_name_def_loc } = specifier in
let (is_type_remote, is_type_local) =
match (import_kind, kind) with
| (ImportType, _)
| (_, Some ImportType) ->
(true, true)
| (ImportTypeof, _)
| (_, Some ImportTypeof) ->
(false, true)
| _ -> (false, false)
in
let remote' =
match local with
| None ->
if is_type_remote then
this#binding_type_identifier remote
else
this#pattern_identifier ~kind:Ast.Variable.Let remote
| Some _ -> this#remote_identifier remote
in
let local' =
match local with
| None -> None
| Some ident ->
let local_visitor =
if is_type_local then
this#binding_type_identifier
else
this#pattern_identifier ~kind:Ast.Variable.Let
in
id local_visitor ident local (fun ident -> Some ident)
in
if local == local' && remote == remote' then
specifier
else
{ kind; local = local'; remote = remote'; remote_name_def_loc }
method import_default_specifier ~import_kind (id : ('loc, 'loc) Ast.Identifier.t) =
let open Ast.Statement.ImportDeclaration in
let local_visitor =
match import_kind with
| ImportType
| ImportTypeof ->
this#binding_type_identifier
| _ -> this#pattern_identifier ~kind:Ast.Variable.Let
in
local_visitor id
method import_namespace_specifier ~import_kind _loc (id : ('loc, 'loc) Ast.Identifier.t) =
let open Ast.Statement.ImportDeclaration in
let local_visitor =
match import_kind with
| ImportType
| ImportTypeof ->
this#binding_type_identifier
| _ -> this#pattern_identifier ~kind:Ast.Variable.Let
in
local_visitor id
method jsx_element _loc (expr : ('loc, 'loc) Ast.JSX.element) =
let open Ast.JSX in
let { opening_element; closing_element; children; } = expr in
let opening_element' = this#jsx_opening_element opening_element in
let closing_element' = map_opt this#jsx_closing_element closing_element in
let children' = this#jsx_children children in
let = this#syntax_opt comments in
if
opening_element == opening_element'
&& closing_element == closing_element'
&& children == children'
&& comments == comments'
then
expr
else
{
opening_element = opening_element';
closing_element = closing_element';
children = children';
comments = comments';
}
method jsx_fragment _loc (expr : ('loc, 'loc) Ast.JSX.fragment) =
let open Ast.JSX in
let { frag_children; ; _ } = expr in
let children' = this#jsx_children frag_children in
let = this#syntax_opt frag_comments in
if frag_children == children' && frag_comments == frag_comments' then
expr
else
{ expr with frag_children = children'; frag_comments = frag_comments' }
method jsx_opening_element (elem : ('loc, 'loc) Ast.JSX.Opening.t) =
let open Ast.JSX.Opening in
let (loc, { name; targs; self_closing; attributes }) = elem in
let name' = this#jsx_element_name name in
let targs' = map_opt this#call_type_args targs in
let attributes' = map_list this#jsx_opening_attribute attributes in
if name == name' && targs == targs' && attributes == attributes' then
elem
else
(loc, { name = name'; targs = targs'; self_closing; attributes = attributes' })
method jsx_closing_element (elem : ('loc, 'loc) Ast.JSX.Closing.t) =
let open Ast.JSX.Closing in
let (loc, { name }) = elem in
let name' = this#jsx_element_name name in
if name == name' then
elem
else
(loc, { name = name' })
method jsx_opening_attribute (jsx_attr : ('loc, 'loc) Ast.JSX.Opening.attribute) =
let open Ast.JSX.Opening in
match jsx_attr with
| Attribute attr -> id this#jsx_attribute attr jsx_attr (fun attr -> Attribute attr)
| SpreadAttribute (loc, attr) ->
id_loc this#jsx_spread_attribute loc attr jsx_attr (fun attr -> SpreadAttribute (loc, attr))
method jsx_spread_attribute _loc (attr : ('loc, 'loc) Ast.JSX.SpreadAttribute.t') =
let open Ast.JSX.SpreadAttribute in
let { argument; } = attr in
let argument' = this#expression argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
attr
else
{ argument = argument'; comments = comments' }
method jsx_attribute (attr : ('loc, 'loc) Ast.JSX.Attribute.t) =
let open Ast.JSX.Attribute in
let (loc, { name; value }) = attr in
let name' = this#jsx_attribute_name name in
let value' = map_opt this#jsx_attribute_value value in
if name == name' && value == value' then
attr
else
(loc, { name = name'; value = value' })
method jsx_attribute_name (name : ('loc, 'loc) Ast.JSX.Attribute.name) =
let open Ast.JSX.Attribute in
match name with
| Identifier ident ->
id this#jsx_attribute_name_identifier ident name (fun ident -> Identifier ident)
| NamespacedName ns ->
id this#jsx_attribute_name_namespaced ns name (fun ns -> NamespacedName ns)
method jsx_attribute_name_identifier ident = this#jsx_identifier ident
method jsx_attribute_name_namespaced ns = this#jsx_namespaced_name ns
method jsx_attribute_value (value : ('loc, 'loc) Ast.JSX.Attribute.value) =
let open Ast.JSX.Attribute in
match value with
| StringLiteral (loc, lit) ->
id_loc this#jsx_attribute_value_literal loc lit value (fun lit -> StringLiteral (loc, lit))
| ExpressionContainer (loc, expr) ->
id_loc this#jsx_attribute_value_expression loc expr value (fun expr ->
ExpressionContainer (loc, expr)
)
method jsx_attribute_value_expression loc (jsx_expr : ('loc, 'loc) Ast.JSX.ExpressionContainer.t)
=
this#jsx_expression loc jsx_expr
method jsx_attribute_value_literal loc (lit : 'loc Ast.StringLiteral.t) =
this#string_literal loc lit
method jsx_children ((loc, children) as orig : 'loc * ('loc, 'loc) Ast.JSX.child list) =
let children' = map_list this#jsx_child children in
if children == children' then
orig
else
(loc, children')
method jsx_child (child : ('loc, 'loc) Ast.JSX.child) =
let open Ast.JSX in
match child with
| (loc, Element elem) ->
id_loc this#jsx_element loc elem child (fun elem -> (loc, Element elem))
| (loc, Fragment frag) ->
id_loc this#jsx_fragment loc frag child (fun frag -> (loc, Fragment frag))
| (loc, ExpressionContainer expr) ->
id_loc this#jsx_expression loc expr child (fun expr -> (loc, ExpressionContainer expr))
| (loc, SpreadChild spread) ->
id this#jsx_spread_child spread child (fun spread -> (loc, SpreadChild spread))
| (_loc, Text _) -> child
method jsx_expression _loc (jsx_expr : ('loc, 'loc) Ast.JSX.ExpressionContainer.t) =
let open Ast.JSX.ExpressionContainer in
let { expression; } = jsx_expr in
let = this#syntax_opt comments in
match expression with
| Expression expr ->
let expr' = this#expression expr in
if expr == expr' && comments == comments' then
jsx_expr
else
{ expression = Expression expr'; comments = comments' }
| EmptyExpression ->
if comments == comments' then
jsx_expr
else
{ expression = EmptyExpression; comments = comments' }
method jsx_spread_child (jsx_spread_child : ('loc, 'loc) Ast.JSX.SpreadChild.t) =
let open Ast.JSX.SpreadChild in
let { expression; } = jsx_spread_child in
let expression' = this#expression expression in
let = this#syntax_opt comments in
if expression == expression' && comments == comments' then
jsx_spread_child
else
{ expression = expression'; comments = comments' }
method jsx_element_name (name : ('loc, 'loc) Ast.JSX.name) =
let open Ast.JSX in
match name with
| Identifier ident ->
id this#jsx_element_name_identifier ident name (fun ident -> Identifier ident)
| NamespacedName ns ->
id this#jsx_element_name_namespaced ns name (fun ns -> NamespacedName ns)
| MemberExpression expr ->
id this#jsx_element_name_member_expression expr name (fun expr -> MemberExpression expr)
method jsx_element_name_identifier ident = this#jsx_identifier ident
method jsx_element_name_namespaced ns = this#jsx_namespaced_name ns
method jsx_element_name_member_expression expr = this#jsx_member_expression expr
method jsx_namespaced_name (namespaced_name : ('loc, 'loc) Ast.JSX.NamespacedName.t) =
let open Ast.JSX in
NamespacedName.(
let (loc, { namespace; name }) = namespaced_name in
let namespace' = this#jsx_identifier namespace in
let name' = this#jsx_identifier name in
if namespace == namespace' && name == name' then
namespaced_name
else
(loc, { namespace = namespace'; name = name' })
)
method jsx_member_expression (member_exp : ('loc, 'loc) Ast.JSX.MemberExpression.t) =
let open Ast.JSX in
let (loc, { MemberExpression._object; MemberExpression.property }) = member_exp in
let _object' = this#jsx_member_expression_object _object in
let property' = this#jsx_identifier property in
if _object == _object' && property == property' then
member_exp
else
(loc, MemberExpression.{ _object = _object'; property = property' })
method jsx_member_expression_object (_object : ('loc, 'loc) Ast.JSX.MemberExpression._object) =
let open Ast.JSX.MemberExpression in
match _object with
| Identifier ident ->
id this#jsx_member_expression_identifier ident _object (fun ident -> Identifier ident)
| MemberExpression nested_exp ->
id this#jsx_member_expression nested_exp _object (fun exp -> MemberExpression exp)
method jsx_member_expression_identifier ident = this#jsx_element_name_identifier ident
method jsx_identifier (id : ('loc, 'loc) Ast.JSX.Identifier.t) =
let open Ast.JSX.Identifier in
let (loc, { name; }) = id in
let = this#syntax_opt comments in
if comments == comments' then
id
else
(loc, { name; comments = comments' })
method labeled_statement _loc (stmt : ('loc, 'loc) Ast.Statement.Labeled.t) =
let open Ast.Statement.Labeled in
let { label; body; } = stmt in
let label' = this#label_identifier label in
let body' = this#statement body in
let = this#syntax_opt comments in
if label == label' && body == body' && comments == comments' then
stmt
else
{ label = label'; body = body'; comments = comments' }
method logical _loc (expr : ('loc, 'loc) Ast.Expression.Logical.t) =
let open Ast.Expression.Logical in
let { operator = _; left; right; } = expr in
let left' = this#expression left in
let right' = this#expression right in
let = this#syntax_opt comments in
if left == left' && right == right' && comments == comments' then
expr
else
{ expr with left = left'; right = right'; comments = comments' }
method member _loc (expr : ('loc, 'loc) Ast.Expression.Member.t) =
let open Ast.Expression.Member in
let { _object; property; } = expr in
let _object' = this#expression _object in
let property' = this#member_property property in
let = this#syntax_opt comments in
if _object == _object' && property == property' && comments == comments' then
expr
else
{ _object = _object'; property = property'; comments = comments' }
method optional_member loc (expr : ('loc, 'loc) Ast.Expression.OptionalMember.t) =
let open Ast.Expression.OptionalMember in
let { member; optional = _; filtered_out = _ } = expr in
let member' = this#member loc member in
if member == member' then
expr
else
{ expr with member = member' }
method member_property (expr : ('loc, 'loc) Ast.Expression.Member.property) =
let open Ast.Expression.Member in
match expr with
| PropertyIdentifier ident ->
id this#member_property_identifier ident expr (fun ident -> PropertyIdentifier ident)
| PropertyPrivateName ident ->
id this#member_private_name ident expr (fun ident -> PropertyPrivateName ident)
| PropertyExpression e ->
id this#member_property_expression e expr (fun e -> PropertyExpression e)
method member_property_identifier (ident : ('loc, 'loc) Ast.Identifier.t) =
this#identifier ident
method member_private_name (name : 'loc Ast.PrivateName.t) = this#private_name name
method member_property_expression (expr : ('loc, 'loc) Ast.Expression.t) = this#expression expr
method meta_property _loc (expr : 'loc Ast.Expression.MetaProperty.t) =
let open Ast.Expression.MetaProperty in
let { meta; property; } = expr in
let meta' = this#identifier meta in
let property' = this#identifier property in
let = this#syntax_opt comments in
if meta == meta' && property == property' && comments == comments' then
expr
else
{ meta = meta'; property = property'; comments = comments' }
method new_ _loc (expr : ('loc, 'loc) Ast.Expression.New.t) =
let open Ast.Expression.New in
let { callee; targs; arguments; } = expr in
let callee' = this#expression callee in
let targs' = map_opt this#call_type_args targs in
let arguments' = map_opt this#arg_list arguments in
let = this#syntax_opt comments in
if callee == callee' && targs == targs' && arguments == arguments' && comments == comments'
then
expr
else
{ callee = callee'; targs = targs'; arguments = arguments'; comments = comments' }
method object_ _loc (expr : ('loc, 'loc) Ast.Expression.Object.t) =
let open Ast.Expression.Object in
let { properties; } = expr in
let properties' =
map_list
(fun prop ->
match prop with
| Property p ->
let p' = this#object_property p in
if p == p' then
prop
else
Property p'
| SpreadProperty s ->
let s' = this#spread_property s in
if s == s' then
prop
else
SpreadProperty s')
properties
in
let = this#syntax_opt comments in
if properties == properties' && comments == comments' then
expr
else
{ properties = properties'; comments = comments' }
method object_property (prop : ('loc, 'loc) Ast.Expression.Object.Property.t) =
let open Ast.Expression.Object.Property in
match prop with
| (loc, Init { key; value; shorthand }) ->
let key' = this#object_key key in
let value' = this#expression value in
let shorthand' =
shorthand
&&
match (key', value') with
| ( Identifier (_, { Ast.Identifier.name = key_name; _ }),
(_, Ast.Expression.Identifier (_, { Ast.Identifier.name = value_name; _ }))
) ->
String.equal key_name value_name
| _ -> key == key' && value == value'
in
if key == key' && value == value' && shorthand == shorthand' then
prop
else
(loc, Init { key = key'; value = value'; shorthand = shorthand' })
| (loc, Method { key; value = fn }) ->
let key' = this#object_key key in
let fn' = map_loc this#function_expression_or_method fn in
if key == key' && fn == fn' then
prop
else
(loc, Method { key = key'; value = fn' })
| (loc, Get { key; value = fn; }) ->
let key' = this#object_key key in
let fn' = map_loc this#function_expression_or_method fn in
let = this#syntax_opt comments in
if key == key' && fn == fn' && comments == comments' then
prop
else
(loc, Get { key = key'; value = fn'; comments = comments' })
| (loc, Set { key; value = fn; }) ->
let key' = this#object_key key in
let fn' = map_loc this#function_expression_or_method fn in
let = this#syntax_opt comments in
if key == key' && fn == fn' && comments == comments' then
prop
else
(loc, Set { key = key'; value = fn'; comments = comments' })
method object_key (key : ('loc, 'loc) Ast.Expression.Object.Property.key) =
let open Ast.Expression.Object.Property in
match key with
| StringLiteral lit -> id this#object_key_string_literal lit key (fun lit -> StringLiteral lit)
| NumberLiteral lit -> id this#object_key_number_literal lit key (fun lit -> NumberLiteral lit)
| BigIntLiteral lit -> id this#object_key_bigint_literal lit key (fun lit -> BigIntLiteral lit)
| Identifier ident -> id this#object_key_identifier ident key (fun ident -> Identifier ident)
| PrivateName ident -> id this#private_name ident key (fun ident -> PrivateName ident)
| Computed computed -> id this#object_key_computed computed key (fun expr -> Computed expr)
method object_key_string_literal (literal : 'loc * 'loc Ast.StringLiteral.t) =
let (loc, lit) = literal in
id_loc this#string_literal loc lit literal (fun lit -> (loc, lit))
method object_key_number_literal (literal : 'loc * 'loc Ast.NumberLiteral.t) =
let (loc, lit) = literal in
id_loc this#number_literal loc lit literal (fun lit -> (loc, lit))
method object_key_bigint_literal (literal : 'loc * 'loc Ast.BigIntLiteral.t) =
let (loc, lit) = literal in
id_loc this#bigint_literal loc lit literal (fun lit -> (loc, lit))
method object_key_identifier (ident : ('loc, 'loc) Ast.Identifier.t) = this#identifier ident
method object_key_computed (key : ('loc, 'loc) Ast.ComputedKey.t) = this#computed_key key
method opaque_type _loc (otype : ('loc, 'loc) Ast.Statement.OpaqueType.t) =
let open Ast.Statement.OpaqueType in
let { id; tparams; impltype; supertype; } = otype in
let id' = this#binding_type_identifier id in
let tparams' = map_opt this#type_params tparams in
let impltype' = map_opt this#type_ impltype in
let supertype' = map_opt this#type_ supertype in
let = this#syntax_opt comments in
if
id == id'
&& impltype == impltype'
&& tparams == tparams'
&& impltype == impltype'
&& supertype == supertype'
&& comments == comments'
then
otype
else
{
id = id';
tparams = tparams';
impltype = impltype';
supertype = supertype';
comments = comments';
}
method function_param_pattern (expr : ('loc, 'loc) Ast.Pattern.t) =
this#binding_pattern ~kind:Ast.Variable.Let expr
method variable_declarator_pattern ~kind (expr : ('loc, 'loc) Ast.Pattern.t) =
this#binding_pattern ~kind expr
method catch_clause_pattern (expr : ('loc, 'loc) Ast.Pattern.t) =
this#binding_pattern ~kind:Ast.Variable.Let expr
method for_in_assignment_pattern (expr : ('loc, 'loc) Ast.Pattern.t) =
this#assignment_pattern expr
method for_of_assignment_pattern (expr : ('loc, 'loc) Ast.Pattern.t) =
this#assignment_pattern expr
method binding_pattern ?(kind = Ast.Variable.Var) (expr : ('loc, 'loc) Ast.Pattern.t) =
this#pattern ~kind expr
method assignment_pattern (expr : ('loc, 'loc) Ast.Pattern.t) = this#pattern expr
method pattern ?kind (expr : ('loc, 'loc) Ast.Pattern.t) =
let open Ast.Pattern in
let (loc, patt) = expr in
let patt' =
match patt with
| Object { Object.properties; annot; } ->
let properties' = map_list (this#pattern_object_p ?kind) properties in
let annot' = this#type_annotation_hint annot in
let = this#syntax_opt comments in
if properties' == properties && annot' == annot && comments' == comments then
patt
else
Object { Object.properties = properties'; annot = annot'; comments = comments' }
| Array { Array.elements; annot; } ->
let elements' = map_list (this#pattern_array_e ?kind) elements in
let annot' = this#type_annotation_hint annot in
let = this#syntax_opt comments in
if comments == comments' && elements' == elements && annot' == annot then
patt
else
Array { Array.elements = elements'; annot = annot'; comments = comments' }
| Identifier { Identifier.name; annot; optional } ->
let name' = this#pattern_identifier ?kind name in
let annot' = this#type_annotation_hint annot in
if name == name' && annot == annot' then
patt
else
Identifier { Identifier.name = name'; annot = annot'; optional }
| Expression e -> id this#pattern_expression e patt (fun e -> Expression e)
in
if patt == patt' then
expr
else
(loc, patt')
method pattern_identifier ?kind (ident : ('loc, 'loc) Ast.Identifier.t) =
ignore kind;
this#identifier ident
method pattern_string_literal ?kind loc (expr : 'loc Ast.StringLiteral.t) =
ignore kind;
this#string_literal loc expr
method pattern_number_literal ?kind loc (expr : 'loc Ast.NumberLiteral.t) =
ignore kind;
this#number_literal loc expr
method pattern_bigint_literal ?kind loc (expr : 'loc Ast.BigIntLiteral.t) =
ignore kind;
this#bigint_literal loc expr
method pattern_object_p ?kind (p : ('loc, 'loc) Ast.Pattern.Object.property) =
let open Ast.Pattern.Object in
match p with
| Property prop -> id (this#pattern_object_property ?kind) prop p (fun prop -> Property prop)
| RestElement prop ->
id (this#pattern_object_rest_property ?kind) prop p (fun prop -> RestElement prop)
method pattern_object_property ?kind (prop : ('loc, 'loc) Ast.Pattern.Object.Property.t) =
let open Ast.Pattern.Object.Property in
let (loc, { key; pattern; default; shorthand }) = prop in
let key' = this#pattern_object_property_key ?kind key in
let pattern' = this#pattern_object_property_pattern ?kind pattern in
let default' = this#default_opt default in
let shorthand' =
shorthand
&&
match (key', pattern') with
| ( Identifier (_, { Ast.Identifier.name = key_name; _ }),
( _,
Ast.Pattern.Identifier
{ Ast.Pattern.Identifier.name = (_, { Ast.Identifier.name = value_name; _ }); _ }
)
) ->
String.equal key_name value_name
| _ -> key == key' && pattern == pattern'
in
if key' == key && pattern' == pattern && default' == default && shorthand == shorthand' then
prop
else
(loc, { key = key'; pattern = pattern'; default = default'; shorthand = shorthand' })
method pattern_object_property_key ?kind (key : ('loc, 'loc) Ast.Pattern.Object.Property.key) =
let open Ast.Pattern.Object.Property in
match key with
| StringLiteral lit ->
id (this#pattern_object_property_string_literal_key ?kind) lit key (fun lit' ->
StringLiteral lit'
)
| NumberLiteral lit ->
id (this#pattern_object_property_number_literal_key ?kind) lit key (fun lit' ->
NumberLiteral lit'
)
| BigIntLiteral lit ->
id (this#pattern_object_property_bigint_literal_key ?kind) lit key (fun lit' ->
BigIntLiteral lit'
)
| Identifier identifier ->
id (this#pattern_object_property_identifier_key ?kind) identifier key (fun id' ->
Identifier id'
)
| Computed expr ->
id (this#pattern_object_property_computed_key ?kind) expr key (fun expr' -> Computed expr')
method pattern_object_property_string_literal_key
?kind (literal : 'loc * 'loc Ast.StringLiteral.t) =
let (loc, key) = literal in
id_loc (this#pattern_string_literal ?kind) loc key literal (fun key' -> (loc, key'))
method pattern_object_property_number_literal_key
?kind (literal : 'loc * 'loc Ast.NumberLiteral.t) =
let (loc, key) = literal in
id_loc (this#pattern_number_literal ?kind) loc key literal (fun key' -> (loc, key'))
method pattern_object_property_bigint_literal_key
?kind (literal : 'loc * 'loc Ast.BigIntLiteral.t) =
let (loc, key) = literal in
id_loc (this#pattern_bigint_literal ?kind) loc key literal (fun key' -> (loc, key'))
method pattern_object_property_identifier_key ?kind (key : ('loc, 'loc) Ast.Identifier.t) =
this#pattern_identifier ?kind key
method pattern_object_property_computed_key ?kind (key : ('loc, 'loc) Ast.ComputedKey.t) =
ignore kind;
this#computed_key key
method pattern_object_rest_property ?kind (prop : ('loc, 'loc) Ast.Pattern.RestElement.t) =
let open Ast.Pattern.RestElement in
let (loc, { argument; }) = prop in
let argument' = this#pattern_object_rest_property_pattern ?kind argument in
let = this#syntax_opt comments in
if argument' == argument && comments == comments' then
prop
else
(loc, { argument = argument'; comments = comments' })
method pattern_object_property_pattern ?kind (expr : ('loc, 'loc) Ast.Pattern.t) =
this#pattern ?kind expr
method pattern_object_rest_property_pattern ?kind (expr : ('loc, 'loc) Ast.Pattern.t) =
this#pattern ?kind expr
method pattern_array_e ?kind (e : ('loc, 'loc) Ast.Pattern.Array.element) =
let open Ast.Pattern.Array in
match e with
| Hole _ -> e
| Element elem -> id (this#pattern_array_element ?kind) elem e (fun elem -> Element elem)
| RestElement elem ->
id (this#pattern_array_rest_element ?kind) elem e (fun elem -> RestElement elem)
method pattern_array_element ?kind (elem : ('loc, 'loc) Ast.Pattern.Array.Element.t) =
let open Ast.Pattern.Array.Element in
let (loc, { argument; default }) = elem in
let argument' = this#pattern_array_element_pattern ?kind argument in
let default' = this#default_opt default in
if argument == argument' && default == default' then
elem
else
(loc, { argument = argument'; default = default' })
method pattern_array_element_pattern ?kind (patt : ('loc, 'loc) Ast.Pattern.t) =
this#pattern ?kind patt
method pattern_array_rest_element ?kind (elem : ('loc, 'loc) Ast.Pattern.RestElement.t) =
let open Ast.Pattern.RestElement in
let (loc, { argument; }) = elem in
let argument' = this#pattern_array_rest_element_pattern ?kind argument in
let = this#syntax_opt comments in
if argument' == argument && comments == comments' then
elem
else
(loc, { argument = argument'; comments = comments' })
method pattern_array_rest_element_pattern ?kind (expr : ('loc, 'loc) Ast.Pattern.t) =
this#pattern ?kind expr
method pattern_expression (expr : ('loc, 'loc) Ast.Expression.t) = this#expression expr
method predicate (pred : ('loc, 'loc) Ast.Type.Predicate.t) =
let open Ast.Type.Predicate in
let (loc, { kind; }) = pred in
let kind' =
match kind with
| Inferred -> kind
| Declared expr -> id this#expression expr kind (fun expr' -> Declared expr')
in
let = this#syntax_opt comments in
if kind == kind' && comments == comments' then
pred
else
(loc, { kind = kind'; comments = comments' })
method predicate_expression (expr : ('loc, 'loc) Ast.Expression.t) = this#expression expr
method type_guard_annotation
(type_guard_annotation : ('loc, 'loc) Ast.Type.type_guard_annotation) =
let (loc, type_guard) = type_guard_annotation in
let type_guard' = this#type_guard type_guard in
if type_guard' = type_guard then
type_guard_annotation
else
(loc, type_guard')
method type_guard (guard : ('loc, 'loc) Ast.Type.TypeGuard.t) =
let open Ast.Type.TypeGuard in
let (loc, { asserts; guard = (x, t); }) = guard in
let x' = this#identifier x in
let t' = map_opt this#type_ t in
let = this#syntax_opt comments in
if x' == x && t' == t && comments' == comments then
guard
else
(loc, { asserts; guard = (x', t'); comments = comments' })
method function_rest_param (expr : ('loc, 'loc) Ast.Function.RestParam.t) =
let open Ast.Function.RestParam in
let (loc, { argument; }) = expr in
let argument' = this#function_param_pattern argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
expr
else
(loc, { argument = argument'; comments = comments' })
method return _loc (stmt : ('loc, 'loc) Ast.Statement.Return.t) =
let open Ast.Statement.Return in
let { argument; ; return_out } = stmt in
let argument' = map_opt this#expression argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
stmt
else
{ argument = argument'; comments = comments'; return_out }
method sequence _loc (expr : ('loc, 'loc) Ast.Expression.Sequence.t) =
let open Ast.Expression.Sequence in
let { expressions; } = expr in
let expressions' = map_list this#expression expressions in
let = this#syntax_opt comments in
if expressions == expressions' && comments == comments' then
expr
else
{ expressions = expressions'; comments = comments' }
method toplevel_statement_list (stmts : ('loc, 'loc) Ast.Statement.t list) =
this#statement_list stmts
method statement_list (stmts : ('loc, 'loc) Ast.Statement.t list) =
map_list_multiple this#statement_fork_point stmts
method statement_fork_point (stmt : ('loc, 'loc) Ast.Statement.t) = [this#statement stmt]
method spread_element (expr : ('loc, 'loc) Ast.Expression.SpreadElement.t) =
let open Ast.Expression.SpreadElement in
let (loc, { argument; }) = expr in
let argument' = this#expression argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
expr
else
(loc, { argument = argument'; comments = comments' })
method spread_property (expr : ('loc, 'loc) Ast.Expression.Object.SpreadProperty.t) =
let open Ast.Expression.Object.SpreadProperty in
let (loc, { argument; }) = expr in
let argument' = this#expression argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
expr
else
(loc, { argument = argument'; comments = comments' })
method super_expression _loc (expr : 'loc Ast.Expression.Super.t) =
let open Ast.Expression.Super in
let { } = expr in
let = this#syntax_opt comments in
if comments == comments' then
expr
else
{ comments = comments' }
method switch _loc (switch : ('loc, 'loc) Ast.Statement.Switch.t) =
let open Ast.Statement.Switch in
let { discriminant; cases; ; exhaustive_out } = switch in
let discriminant' = this#expression discriminant in
let cases' = map_list this#switch_case cases in
let = this#syntax_opt comments in
if discriminant == discriminant' && cases == cases' && comments == comments' then
switch
else
{ discriminant = discriminant'; cases = cases'; comments = comments'; exhaustive_out }
method switch_case (case : ('loc, 'loc) Ast.Statement.Switch.Case.t) =
let open Ast.Statement.Switch.Case in
let (loc, { test; consequent; }) = case in
let test' = map_opt this#expression test in
let consequent' = this#statement_list consequent in
let = this#syntax_opt comments in
if test == test' && consequent == consequent' && comments == comments' then
case
else
(loc, { test = test'; consequent = consequent'; comments = comments' })
method tagged_template _loc (expr : ('loc, 'loc) Ast.Expression.TaggedTemplate.t) =
let open Ast.Expression.TaggedTemplate in
let { tag; quasi; } = expr in
let tag' = this#expression tag in
let quasi' = map_loc this#template_literal quasi in
let = this#syntax_opt comments in
if tag == tag' && quasi == quasi' && comments == comments' then
expr
else
{ tag = tag'; quasi = quasi'; comments = comments' }
method template_literal _loc (expr : ('loc, 'loc) Ast.Expression.TemplateLiteral.t) =
let open Ast.Expression.TemplateLiteral in
let { quasis; expressions; } = expr in
let quasis' = map_list this#template_literal_element quasis in
let expressions' = map_list this#expression expressions in
let = this#syntax_opt comments in
if quasis == quasis' && expressions == expressions' && comments == comments' then
expr
else
{ quasis = quasis'; expressions = expressions'; comments = comments' }
method template_literal_element (elem : 'loc Ast.Expression.TemplateLiteral.Element.t) = elem
method this_expression _loc (expr : 'loc Ast.Expression.This.t) =
let open Ast.Expression.This in
let { } = expr in
let = this#syntax_opt comments in
if comments == comments' then
expr
else
{ comments = comments' }
method throw _loc (stmt : ('loc, 'loc) Ast.Statement.Throw.t) =
let open Ast.Statement.Throw in
let { argument; } = stmt in
let argument' = this#expression argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
stmt
else
{ argument = argument'; comments = comments' }
method try_catch _loc (stmt : ('loc, 'loc) Ast.Statement.Try.t) =
let open Ast.Statement.Try in
let { block; handler; finalizer; } = stmt in
let block' = map_loc this#block block in
let handler' =
match handler with
| Some (loc, clause) ->
id_loc this#catch_clause loc clause handler (fun clause -> Some (loc, clause))
| None -> handler
in
let finalizer' =
match finalizer with
| Some (finalizer_loc, block) ->
id_loc this#block finalizer_loc block finalizer (fun block -> Some (finalizer_loc, block))
| None -> finalizer
in
let = this#syntax_opt comments in
if block == block' && handler == handler' && finalizer == finalizer' && comments == comments'
then
stmt
else
{ block = block'; handler = handler'; finalizer = finalizer'; comments = comments' }
method type_cast _loc (expr : ('loc, 'loc) Ast.Expression.TypeCast.t) =
let open Ast.Expression.TypeCast in
let { expression; annot; } = expr in
let expression' = this#expression expression in
let annot' = this#type_annotation annot in
let = this#syntax_opt comments in
if expression' == expression && annot' == annot && comments' == comments then
expr
else
{ expression = expression'; annot = annot'; comments = comments' }
method ts_type_cast _loc (expr : ('loc, 'loc) Ast.Expression.TSTypeCast.t) =
let open Ast.Expression.TSTypeCast in
let { expression; kind; } = expr in
let expression' = this#expression expression in
let kind' =
match kind with
| AsConst -> kind
| Satisfies annot ->
let annot' = this#type_ annot in
if annot == annot' then
kind
else
Satisfies annot'
in
let = this#syntax_opt comments in
if expression' == expression && comments' == comments then
expr
else
{ expression = expression'; kind = kind'; comments = comments' }
method unary_expression _loc (expr : ('loc, 'loc) Flow_ast.Expression.Unary.t) =
let open Flow_ast.Expression.Unary in
let { argument; operator = _; } = expr in
let argument' = this#expression argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
expr
else
{ expr with argument = argument'; comments = comments' }
method update_expression _loc (expr : ('loc, 'loc) Ast.Expression.Update.t) =
let open Ast.Expression.Update in
let { argument; operator = _; prefix = _; } = expr in
let argument' = this#expression argument in
let = this#syntax_opt comments in
if argument == argument' && comments == comments' then
expr
else
{ expr with argument = argument'; comments = comments' }
method variable_declaration _loc (decl : ('loc, 'loc) Ast.Statement.VariableDeclaration.t) =
let open Ast.Statement.VariableDeclaration in
let { declarations; kind; } = decl in
let decls' = map_list (this#variable_declarator ~kind) declarations in
let = this#syntax_opt comments in
if declarations == decls' && comments == comments' then
decl
else
{ declarations = decls'; kind; comments = comments' }
method variable_declarator
~kind (decl : ('loc, 'loc) Ast.Statement.VariableDeclaration.Declarator.t) =
let open Ast.Statement.VariableDeclaration.Declarator in
let (loc, { id; init }) = decl in
let id' = this#variable_declarator_pattern ~kind id in
let init' = map_opt this#expression init in
if id == id' && init == init' then
decl
else
(loc, { id = id'; init = init' })
method while_ _loc (stuff : ('loc, 'loc) Ast.Statement.While.t) =
let open Ast.Statement.While in
let { test; body; } = stuff in
let test' = this#predicate_expression test in
let body' = this#statement body in
let = this#syntax_opt comments in
if test == test' && body == body' && comments == comments' then
stuff
else
{ test = test'; body = body'; comments = comments' }
method with_ _loc (stuff : ('loc, 'loc) Ast.Statement.With.t) =
let open Ast.Statement.With in
let { _object; body; } = stuff in
let _object' = this#expression _object in
let body' = this#statement body in
let = this#syntax_opt comments in
if _object == _object' && body == body' && comments == comments' then
stuff
else
{ _object = _object'; body = body'; comments = comments' }
method type_alias _loc (stuff : ('loc, 'loc) Ast.Statement.TypeAlias.t) =
let open Ast.Statement.TypeAlias in
let { id; tparams; right; } = stuff in
let id' = this#binding_type_identifier id in
let tparams' = map_opt this#type_params tparams in
let right' = this#type_ right in
let = this#syntax_opt comments in
if id == id' && right == right' && tparams == tparams' && comments == comments' then
stuff
else
{ id = id'; tparams = tparams'; right = right'; comments = comments' }
method yield _loc (expr : ('loc, 'loc) Ast.Expression.Yield.t) =
let open Ast.Expression.Yield in
let { argument; delegate; ; result_out } = expr in
let argument' = map_opt this#expression argument in
let = this#syntax_opt comments in
if comments == comments' && argument == argument' then
expr
else
{ argument = argument'; delegate; comments = comments'; result_out }
end
let fold_program (mappers : 'a mapper list) ast =
List.fold_left (fun ast (m : 'a mapper) -> m#program ast) ast mappers