genkit 0.3.1

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

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          )
        )
      captures:
        1: storage.modifier.async.ts
      push:
        - meta_scope: meta.arrow.ts
        - match: '(?==>|\{|(^\s*(export|function|class|interface|let|var|const|import|enum|namespace|module|type|abstract|declare)\s+))'
          pop: true
        - include: comment
        - include: type-parameters
        - include: function-parameters
        - include: arrow-return-type
        - include: possibly-arrow-return-type
    - match: "=>"
      captures:
        0: storage.type.function.arrow.ts
      push:
        - meta_scope: meta.arrow.ts
        - match: '((?<=\}|\S)(?<!=>)|((?!\{)(?=\S)))(?!\/[\/\*])'
          pop: true
        - include: single-line-comment-consuming-line-ending
        - include: decl-block
        - include: expression
  arrow-return-type:
    - match: (?<=\))\s*(:)
      captures:
        1: keyword.operator.type.annotation.ts
      push:
        - meta_scope: meta.return.type.arrow.ts
        - match: '(?==>|\{|(^\s*(export|function|class|interface|let|var|const|import|enum|namespace|module|type|abstract|declare)\s+))'
          pop: true
        - include: arrow-return-type-body
  arrow-return-type-body:
    - match: '(?<=[:])(?=\s*\{)'
      push:
        - match: '(?<=\})'
          pop: true
        - include: type-object
    - include: type-predicate-operator
    - include: type
  async-modifier:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(async)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: storage.modifier.async.ts
  binding-element:
    - include: comment
    - include: string
    - include: numeric-literal
    - include: regex
    - include: object-binding-pattern
    - include: array-binding-pattern
    - include: destructuring-variable-rest
    - include: variable-initializer
  binding-element-const:
    - include: comment
    - include: string
    - include: numeric-literal
    - include: regex
    - include: object-binding-pattern-const
    - include: array-binding-pattern-const
    - include: destructuring-variable-rest-const
    - include: variable-initializer
  boolean-literal:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))true(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: constant.language.boolean.true.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))false(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: constant.language.boolean.false.ts
  brackets:
    - match: "{"
      push:
        - match: '}|(?=\*/)'
          pop: true
        - include: brackets
    - match: '\['
      push:
        - match: '\]|(?=\*/)'
          pop: true
        - include: brackets
  cast:
    - match: \s*(<)\s*(const)\s*(>)
      scope: cast.expr.ts
      captures:
        1: meta.brace.angle.ts
        2: storage.modifier.ts
        3: meta.brace.angle.ts
    - match: '(?:(?<!\+\+|--)(?<=^return|[^\._$[:alnum:]]return|^throw|[^\._$[:alnum:]]throw|^yield|[^\._$[:alnum:]]yield|^await|[^\._$[:alnum:]]await|^default|[^\._$[:alnum:]]default|[=(,:>*?\&\|\^]|[^_$[:alnum:]](?:\+\+|\-\-)|[^\+]\+|[^\-]\-))\s*(<)(?!<?\=)(?!\s*$)'
      captures:
        1: meta.brace.angle.ts
      push:
        - meta_scope: cast.expr.ts
        - match: (\>)
          captures:
            1: meta.brace.angle.ts
          pop: true
        - include: type
    - match: '(?:(?<=^))\s*(<)(?=[_$[:alpha:]][_$[:alnum:]]*\s*>)'
      captures:
        1: meta.brace.angle.ts
      push:
        - meta_scope: cast.expr.ts
        - match: (\>)
          captures:
            1: meta.brace.angle.ts
          pop: true
        - include: type
  class-declaration:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(?:(abstract)\s+)?\b(class)\b(?=\s+|/[/*])'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: storage.modifier.ts
        4: storage.type.class.ts
      push:
        - meta_scope: meta.class.ts
        - match: '(?<=\})'
          pop: true
        - include: class-declaration-or-expression-patterns
  class-declaration-or-expression-patterns:
    - include: comment
    - include: class-or-interface-heritage
    - match: "[_$[:alpha:]][_$[:alnum:]]*"
      captures:
        0: entity.name.type.class.ts
    - include: type-parameters
    - include: class-or-interface-body
  class-expression:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(abstract)\s+)?(class)\b(?=\s+|[<{]|\/[\/*])'
      captures:
        1: storage.modifier.ts
        2: storage.type.class.ts
      push:
        - meta_scope: meta.class.ts
        - match: '(?<=\})'
          pop: true
        - include: class-declaration-or-expression-patterns
  class-or-interface-body:
    - match: '\{'
      captures:
        0: punctuation.definition.block.ts
      push:
        - match: '\}'
          captures:
            0: punctuation.definition.block.ts
          pop: true
        - include: comment
        - include: decorator
        - match: (?<=:)\s*
          push:
            - match: '(?=\s|[;),}\]:\-\+]|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))'
              pop: true
            - include: expression
        - include: method-declaration
        - include: indexer-declaration
        - include: field-declaration
        - include: string
        - include: type-annotation
        - include: variable-initializer
        - include: access-modifier
        - include: property-accessor
        - include: async-modifier
        - include: after-operator-block-as-object-literal
        - include: decl-block
        - include: expression
        - include: punctuation-comma
        - include: punctuation-semicolon
  class-or-interface-heritage:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:\b(extends|implements)\b)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      captures:
        1: storage.modifier.ts
      push:
        - match: '(?=\{)'
          pop: true
        - include: comment
        - include: class-or-interface-heritage
        - include: type-parameters
        - include: expressionWithoutIdentifiers
        - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))(?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s*\??\.\s*[_$[:alpha:]][_$[:alnum:]]*)*\s*)'
          captures:
            1: entity.name.type.module.ts
            2: punctuation.accessor.ts
            3: punctuation.accessor.optional.ts
        - match: "([_$[:alpha:]][_$[:alnum:]]*)"
          captures:
            1: entity.other.inherited-class.ts
        - include: expressionPunctuations
  control-statement:
    - include: switch-statement
    - include: for-loop
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(catch|finally|throw|try)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.control.trycatch.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(break|continue|goto)\s+([_$[:alpha:]][_$[:alnum:]]*)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      captures:
        1: keyword.control.loop.ts
        2: entity.name.label.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(break|continue|do|goto|while)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.control.loop.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(return)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.control.flow.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(case|default|switch)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.control.switch.ts
    - include: if-statement
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(else|if)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.control.conditional.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(with)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.control.with.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(package)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.control.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(debugger)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.other.debugger.ts
  decl-block:
    - match: '\{'
      captures:
        0: punctuation.definition.block.ts
      push:
        - meta_scope: meta.block.ts
        - match: '\}'
          captures:
            0: punctuation.definition.block.ts
          pop: true
        - include: statements
  declaration:
    - include: decorator
    - include: var-expr
    - include: function-declaration
    - include: class-declaration
    - include: interface-declaration
    - include: enum-declaration
    - include: namespace-declaration
    - include: type-alias-declaration
    - include: import-equals-declaration
    - include: import-declaration
    - include: export-declaration
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(declare|export)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: storage.modifier.ts
  decorator:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))\@'
      captures:
        0: punctuation.decorator.ts
      push:
        - meta_scope: meta.decorator.ts
        - match: (?=\s)
          pop: true
        - include: expression
  destructuring-const:
    - match: '(?<!=|:|^of|[^\._$[:alnum:]]of|^in|[^\._$[:alnum:]]in)\s*(?=\{)'
      push:
        - meta_scope: meta.object-binding-pattern-variable.ts
        - match: '(?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: object-binding-pattern-const
        - include: type-annotation
        - include: comment
    - match: '(?<!=|:|^of|[^\._$[:alnum:]]of|^in|[^\._$[:alnum:]]in)\s*(?=\[)'
      push:
        - meta_scope: meta.array-binding-pattern-variable.ts
        - match: '(?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: array-binding-pattern-const
        - include: type-annotation
        - include: comment
  destructuring-parameter:
    - match: '(?<!=|:)\s*(?:(\.\.\.)\s*)?(\{)'
      captures:
        1: keyword.operator.rest.ts
        2: punctuation.definition.binding-pattern.object.ts
      push:
        - meta_scope: meta.parameter.object-binding-pattern.ts
        - match: '\}'
          captures:
            0: punctuation.definition.binding-pattern.object.ts
          pop: true
        - include: parameter-object-binding-element
    - match: '(?<!=|:)\s*(?:(\.\.\.)\s*)?(\[)'
      captures:
        1: keyword.operator.rest.ts
        2: punctuation.definition.binding-pattern.array.ts
      push:
        - meta_scope: meta.paramter.array-binding-pattern.ts
        - match: '\]'
          captures:
            0: punctuation.definition.binding-pattern.array.ts
          pop: true
        - include: parameter-binding-element
        - include: punctuation-comma
  destructuring-parameter-rest:
    - match: '(?:(\.\.\.)\s*)?([_$[:alpha:]][_$[:alnum:]]*)'
      captures:
        1: keyword.operator.rest.ts
        2: variable.parameter.ts
  destructuring-variable:
    - match: '(?<!=|:|^of|[^\._$[:alnum:]]of|^in|[^\._$[:alnum:]]in)\s*(?=\{)'
      push:
        - meta_scope: meta.object-binding-pattern-variable.ts
        - match: '(?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: object-binding-pattern
        - include: type-annotation
        - include: comment
    - match: '(?<!=|:|^of|[^\._$[:alnum:]]of|^in|[^\._$[:alnum:]]in)\s*(?=\[)'
      push:
        - meta_scope: meta.array-binding-pattern-variable.ts
        - match: '(?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: array-binding-pattern
        - include: type-annotation
        - include: comment
  destructuring-variable-rest:
    - match: '(?:(\.\.\.)\s*)?([_$[:alpha:]][_$[:alnum:]]*)'
      captures:
        1: keyword.operator.rest.ts
        2: meta.definition.variable.ts variable.other.readwrite.ts
  destructuring-variable-rest-const:
    - match: '(?:(\.\.\.)\s*)?([_$[:alpha:]][_$[:alnum:]]*)'
      captures:
        1: keyword.operator.rest.ts
        2: meta.definition.variable.ts variable.other.constant.ts
  directives:
    - match: '^(///)\s*(?=<(reference|amd-dependency|amd-module)(\s+(path|types|no-default-lib|lib|name)\s*=\s*((\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)))+\s*/>\s*$)'
      captures:
        1: punctuation.definition.comment.ts
      push:
        - meta_scope: comment.line.triple-slash.directive.ts
        - match: (?=$)
          pop: true
        - match: (<)(reference|amd-dependency|amd-module)
          captures:
            1: punctuation.definition.tag.directive.ts
            2: entity.name.tag.directive.ts
          push:
            - meta_scope: meta.tag.ts
            - match: />
              captures:
                0: punctuation.definition.tag.directive.ts
              pop: true
            - match: path|types|no-default-lib|lib|name
              scope: entity.other.attribute-name.directive.ts
            - match: "="
              scope: keyword.operator.assignment.ts
            - include: string
  docblock:
    - match: |-
        (?x)
        ((@)(?:access|api))
        \s+
        (private|protected|public)
        \b
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: constant.language.access-type.jsdoc
    - match: |-
        (?x)
        ((@)author)
        \s+
        (
          [^@\s<>*/]
          (?:[^@<>*/]|\*[^/])*
        )
        (?:
          \s*
          (<)
          ([^>\s]+)
          (>)
        )?
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: entity.name.type.instance.jsdoc
        4: punctuation.definition.bracket.angle.begin.jsdoc
        5: constant.other.email.link.underline.jsdoc
        6: punctuation.definition.bracket.angle.end.jsdoc
    - match: |-
        (?x)
        ((@)borrows) \s+
        ((?:[^@\s*/]|\*[^/])+)    # <that namepath>
        \s+ (as) \s+              # as
        ((?:[^@\s*/]|\*[^/])+)    # <this namepath>
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: entity.name.type.instance.jsdoc
        4: keyword.operator.control.jsdoc
        5: entity.name.type.instance.jsdoc
    - match: ((@)example)\s+
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
      push:
        - meta_scope: meta.example.jsdoc
        - match: (?=@|\*/)
          pop: true
        - match: ^\s\*\s+
        - match: \G(<)caption(>)
          captures:
            0: entity.name.tag.inline.jsdoc
            1: punctuation.definition.bracket.angle.begin.jsdoc
            2: punctuation.definition.bracket.angle.end.jsdoc
          push:
            - meta_content_scope: constant.other.description.jsdoc
            - match: (</)caption(>)|(?=\*/)
              captures:
                0: entity.name.tag.inline.jsdoc
                1: punctuation.definition.bracket.angle.begin.jsdoc
                2: punctuation.definition.bracket.angle.end.jsdoc
              pop: true
        - match: '[^\s@*](?:[^*]|\*[^/])*'
          captures:
            0: source.embedded.ts
    - match: (?x) ((@)kind) \s+ (class|constant|event|external|file|function|member|mixin|module|namespace|typedef) \b
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: constant.language.symbol-type.jsdoc
    - match: |-
        (?x)
        ((@)see)
        \s+
        (?:
          # URL
          (
            (?=https?://)
            (?:[^\s*]|\*[^/])+
          )
          |
          # JSDoc namepath
          (
            (?!
              # Avoid matching bare URIs (also acceptable as links)
              https?://
              |
              # Avoid matching {@inline tags}; we match those below
              (?:\[[^\[\]]*\])? # Possible description [preceding]{@tag}
              {@(?:link|linkcode|linkplain|tutorial)\b
            )
            # Matched namepath
            (?:[^@\s*/]|\*[^/])+
          )
        )
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: variable.other.link.underline.jsdoc
        4: entity.name.type.instance.jsdoc
    - match: |-
        (?x)
        ((@)template)
        \s+
        # One or more valid identifiers
        (
          [A-Za-z_$]         # First character: non-numeric word character
          [\w$.\[\]]*        # Rest of identifier
          (?:                # Possible list of additional identifiers
            \s* , \s*
            [A-Za-z_$]
            [\w$.\[\]]*
          )*
        )
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: variable.other.jsdoc
    - match: |-
        (?x)
        (
          (@)
          (?:arg|argument|const|constant|member|namespace|param|var)
        )
        \s+
        (
          [A-Za-z_$]
          [\w$.\[\]]*
        )
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: variable.other.jsdoc
    - match: '((@)typedef)\s+(?={)'
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
      push:
        - match: '(?=\s|\*/|[^{}\[\]A-Za-z_$])'
          pop: true
        - include: jsdoctype
        - match: '(?:[^@\s*/]|\*[^/])+'
          scope: entity.name.type.instance.jsdoc
    - match: '((@)(?:arg|argument|const|constant|member|namespace|param|prop|property|var))\s+(?={)'
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
      push:
        - match: '(?=\s|\*/|[^{}\[\]A-Za-z_$])'
          pop: true
        - include: jsdoctype
        - match: '([A-Za-z_$][\w$.\[\]]*)'
          scope: variable.other.jsdoc
        - match: |-
            (?x)
            (\[)\s*
            [\w$]+
            (?:
              (?:\[\])?                                        # Foo[ ].bar properties within an array
              \.                                                # Foo.Bar namespaced parameter
              [\w$]+
            )*
            (?:
              \s*
              (=)                                                # [foo=bar] Default parameter value
              \s*
              (
                # The inner regexes are to stop the match early at */ and to not stop at escaped quotes
                (?>
                  "(?:(?:\*(?!/))|(?:\\(?!"))|[^*\\])*?" |                      # [foo="bar"] Double-quoted
                  '(?:(?:\*(?!/))|(?:\\(?!'))|[^*\\])*?' |                      # [foo='bar'] Single-quoted
                  \[ (?:(?:\*(?!/))|[^*])*? \] |                                # [foo=[1,2]] Array literal
                  (?:(?:\*(?!/))|\s(?!\s*\])|\[.*?(?:\]|(?=\*/))|[^*\s\[\]])*   # Everything else
                )*
              )
            )?
            \s*(?:(\])((?:[^*\s]|\*[^\s/])+)?|(?=\*/))
          scope: variable.other.jsdoc
          captures:
            1: punctuation.definition.optional-value.begin.bracket.square.jsdoc
            2: keyword.operator.assignment.jsdoc
            3: source.embedded.ts
            4: punctuation.definition.optional-value.end.bracket.square.jsdoc
            5: invalid.illegal.syntax.jsdoc
    - match: |-
        (?x)
        (
          (@)
          (?:define|enum|exception|export|extends|lends|implements|modifies
          |namespace|private|protected|returns?|suppress|this|throws|type
          |yields?)
        )
        \s+(?={)
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
      push:
        - match: '(?=\s|\*/|[^{}\[\]A-Za-z_$])'
          pop: true
        - include: jsdoctype
    - match: |-
        (?x)
        (
          (@)
          (?:alias|augments|callback|constructs|emits|event|fires|exports?
          |extends|external|function|func|host|lends|listens|interface|memberof!?
          |method|module|mixes|mixin|name|requires|see|this|typedef|uses)
        )
        \s+
        (
          (?:
            [^{}@\s*] | \*[^/]
          )+
        )
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: entity.name.type.instance.jsdoc
    - match: '((@)(?:default(?:value)?|license|version))\s+(([''''"]))'
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: variable.other.jsdoc
        4: punctuation.definition.string.begin.jsdoc
      push:
        - meta_content_scope: variable.other.jsdoc
        - match: (\3)|(?=$|\*/)
          captures:
            0: variable.other.jsdoc
            1: punctuation.definition.string.end.jsdoc
          pop: true
    - match: '((@)(?:default(?:value)?|license|tutorial|variation|version))\s+([^\s*]+)'
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
        3: variable.other.jsdoc
    - match: '(?x) (@) (?:abstract|access|alias|api|arg|argument|async|attribute|augments|author|beta|borrows|bubbles |callback|chainable|class|classdesc|code|config|const|constant|constructor|constructs|copyright |default|defaultvalue|define|deprecated|desc|description|dict|emits|enum|event|example|exception |exports?|extends|extension(?:_?for)?|external|externs|file|fileoverview|final|fires|for|func |function|generator|global|hideconstructor|host|ignore|implements|implicitCast|inherit[Dd]oc |inner|instance|interface|internal|kind|lends|license|listens|main|member|memberof!?|method |mixes|mixins?|modifies|module|name|namespace|noalias|nocollapse|nocompile|nosideeffects |override|overview|package|param|polymer(?:Behavior)?|preserve|private|prop|property|protected |public|read[Oo]nly|record|require[ds]|returns?|see|since|static|struct|submodule|summary |suppress|template|this|throws|todo|tutorial|type|typedef|unrestricted|uses|var|variation |version|virtual|writeOnce|yields?) \b'
      scope: storage.type.class.jsdoc
      captures:
        1: punctuation.definition.block.tag.jsdoc
    - include: inline-tags
    - match: '((@)(?:[_$[:alpha:]][_$[:alnum:]]*))(?=\s+)'
      captures:
        1: storage.type.class.jsdoc
        2: punctuation.definition.block.tag.jsdoc
  enum-declaration:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?(?:\b(const)\s+)?\b(enum)\s+([_$[:alpha:]][_$[:alnum:]]*)'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: storage.modifier.ts
        4: storage.type.enum.ts
        5: entity.name.type.enum.ts
      push:
        - meta_scope: meta.enum.declaration.ts
        - match: '(?<=\})'
          pop: true
        - include: comment
        - match: '\{'
          captures:
            0: punctuation.definition.block.ts
          push:
            - match: '\}'
              captures:
                0: punctuation.definition.block.ts
              pop: true
            - include: comment
            - match: "([_$[:alpha:]][_$[:alnum:]]*)"
              captures:
                0: variable.other.enummember.ts
              push:
                - match: '(?=,|\}|$)'
                  pop: true
                - include: comment
                - include: variable-initializer
            - match: '(?=((\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\])))'
              push:
                - match: '(?=,|\}|$)'
                  pop: true
                - include: string
                - include: array-literal
                - include: comment
                - include: variable-initializer
            - include: punctuation-comma
  export-declaration:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)\s+(as)\s+(namespace)\s+([_$[:alpha:]][_$[:alnum:]]*)'
      captures:
        1: keyword.control.export.ts
        2: keyword.control.as.ts
        3: storage.type.namespace.ts
        4: entity.name.type.module.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)(?:\s+(type))?(?:(?:\s*(=))|(?:\s+(default)(?=\s+)))'
      captures:
        1: keyword.control.export.ts
        2: keyword.control.type.ts
        3: keyword.operator.assignment.ts
        4: keyword.control.default.ts
      push:
        - meta_scope: meta.export.default.ts
        - match: (?=$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))
          pop: true
        - include: interface-declaration
        - include: expression
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(export)(?:\s+(type))?\b(?!(\$)|(\s*:))((?=\s*[\{*])|((?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s|,))(?!\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b)))'
      captures:
        1: keyword.control.export.ts
        2: keyword.control.type.ts
      push:
        - meta_scope: meta.export.ts
        - match: (?=$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))
          pop: true
        - include: import-export-declaration
  expression:
    - include: expressionWithoutIdentifiers
    - include: identifiers
    - include: expressionPunctuations
  expression-inside-possibly-arrow-parens:
    - include: expressionWithoutIdentifiers
    - include: comment
    - include: string
    - include: decorator
    - include: destructuring-parameter
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(public|protected|private|readonly)\s+(?=(public|protected|private|readonly)\s+)'
      captures:
        1: storage.modifier.ts
    - match: |-
        (?x)(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(public|private|protected|readonly)\s+)?(?:(\.\.\.)\s*)?(?<!=|:)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(this)|([_$[:alpha:]][_$[:alnum:]]*))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*(\??)(?=\s*
        # function assignment |
        (=\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        )) |
        # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
        (:\s*(
          (<) |
          ([(]\s*(
            ([)]) |
            (\.\.\.) |
            ([_$[:alnum:]]+\s*(
              ([:,?=])|
              ([)]\s*=>)
            ))
          ))
        )) |
        (:\s*(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))Function(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))) |
        (:\s*((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*))))))) |
        (:\s*(=>|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(<[^<>]*>)|[^<>(),=])+=\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        )))
      captures:
        1: storage.modifier.ts
        2: keyword.operator.rest.ts
        3: entity.name.function.ts variable.language.this.ts
        4: entity.name.function.ts
        5: keyword.operator.optional.ts
    - match: '(?x)(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(public|private|protected|readonly)\s+)?(?:(\.\.\.)\s*)?(?<!=|:)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(this)|([_$[:alpha:]][_$[:alnum:]]*))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*(\??)(?=\s*[:,]|$)'
      captures:
        1: storage.modifier.ts
        2: keyword.operator.rest.ts
        3: variable.parameter.ts variable.language.this.ts
        4: variable.parameter.ts
        5: keyword.operator.optional.ts
    - include: type-annotation
    - include: variable-initializer
    - match: ","
      scope: punctuation.separator.parameter.ts
    - include: identifiers
    - include: expressionPunctuations
  expression-operators:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(await)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.control.flow.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(yield)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))(?=\s*\/\*([^\*]|(\*[^\/]))*\*\/\s*\*)'
      captures:
        1: keyword.control.flow.ts
      push:
        - match: \*
          captures:
            0: keyword.generator.asterisk.ts
          pop: true
        - include: comment
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(yield)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))(?:\s*(\*))?'
      captures:
        1: keyword.control.flow.ts
        2: keyword.generator.asterisk.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))delete(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.operator.expression.delete.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))in(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))(?!\()'
      scope: keyword.operator.expression.in.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))of(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))(?!\()'
      scope: keyword.operator.expression.of.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))instanceof(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.operator.expression.instanceof.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))new(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.operator.new.ts
    - include: typeof-operator
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))void(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.operator.expression.void.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(as)\s+(const)(?=\s*($|[;,:})\]]))'
      captures:
        1: keyword.control.as.ts
        2: storage.modifier.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(as)\s+'
      captures:
        1: keyword.control.as.ts
      push:
        - match: '(?=^|[;),}\]:?\-\+\>]|\|\||\&\&|\!\=\=|$|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(as)\s+)|(\s+\<))'
          pop: true
        - include: type
    - match: \.\.\.
      scope: keyword.operator.spread.ts
    - match: \*=|(?<!\()/=|%=|\+=|\-=
      scope: keyword.operator.assignment.compound.ts
    - match: \&=|\^=|<<=|>>=|>>>=|\|=
      scope: keyword.operator.assignment.compound.bitwise.ts
    - match: "<<|>>>|>>"
      scope: keyword.operator.bitwise.shift.ts
    - match: "===|!==|==|!="
      scope: keyword.operator.comparison.ts
    - match: <=|>=|<>|<|>
      scope: keyword.operator.relational.ts
    - match: '(?<=[_$[:alnum:]])(\!)\s*(/)(?![/*])'
      captures:
        1: keyword.operator.logical.ts
        2: keyword.operator.arithmetic.ts
    - match: \!|&&|\|\||\?\?
      scope: keyword.operator.logical.ts
    - match: \&|~|\^|\|
      scope: keyword.operator.bitwise.ts
    - match: \=
      scope: keyword.operator.assignment.ts
    - match: "--"
      scope: keyword.operator.decrement.ts
    - match: \+\+
      scope: keyword.operator.increment.ts
    - match: '%|\*|/|-|\+'
      scope: keyword.operator.arithmetic.ts
    - match: '(?<=[_$[:alnum:])\]])\s*(?=(\/\*([^\*]|(\*[^\/]))*\*\/\s*)+(/)(?![/*]))'
      push:
        - match: '(/)(?!\*([^\*]|(\*[^\/]))*\*\/)'
          captures:
            1: keyword.operator.arithmetic.ts
          pop: true
        - include: comment
    - match: '(?<=[_$[:alnum:])\]])\s*(/)(?![/*])'
      captures:
        1: keyword.operator.arithmetic.ts
  expressionPunctuations:
    - include: punctuation-comma
    - include: punctuation-accessor
  expressionWithoutIdentifiers:
    - include: string
    - include: regex
    - include: comment
    - include: function-expression
    - include: class-expression
    - include: arrow-function
    - include: paren-expression-possibly-arrow
    - include: cast
    - include: ternary-expression
    - include: new-expr
    - include: instanceof-expr
    - include: object-literal
    - include: expression-operators
    - include: function-call
    - include: literal
    - include: support-objects
    - include: paren-expression
  field-declaration:
    - match: |-
        (?x)(?<!\()(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(readonly)\s+)?(?=\s*((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$))|(\#?[_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(?:(?:(\?)|(\!))\s*)?(=|:|;|,|\}|$))
      captures:
        1: storage.modifier.ts
      push:
        - meta_scope: meta.field.declaration.ts
        - match: |-
            (?x)(?=\}|;|,|$|(^(?!\s*((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
              (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
              (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
              (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
              (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
              (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
              (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
              (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
              (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
            )(?!\$))|(\#?[_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(?:(?:(\?)|(\!))\s*)?(=|:|;|,|$))))|(?<=\})
          pop: true
        - include: variable-initializer
        - include: type-annotation
        - include: string
        - include: array-literal
        - include: numeric-literal
        - include: comment
        - match: |-
            (?x)(\#?[_$[:alpha:]][_$[:alnum:]]*)(?:(\?)|(\!))?(?=\s*\s*
            # function assignment |
            (=\s*(
              ((async\s+)?(
                (function\s*[(<*]) |
                (function\s+) |
                ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
              )) |
              ((async\s*)?(
                ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
                # sure shot arrow functions even if => is on new line
            (
              (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
              [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
              (
                ([)]\s*:) |                                                                                       # ():
                ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
              )
            ) |

            # arrow function possible to detect only with => on same line
            (
              (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
              \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
              (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
              \s*=>                                                                                               # arrow operator
            )
              ))
            )) |
            # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
            (:\s*(
              (<) |
              ([(]\s*(
                ([)]) |
                (\.\.\.) |
                ([_$[:alnum:]]+\s*(
                  ([:,?=])|
                  ([)]\s*=>)
                ))
              ))
            )) |
            (:\s*(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))Function(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))) |
            (:\s*((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*))))))) |
            (:\s*(=>|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(<[^<>]*>)|[^<>(),=])+=\s*(
              ((async\s+)?(
                (function\s*[(<*]) |
                (function\s+) |
                ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
              )) |
              ((async\s*)?(
                ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
                # sure shot arrow functions even if => is on new line
            (
              (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
              [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
              (
                ([)]\s*:) |                                                                                       # ():
                ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
              )
            ) |

            # arrow function possible to detect only with => on same line
            (
              (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
              \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
              (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
              \s*=>                                                                                               # arrow operator
            )
              ))
            )))
          captures:
            1: meta.definition.property.ts entity.name.function.ts
            2: keyword.operator.optional.ts
            3: keyword.operator.definiteassignment.ts
        - match: '\#?[_$[:alpha:]][_$[:alnum:]]*'
          scope: meta.definition.property.ts variable.object.property.ts
        - match: \?
          scope: keyword.operator.optional.ts
        - match: \!
          scope: keyword.operator.definiteassignment.ts
  for-loop:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))for(?=((\s+|(\s*\/\*([^\*]|(\*[^\/]))*\*\/\s*))await)?\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)?(\())'
      captures:
        0: keyword.control.loop.ts
      push:
        - match: (?<=\))
          pop: true
        - include: comment
        - match: await
          scope: keyword.control.loop.ts
        - match: \(
          captures:
            0: meta.brace.round.ts
          push:
            - match: \)
              captures:
                0: meta.brace.round.ts
              pop: true
            - include: var-expr
            - include: expression
            - include: punctuation-semicolon
  function-body:
    - include: comment
    - include: type-parameters
    - include: function-parameters
    - include: return-type
    - include: decl-block
    - match: \*
      scope: keyword.generator.asterisk.ts
  function-call:
    - match: '(?=(((([_$[:alpha:]][_$[:alnum:]]*)(\s*\??\.\s*(\#?[_$[:alpha:]][_$[:alnum:]]*))*)|(\??\.\s*\#?[_$[:alpha:]][_$[:alnum:]]*))|(?<=[\)]))\s*(?:(\?\.\s*)|(\!))?((<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))(([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>)*(?<!=)\>))*(?<!=)\>)*(?<!=)>\s*)?\())'
      push:
        - match: '(?<=\))(?!(((([_$[:alpha:]][_$[:alnum:]]*)(\s*\??\.\s*(\#?[_$[:alpha:]][_$[:alnum:]]*))*)|(\??\.\s*\#?[_$[:alpha:]][_$[:alnum:]]*))|(?<=[\)]))\s*(?:(\?\.\s*)|(\!))?((<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))(([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>)*(?<!=)\>))*(?<!=)\>)*(?<!=)>\s*)?\())'
          pop: true
        - match: '(?=(([_$[:alpha:]][_$[:alnum:]]*)(\s*\??\.\s*(\#?[_$[:alpha:]][_$[:alnum:]]*))*)|(\??\.\s*\#?[_$[:alpha:]][_$[:alnum:]]*))'
          push:
            - meta_scope: meta.function-call.ts
            - match: '(?=\s*(?:(\?\.\s*)|(\!))?((<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))(([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>)*(?<!=)\>))*(?<!=)\>)*(?<!=)>\s*)?\())'
              pop: true
            - include: function-call-target
        - include: comment
        - include: function-call-optionals
        - include: type-arguments
        - include: paren-expression
    - match: '(?=(((([_$[:alpha:]][_$[:alnum:]]*)(\s*\??\.\s*(\#?[_$[:alpha:]][_$[:alnum:]]*))*)|(\??\.\s*\#?[_$[:alpha:]][_$[:alnum:]]*))|(?<=[\)]))(<\s*[\{\[\(]\s*$))'
      push:
        - match: '(?<=\>)(?!(((([_$[:alpha:]][_$[:alnum:]]*)(\s*\??\.\s*(\#?[_$[:alpha:]][_$[:alnum:]]*))*)|(\??\.\s*\#?[_$[:alpha:]][_$[:alnum:]]*))|(?<=[\)]))(<\s*[\{\[\(]\s*$))'
          pop: true
        - match: '(?=(([_$[:alpha:]][_$[:alnum:]]*)(\s*\??\.\s*(\#?[_$[:alpha:]][_$[:alnum:]]*))*)|(\??\.\s*\#?[_$[:alpha:]][_$[:alnum:]]*))'
          push:
            - meta_scope: meta.function-call.ts
            - match: '(?=(<\s*[\{\[\(]\s*$))'
              pop: true
            - include: function-call-target
        - include: comment
        - include: function-call-optionals
        - include: type-arguments
  function-call-optionals:
    - match: \?\.
      scope: meta.function-call.ts punctuation.accessor.optional.ts
    - match: \!
      scope: meta.function-call.ts keyword.operator.definiteassignment.ts
  function-call-target:
    - include: support-function-call-identifiers
    - match: '(\#?[_$[:alpha:]][_$[:alnum:]]*)'
      scope: entity.name.function.ts
  function-declaration:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?(?:(async)\s+)?(function\b)(?:\s*(\*))?(?:(?:\s+|(?<=\*))([_$[:alpha:]][_$[:alnum:]]*))?\s*'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: storage.modifier.async.ts
        4: storage.type.function.ts
        5: keyword.generator.asterisk.ts
        6: meta.definition.function.ts entity.name.function.ts
      push:
        - meta_scope: meta.function.ts
        - match: '(?=;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))|(?<=\})'
          pop: true
        - include: function-name
        - include: function-body
  function-expression:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(async)\s+)?(function\b)(?:\s*(\*))?(?:(?:\s+|(?<=\*))([_$[:alpha:]][_$[:alnum:]]*))?\s*'
      captures:
        1: storage.modifier.async.ts
        2: storage.type.function.ts
        3: keyword.generator.asterisk.ts
        4: meta.definition.function.ts entity.name.function.ts
      push:
        - meta_scope: meta.function.expression.ts
        - match: '(?=;)|(?<=\})'
          pop: true
        - include: function-name
        - include: single-line-comment-consuming-line-ending
        - include: function-body
  function-name:
    - match: "[_$[:alpha:]][_$[:alnum:]]*"
      scope: meta.definition.function.ts entity.name.function.ts
  function-parameters:
    - match: \(
      captures:
        0: punctuation.definition.parameters.begin.ts
      push:
        - meta_scope: meta.parameters.ts
        - match: \)
          captures:
            0: punctuation.definition.parameters.end.ts
          pop: true
        - include: function-parameters-body
  function-parameters-body:
    - include: comment
    - include: string
    - include: decorator
    - include: destructuring-parameter
    - include: parameter-name
    - include: parameter-type-annotation
    - include: variable-initializer
    - match: ","
      scope: punctuation.separator.parameter.ts
  identifiers:
    - include: object-identifiers
    - match: |-
        (?x)(?:(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*)?([_$[:alpha:]][_$[:alnum:]]*)(?=\s*=\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        ))
      captures:
        1: punctuation.accessor.ts
        2: punctuation.accessor.optional.ts
        3: entity.name.function.ts
    - match: '(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(\#?[[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])'
      captures:
        1: punctuation.accessor.ts
        2: punctuation.accessor.optional.ts
        3: variable.other.constant.property.ts
    - match: '(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(\#?[_$[:alpha:]][_$[:alnum:]]*)'
      captures:
        1: punctuation.accessor.ts
        2: punctuation.accessor.optional.ts
        3: variable.other.property.ts
    - match: "([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])"
      scope: variable.other.constant.ts
    - match: "[_$[:alpha:]][_$[:alnum:]]*"
      scope: variable.other.readwrite.ts
  if-statement:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?=\bif\s*(\(([^\(\)]|(\([^\(\)]*\)))*\))\s*(?!\{))'
      push:
        - match: '(?=;|$|\})'
          pop: true
        - include: comment
        - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(if)\s*(\()'
          captures:
            1: keyword.control.conditional.ts
            2: meta.brace.round.ts
          push:
            - match: \)
              captures:
                0: meta.brace.round.ts
              pop: true
            - include: expression
        - match: '(?<=\))\s*\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/([gimsuy]+|(?![\/\*])|(?=\/\*))(?!\s*[a-zA-Z0-9_$]))'
          captures:
            0: punctuation.definition.string.begin.ts
          push:
            - meta_scope: string.regexp.ts
            - match: "(/)([gimsuy]*)"
              captures:
                1: punctuation.definition.string.end.ts
                2: keyword.other.ts
              pop: true
            - include: regexp
        - include: statements
  import-declaration:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type)(?!\s+from))?(?!\s*[:\(])(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: keyword.control.import.ts
        4: keyword.control.type.ts
      push:
        - meta_scope: meta.import.ts
        - match: '(?<!^import|[^\._$[:alnum:]]import)(?=;|$|^)'
          pop: true
        - include: single-line-comment-consuming-line-ending
        - include: comment
        - include: string
        - match: '(?<=^import|[^\._$[:alnum:]]import)(?!\s*["''])'
          push:
            - match: \bfrom\b
              captures:
                0: keyword.control.from.ts
              pop: true
            - include: import-export-declaration
        - include: import-export-declaration
  import-equals-declaration:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(require)\s*(\()'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: keyword.control.import.ts
        4: keyword.control.type.ts
        5: variable.other.readwrite.alias.ts
        6: keyword.operator.assignment.ts
        7: keyword.control.require.ts
        8: meta.brace.round.ts
      push:
        - meta_scope: meta.import-equals.external.ts
        - match: \)
          captures:
            0: meta.brace.round.ts
          pop: true
        - include: comment
        - include: string
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(import)(?:\s+(type))?\s+([_$[:alpha:]][_$[:alnum:]]*)\s*(=)\s*(?!require\b)'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: keyword.control.import.ts
        4: keyword.control.type.ts
        5: variable.other.readwrite.alias.ts
        6: keyword.operator.assignment.ts
      push:
        - meta_scope: meta.import-equals.internal.ts
        - match: (?=;|$|^)
          pop: true
        - include: single-line-comment-consuming-line-ending
        - include: comment
        - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))'
          captures:
            1: entity.name.type.module.ts
            2: punctuation.accessor.ts
            3: punctuation.accessor.optional.ts
        - match: "([_$[:alpha:]][_$[:alnum:]]*)"
          scope: variable.other.readwrite.ts
  import-export-block:
    - match: '\{'
      captures:
        0: punctuation.definition.block.ts
      push:
        - meta_scope: meta.block.ts
        - match: '\}'
          captures:
            0: punctuation.definition.block.ts
          pop: true
        - include: import-export-clause
  import-export-clause:
    - include: comment
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bdefault)|(\*)|(\b[_$[:alpha:]][_$[:alnum:]]*))\s+(as)\s+(?:(default(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|([_$[:alpha:]][_$[:alnum:]]*))'
      captures:
        1: keyword.control.default.ts
        2: constant.language.import-export-all.ts
        3: variable.other.readwrite.ts
        4: keyword.control.as.ts
        5: keyword.control.default.ts
        6: variable.other.readwrite.alias.ts
    - include: punctuation-comma
    - match: \*
      scope: constant.language.import-export-all.ts
    - match: \b(default)\b
      scope: keyword.control.default.ts
    - match: "([_$[:alpha:]][_$[:alnum:]]*)"
      scope: variable.other.readwrite.alias.ts
  import-export-declaration:
    - include: comment
    - include: string
    - include: import-export-block
    - match: \bfrom\b
      scope: keyword.control.from.ts
    - include: import-export-clause
  indexer-declaration:
    - match: '(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(readonly)\s*)?\s*(\[)\s*([_$[:alpha:]][_$[:alnum:]]*)\s*(?=:)'
      captures:
        1: storage.modifier.ts
        2: meta.brace.square.ts
        3: variable.parameter.ts
      push:
        - meta_scope: meta.indexer.declaration.ts
        - match: '(\])\s*(\?\s*)?|$'
          captures:
            1: meta.brace.square.ts
            2: keyword.operator.optional.ts
          pop: true
        - include: type-annotation
  indexer-mapped-type-declaration:
    - match: '(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))([+-])?(readonly)\s*)?\s*(\[)\s*([_$[:alpha:]][_$[:alnum:]]*)\s+(in)\s+'
      captures:
        1: keyword.operator.type.modifier.ts
        2: storage.modifier.ts
        3: meta.brace.square.ts
        4: entity.name.type.ts
        5: keyword.operator.expression.in.ts
      push:
        - meta_scope: meta.indexer.mappedtype.declaration.ts
        - match: '(\])([+-])?\s*(\?\s*)?|$'
          captures:
            1: meta.brace.square.ts
            2: keyword.operator.type.modifier.ts
            3: keyword.operator.optional.ts
          pop: true
        - include: type
  inline-tags:
    - match: '(\[)[^\]]+(\])(?={@(?:link|linkcode|linkplain|tutorial))'
      scope: constant.other.description.jsdoc
      captures:
        1: punctuation.definition.bracket.square.begin.jsdoc
        2: punctuation.definition.bracket.square.end.jsdoc
    - match: '({)((@)(?:link(?:code|plain)?|tutorial))\s*'
      captures:
        1: punctuation.definition.bracket.curly.begin.jsdoc
        2: storage.type.class.jsdoc
        3: punctuation.definition.inline.tag.jsdoc
      push:
        - meta_scope: entity.name.type.instance.jsdoc
        - match: '}|(?=\*/)'
          captures:
            0: punctuation.definition.bracket.curly.end.jsdoc
          pop: true
        - match: '\G((?=https?://)(?:[^|}\s*]|\*[/])+)(\|)?'
          captures:
            1: variable.other.link.underline.jsdoc
            2: punctuation.separator.pipe.jsdoc
        - match: '\G((?:[^{}@\s|*]|\*[^/])+)(\|)?'
          captures:
            1: variable.other.description.jsdoc
            2: punctuation.separator.pipe.jsdoc
  instanceof-expr:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(instanceof)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      captures:
        1: keyword.operator.expression.instanceof.ts
      push:
        - match: '(?<=\))|(?=[;),}\]:?\-\+\>]|\|\||\&\&|\!\=\=|$|(([\&\~\^\|]\s*)?[_$[:alpha:]][_$[:alnum:]]*\s+instanceof(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))function((\s+[_$[:alpha:]][_$[:alnum:]]*)|(\s*[\(]))))'
          pop: true
        - include: type
  interface-declaration:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(?:(abstract)\s+)?\b(interface)\b(?=\s+|/[/*])'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: storage.modifier.ts
        4: storage.type.interface.ts
      push:
        - meta_scope: meta.interface.ts
        - match: '(?<=\})'
          pop: true
        - include: comment
        - include: class-or-interface-heritage
        - match: "[_$[:alpha:]][_$[:alnum:]]*"
          captures:
            0: entity.name.type.interface.ts
        - include: type-parameters
        - include: class-or-interface-body
  jsdoctype:
    - match: '\G{(?:[^}*]|\*[^/}])+$'
      scope: invalid.illegal.type.jsdoc
    - match: '\G({)'
      captures:
        0: entity.name.type.instance.jsdoc
        1: punctuation.definition.bracket.curly.begin.jsdoc
      push:
        - meta_content_scope: entity.name.type.instance.jsdoc
        - match: '((}))\s*|(?=\*/)'
          captures:
            1: entity.name.type.instance.jsdoc
            2: punctuation.definition.bracket.curly.end.jsdoc
          pop: true
        - include: brackets
  label:
    - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(:)(?=\s*\{)'
      captures:
        1: entity.name.label.ts
        2: punctuation.separator.label.ts
      push:
        - match: '(?<=\})'
          pop: true
        - include: decl-block
    - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(:)'
      captures:
        1: entity.name.label.ts
        2: punctuation.separator.label.ts
  literal:
    - include: numeric-literal
    - include: boolean-literal
    - include: null-literal
    - include: undefined-literal
    - include: numericConstant-literal
    - include: array-literal
    - include: this-literal
    - include: super-literal
  method-declaration:
    - match: '(?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?\s*\b(constructor)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      captures:
        1: storage.modifier.ts
        2: storage.modifier.ts
        3: storage.modifier.async.ts
        4: storage.type.ts
      push:
        - meta_scope: meta.method.declaration.ts
        - match: '(?=\}|;|,|$)|(?<=\})'
          pop: true
        - include: method-declaration-name
        - include: function-body
    - match: '(?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:(?:\s*\b(new)\b(?!:)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|(?:(\*)\s*)?)(?=\s*((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*))?[\(])'
      captures:
        1: storage.modifier.ts
        2: storage.modifier.ts
        3: storage.modifier.async.ts
        4: keyword.operator.new.ts
        5: keyword.generator.asterisk.ts
      push:
        - meta_scope: meta.method.declaration.ts
        - match: '(?=\}|;|,|$)|(?<=\})'
          pop: true
        - include: method-declaration-name
        - include: function-body
    - match: |-
        (?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:\b(public|private|protected)\s+)?(?:\b(abstract)\s+)?(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=\s*(((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*))?[\(])
      captures:
        1: storage.modifier.ts
        2: storage.modifier.ts
        3: storage.modifier.async.ts
        4: storage.type.property.ts
        5: keyword.generator.asterisk.ts
      push:
        - meta_scope: meta.method.declaration.ts
        - match: '(?=\}|;|,|$)|(?<=\})'
          pop: true
        - include: method-declaration-name
        - include: function-body
  method-declaration-name:
    - match: |-
        (?x)(?=((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??)\s*[\(\<])
      push:
        - match: (?=\(|\<)
          pop: true
        - include: string
        - include: array-literal
        - include: numeric-literal
        - match: "[_$[:alpha:]][_$[:alnum:]]*"
          scope: meta.definition.method.ts entity.name.function.ts
        - match: \?
          scope: keyword.operator.optional.ts
  namespace-declaration:
    - match: '(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(namespace|module)\s+(?=[_$[:alpha:]"''`]))'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: storage.type.namespace.ts
      push:
        - meta_scope: meta.namespace.declaration.ts
        - match: '(?<=\})|(?=;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))'
          pop: true
        - include: comment
        - include: string
        - match: "([_$[:alpha:]][_$[:alnum:]]*)"
          scope: entity.name.type.module.ts
        - include: punctuation-accessor
        - include: decl-block
  new-expr:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(new)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      captures:
        1: keyword.operator.new.ts
      push:
        - meta_scope: new.expr.ts
        - match: '(?<=\))|(?=[;),}\]:?\-\+\>]|\|\||\&\&|\!\=\=|$|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))new(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))function((\s+[_$[:alpha:]][_$[:alnum:]]*)|(\s*[\(]))))'
          pop: true
        - include: paren-expression
        - include: class-declaration
        - include: type
  null-literal:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))null(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: constant.language.null.ts
  numeric-literal:
    - match: '\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$)'
      scope: constant.numeric.hex.ts
      captures:
        1: storage.type.numeric.bigint.ts
    - match: '\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$)'
      scope: constant.numeric.binary.ts
      captures:
        1: storage.type.numeric.bigint.ts
    - match: '\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$)'
      scope: constant.numeric.octal.ts
      captures:
        1: storage.type.numeric.bigint.ts
    - match: |-
        (?x)
        (?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$)
      captures:
        0: constant.numeric.decimal.ts
        1: meta.delimiter.decimal.period.ts
        2: storage.type.numeric.bigint.ts
        3: meta.delimiter.decimal.period.ts
        4: storage.type.numeric.bigint.ts
        5: meta.delimiter.decimal.period.ts
        6: storage.type.numeric.bigint.ts
        7: storage.type.numeric.bigint.ts
        8: meta.delimiter.decimal.period.ts
        9: storage.type.numeric.bigint.ts
        10: meta.delimiter.decimal.period.ts
        11: storage.type.numeric.bigint.ts
        12: meta.delimiter.decimal.period.ts
        13: storage.type.numeric.bigint.ts
        14: storage.type.numeric.bigint.ts
  numericConstant-literal:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))NaN(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: constant.language.nan.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))Infinity(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: constant.language.infinity.ts
  object-binding-element:
    - include: comment
    - match: |-
        (?x)(?=((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(:))
      push:
        - match: '(?=,|\})'
          pop: true
        - include: object-binding-element-propertyName
        - include: binding-element
    - include: object-binding-pattern
    - include: destructuring-variable-rest
    - include: variable-initializer
    - include: punctuation-comma
  object-binding-element-const:
    - include: comment
    - match: |-
        (?x)(?=((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(:))
      push:
        - match: '(?=,|\})'
          pop: true
        - include: object-binding-element-propertyName
        - include: binding-element-const
    - include: object-binding-pattern-const
    - include: destructuring-variable-rest-const
    - include: variable-initializer
    - include: punctuation-comma
  object-binding-element-propertyName:
    - match: |-
        (?x)(?=((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(:))
      push:
        - match: (:)
          captures:
            0: punctuation.destructuring.ts
          pop: true
        - include: string
        - include: array-literal
        - include: numeric-literal
        - match: "([_$[:alpha:]][_$[:alnum:]]*)"
          scope: variable.object.property.ts
  object-binding-pattern:
    - match: '(?:(\.\.\.)\s*)?(\{)'
      captures:
        1: keyword.operator.rest.ts
        2: punctuation.definition.binding-pattern.object.ts
      push:
        - match: '\}'
          captures:
            0: punctuation.definition.binding-pattern.object.ts
          pop: true
        - include: object-binding-element
  object-binding-pattern-const:
    - match: '(?:(\.\.\.)\s*)?(\{)'
      captures:
        1: keyword.operator.rest.ts
        2: punctuation.definition.binding-pattern.object.ts
      push:
        - match: '\}'
          captures:
            0: punctuation.definition.binding-pattern.object.ts
          pop: true
        - include: object-binding-element-const
  object-identifiers:
    - match: '([_$[:alpha:]][_$[:alnum:]]*)(?=\s*\??\.\s*prototype\b(?!\$))'
      scope: support.class.ts
    - match: |-
        (?x)(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(?:
          (\#?[[:upper:]][_$[:digit:][:upper:]]*) |
          (\#?[_$[:alpha:]][_$[:alnum:]]*)
        )(?=\s*\??\.\s*\#?[_$[:alpha:]][_$[:alnum:]]*)
      captures:
        1: punctuation.accessor.ts
        2: punctuation.accessor.optional.ts
        3: variable.other.constant.object.property.ts
        4: variable.other.object.property.ts
    - match: |-
        (?x)(?:
          ([[:upper:]][_$[:digit:][:upper:]]*) |
          ([_$[:alpha:]][_$[:alnum:]]*)
        )(?=\s*\??\.\s*\#?[_$[:alpha:]][_$[:alnum:]]*)
      captures:
        1: variable.other.constant.object.ts
        2: variable.other.object.ts
  object-literal:
    - match: '\{'
      captures:
        0: punctuation.definition.block.ts
      push:
        - meta_scope: meta.objectliteral.ts
        - match: '\}'
          captures:
            0: punctuation.definition.block.ts
          pop: true
        - include: object-member
  object-literal-method-declaration:
    - match: |-
        (?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=\s*(((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*))?[\(])
      captures:
        1: storage.modifier.async.ts
        2: storage.type.property.ts
        3: keyword.generator.asterisk.ts
      push:
        - meta_scope: meta.method.declaration.ts
        - match: '(?=\}|;|,)|(?<=\})'
          pop: true
        - include: method-declaration-name
        - include: function-body
        - match: |-
            (?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:\b(async)\s+)?(?:\b(get|set)\s+)?(?:(\*)\s*)?(?=\s*(((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
              (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
              (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
              (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
              (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
              (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
              (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
              (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
              (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
            )(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(\??))\s*((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*))?[\(])
          captures:
            1: storage.modifier.async.ts
            2: storage.type.property.ts
            3: keyword.generator.asterisk.ts
          push:
            - match: (?=\(|\<)
              pop: true
            - include: method-declaration-name
  object-member:
    - include: comment
    - include: object-literal-method-declaration
    - match: '(?=\[)'
      push:
        - meta_scope: meta.object.member.ts meta.object-literal.key.ts
        - match: '(?=:)|((?<=[\]])(?=\s*[\(\<]))'
          pop: true
        - include: comment
        - include: array-literal
    - match: '(?=[\''\"\`])'
      push:
        - meta_scope: meta.object.member.ts meta.object-literal.key.ts
        - match: '(?=:)|((?<=[\''\"\`])(?=((\s*[\(\<,}])|(\s+(as)\s+))))'
          pop: true
        - include: comment
        - include: string
    - match: |-
        (?x)(?=(\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$)))
      push:
        - meta_scope: meta.object.member.ts meta.object-literal.key.ts
        - match: '(?=:)|(?=\s*([\(\<,}])|(\s+as\s+))'
          pop: true
        - include: comment
        - include: numeric-literal
    - match: '(?<=[\]\''\"\`])(?=\s*[\(\<])'
      push:
        - meta_scope: meta.method.declaration.ts
        - match: '(?=\}|;|,)|(?<=\})'
          pop: true
        - include: function-body
    - match: '(?![_$[:alpha:]])([[:digit:]]+)\s*(?=(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*:)'
      scope: meta.object.member.ts
      captures:
        0: meta.object-literal.key.ts
        1: constant.numeric.decimal.ts
    - match: |-
        (?x)(?:([_$[:alpha:]][_$[:alnum:]]*)\s*(?=(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*:(\s*\/\*([^\*]|(\*[^\/]))*\*\/)*\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        )))
      scope: meta.object.member.ts
      captures:
        0: meta.object-literal.key.ts
        1: entity.name.function.ts
    - match: '(?:[_$[:alpha:]][_$[:alnum:]]*)\s*(?=(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*:)'
      scope: meta.object.member.ts
      captures:
        0: meta.object-literal.key.ts
    - match: \.\.\.
      captures:
        0: keyword.operator.spread.ts
      push:
        - meta_scope: meta.object.member.ts
        - match: '(?=,|\})'
          pop: true
        - include: expression
    - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?=,|\}|$|\/\/|\/\*)'
      scope: meta.object.member.ts
      captures:
        1: variable.other.readwrite.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(as)\s+(const)(?=\s*([,}]|$))'
      scope: meta.object.member.ts
      captures:
        1: keyword.control.as.ts
        2: storage.modifier.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(as)\s+'
      captures:
        1: keyword.control.as.ts
      push:
        - meta_scope: meta.object.member.ts
        - match: '(?=[;),}\]:?\-\+\>]|\|\||\&\&|\!\=\=|$|^|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(as)\s+))'
          pop: true
        - include: type
    - match: '(?=[_$[:alpha:]][_$[:alnum:]]*\s*=)'
      push:
        - meta_scope: meta.object.member.ts
        - match: '(?=,|\}|$|\/\/|\/\*)'
          pop: true
        - include: expression
    - match: ":"
      captures:
        0: meta.object-literal.key.ts punctuation.separator.key-value.ts
      push:
        - meta_scope: meta.object.member.ts
        - match: '(?=,|\})'
          pop: true
        - match: '(?<=:)\s*(async)?(?=\s*(<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)\(\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))'
          captures:
            1: storage.modifier.async.ts
          push:
            - match: (?<=\))
              pop: true
            - include: type-parameters
            - match: \(
              captures:
                0: meta.brace.round.ts
              push:
                - match: \)
                  captures:
                    0: meta.brace.round.ts
                  pop: true
                - include: expression-inside-possibly-arrow-parens
        - match: '(?<=:)\s*(async)?\s*(\()(?=\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))'
          captures:
            1: storage.modifier.async.ts
            2: meta.brace.round.ts
          push:
            - match: \)
              captures:
                0: meta.brace.round.ts
              pop: true
            - include: expression-inside-possibly-arrow-parens
        - match: (?<=:)\s*(async)?\s*(?=\<\s*$)
          captures:
            1: storage.modifier.async.ts
          push:
            - match: (?<=\>)
              pop: true
            - include: type-parameters
        - match: '(?<=\>)\s*(\()(?=\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))'
          captures:
            1: meta.brace.round.ts
          push:
            - match: \)
              captures:
                0: meta.brace.round.ts
              pop: true
            - include: expression-inside-possibly-arrow-parens
        - include: possibly-arrow-return-type
        - include: expression
    - include: punctuation-comma
  parameter-array-binding-pattern:
    - match: '(?:(\.\.\.)\s*)?(\[)'
      captures:
        1: keyword.operator.rest.ts
        2: punctuation.definition.binding-pattern.array.ts
      push:
        - match: '\]'
          captures:
            0: punctuation.definition.binding-pattern.array.ts
          pop: true
        - include: parameter-binding-element
        - include: punctuation-comma
  parameter-binding-element:
    - include: comment
    - include: string
    - include: numeric-literal
    - include: regex
    - include: parameter-object-binding-pattern
    - include: parameter-array-binding-pattern
    - include: destructuring-parameter-rest
    - include: variable-initializer
  parameter-name:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(public|protected|private|readonly)\s+(?=(public|protected|private|readonly)\s+)'
      captures:
        1: storage.modifier.ts
    - match: |-
        (?x)(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(public|private|protected|readonly)\s+)?(?:(\.\.\.)\s*)?(?<!=|:)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(this)|([_$[:alpha:]][_$[:alnum:]]*))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*(\??)(?=\s*
        # function assignment |
        (=\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        )) |
        # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
        (:\s*(
          (<) |
          ([(]\s*(
            ([)]) |
            (\.\.\.) |
            ([_$[:alnum:]]+\s*(
              ([:,?=])|
              ([)]\s*=>)
            ))
          ))
        )) |
        (:\s*(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))Function(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))) |
        (:\s*((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*))))))) |
        (:\s*(=>|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(<[^<>]*>)|[^<>(),=])+=\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        )))
      captures:
        1: storage.modifier.ts
        2: keyword.operator.rest.ts
        3: entity.name.function.ts variable.language.this.ts
        4: entity.name.function.ts
        5: keyword.operator.optional.ts
    - match: '(?x)(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(public|private|protected|readonly)\s+)?(?:(\.\.\.)\s*)?(?<!=|:)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(this)|([_$[:alpha:]][_$[:alnum:]]*))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*(\??)'
      captures:
        1: storage.modifier.ts
        2: keyword.operator.rest.ts
        3: variable.parameter.ts variable.language.this.ts
        4: variable.parameter.ts
        5: keyword.operator.optional.ts
  parameter-object-binding-element:
    - include: comment
    - match: |-
        (?x)(?=((\b(?<!\$)0(?:x|X)[0-9a-fA-F][0-9a-fA-F_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:b|B)[01][01_]*(n)?\b(?!\$))|(\b(?<!\$)0(?:o|O)?[0-7][0-7_]*(n)?\b(?!\$))|((?<!\$)(?:
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)| # 1.1E+3
          (?:\b[0-9][0-9_]*(\.)[eE][+-]?[0-9][0-9_]*(n)?\b)|             # 1.E+3
          (?:\B(\.)[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|             # .1E+3
          (?:\b[0-9][0-9_]*[eE][+-]?[0-9][0-9_]*(n)?\b)|                 # 1E+3
          (?:\b[0-9][0-9_]*(\.)[0-9][0-9_]*(n)?\b)|                      # 1.1
          (?:\b[0-9][0-9_]*(\.)(n)?\B)|                                  # 1.
          (?:\B(\.)[0-9][0-9_]*(n)?\b)|                                  # .1
          (?:\b[0-9][0-9_]*(n)?\b(?!\.))                                 # 1
        )(?!\$))|([_$[:alpha:]][_$[:alnum:]]*)|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`)|(\[([^\[\]]|\[[^\[\]]*\])+\]))\s*(:))
      push:
        - match: '(?=,|\})'
          pop: true
        - include: object-binding-element-propertyName
        - include: parameter-binding-element
    - include: parameter-object-binding-pattern
    - include: destructuring-parameter-rest
    - include: variable-initializer
    - include: punctuation-comma
  parameter-object-binding-pattern:
    - match: '(?:(\.\.\.)\s*)?(\{)'
      captures:
        1: keyword.operator.rest.ts
        2: punctuation.definition.binding-pattern.object.ts
      push:
        - match: '\}'
          captures:
            0: punctuation.definition.binding-pattern.object.ts
          pop: true
        - include: parameter-object-binding-element
  parameter-type-annotation:
    - match: (:)
      captures:
        1: keyword.operator.type.annotation.ts
      push:
        - meta_scope: meta.type.annotation.ts
        - match: "(?=[,)])|(?==[^>])"
          pop: true
        - include: type
  paren-expression:
    - match: \(
      captures:
        0: meta.brace.round.ts
      push:
        - match: \)
          captures:
            0: meta.brace.round.ts
          pop: true
        - include: expression
  paren-expression-possibly-arrow:
    - match: '(?<=[(=,])\s*(async)?(?=\s*((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*))?\(\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))'
      captures:
        1: storage.modifier.async.ts
      push:
        - match: (?<=\))
          pop: true
        - include: paren-expression-possibly-arrow-with-typeparameters
    - match: '(?<=[(=,]|=>|^return|[^\._$[:alnum:]]return)\s*(async)?(?=\s*((((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*))?\()|(<))\s*$)'
      captures:
        1: storage.modifier.async.ts
      push:
        - match: (?<=\))
          pop: true
        - include: paren-expression-possibly-arrow-with-typeparameters
    - include: possibly-arrow-return-type
  paren-expression-possibly-arrow-with-typeparameters:
    - include: type-parameters
    - match: \(
      captures:
        0: meta.brace.round.ts
      push:
        - match: \)
          captures:
            0: meta.brace.round.ts
          pop: true
        - include: expression-inside-possibly-arrow-parens
  possibly-arrow-return-type:
    - match: '(?<=\)|^)\s*(:)(?=\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*=>)'
      captures:
        1: meta.arrow.ts meta.return.type.arrow.ts keyword.operator.type.annotation.ts
      push:
        - meta_content_scope: meta.arrow.ts meta.return.type.arrow.ts
        - match: '(?==>|\{|(^\s*(export|function|class|interface|let|var|const|import|enum|namespace|module|type|abstract|declare)\s+))'
          pop: true
        - include: arrow-return-type-body
  property-accessor:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(get|set)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: storage.type.property.ts
  punctuation-accessor:
    - match: '(?:(\.)|(\?\.(?!\s*[[:digit:]])))'
      captures:
        1: punctuation.accessor.ts
        2: punctuation.accessor.optional.ts
  punctuation-comma:
    - match: ","
      scope: punctuation.separator.comma.ts
  punctuation-semicolon:
    - match: ;
      scope: punctuation.terminator.statement.ts
  qstring-double:
    - match: '"'
      captures:
        0: punctuation.definition.string.begin.ts
      push:
        - meta_scope: string.quoted.double.ts
        - match: '(")|((?:[^\\\n])$)'
          captures:
            1: punctuation.definition.string.end.ts
            2: invalid.illegal.newline.ts
          pop: true
        - include: string-character-escape
  qstring-single:
    - match: "'"
      captures:
        0: punctuation.definition.string.begin.ts
      push:
        - meta_scope: string.quoted.single.ts
        - match: '(\'')|((?:[^\\\n])$)'
          captures:
            1: punctuation.definition.string.end.ts
            2: invalid.illegal.newline.ts
          pop: true
        - include: string-character-escape
  regex:
    - match: '(?<!\+\+|--|})(?<=[=(:,\[?+!]|^return|[^\._$[:alnum:]]return|^case|[^\._$[:alnum:]]case|=>|&&|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[\()]|\\.|\[([^\]\\]|\\.)+\]|\(([^\)\\]|\\.)+\))+\/([gimsuy]+|(?![\/\*])|(?=\/\*))(?!\s*[a-zA-Z0-9_$]))'
      captures:
        1: punctuation.definition.string.begin.ts
      push:
        - meta_scope: string.regexp.ts
        - match: "(/)([gimsuy]*)"
          captures:
            1: punctuation.definition.string.end.ts
            2: keyword.other.ts
          pop: true
        - include: regexp
    - match: '((?<![_$[:alnum:])\]]|\+\+|--|}|\*\/)|((?<=^return|[^\._$[:alnum:]]return|^case|[^\._$[:alnum:]]case))\s*)\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/([gimsuy]+|(?![\/\*])|(?=\/\*))(?!\s*[a-zA-Z0-9_$]))'
      captures:
        0: punctuation.definition.string.begin.ts
      push:
        - meta_scope: string.regexp.ts
        - match: "(/)([gimsuy]*)"
          captures:
            1: punctuation.definition.string.end.ts
            2: keyword.other.ts
          pop: true
        - include: regexp
  regex-character-class:
    - match: '\\[wWsSdDtrnvf]|\.'
      scope: constant.other.character-class.regexp
    - match: '\\([0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4})'
      scope: constant.character.numeric.regexp
    - match: '\\c[A-Z]'
      scope: constant.character.control.regexp
    - match: \\.
      scope: constant.character.escape.backslash.regexp
  regexp:
    - match: '\\[bB]|\^|\$'
      scope: keyword.control.anchor.regexp
    - match: '\\[1-9]\d*|\\k<([a-zA-Z_$][\w$]*)>'
      captures:
        0: keyword.other.back-reference.regexp
        1: variable.other.regexp
    - match: '[?+*]|\{(\d+,\d+|\d+,|,\d+|\d+)\}\??'
      scope: keyword.operator.quantifier.regexp
    - match: \|
      scope: keyword.operator.or.regexp
    - match: (\()((\?=)|(\?!)|(\?<=)|(\?<!))
      captures:
        1: punctuation.definition.group.regexp
        2: punctuation.definition.group.assertion.regexp
        3: meta.assertion.look-ahead.regexp
        4: meta.assertion.negative-look-ahead.regexp
        5: meta.assertion.look-behind.regexp
        6: meta.assertion.negative-look-behind.regexp
      push:
        - meta_scope: meta.group.assertion.regexp
        - match: (\))
          captures:
            1: punctuation.definition.group.regexp
          pop: true
        - include: regexp
    - match: '\((?:(\?:)|(?:\?<([a-zA-Z_$][\w$]*)>))?'
      captures:
        0: punctuation.definition.group.regexp
        1: punctuation.definition.group.no-capture.regexp
        2: variable.other.regexp
      push:
        - meta_scope: meta.group.regexp
        - match: \)
          captures:
            0: punctuation.definition.group.regexp
          pop: true
        - include: regexp
    - match: '(\[)(\^)?'
      captures:
        1: punctuation.definition.character-class.regexp
        2: keyword.operator.negation.regexp
      push:
        - meta_scope: constant.other.character-class.set.regexp
        - match: '(\])'
          captures:
            1: punctuation.definition.character-class.regexp
          pop: true
        - match: '(?:.|(\\(?:[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}))|(\\c[A-Z])|(\\.))\-(?:[^\]\\]|(\\(?:[0-7]{3}|x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}))|(\\c[A-Z])|(\\.))'
          scope: constant.other.character-class.range.regexp
          captures:
            1: constant.character.numeric.regexp
            2: constant.character.control.regexp
            3: constant.character.escape.backslash.regexp
            4: constant.character.numeric.regexp
            5: constant.character.control.regexp
            6: constant.character.escape.backslash.regexp
        - include: regex-character-class
    - include: regex-character-class
  return-type:
    - match: (?<=\))\s*(:)(?=\s*\S)
      captures:
        1: keyword.operator.type.annotation.ts
      push:
        - meta_scope: meta.return.type.ts
        - match: "(?<![:|&])(?=$|^|[{};,]|//)"
          pop: true
        - include: return-type-core
    - match: (?<=\))\s*(:)
      captures:
        1: keyword.operator.type.annotation.ts
      push:
        - meta_scope: meta.return.type.ts
        - match: '(?<![:|&])((?=[{};,]|//|^\s*$)|((?<=\S)(?=\s*$)))'
          pop: true
        - include: return-type-core
  return-type-core:
    - include: comment
    - match: '(?<=[:|&])(?=\s*\{)'
      push:
        - match: '(?<=\})'
          pop: true
        - include: type-object
    - include: type-predicate-operator
    - include: type
  shebang:
    - match: \A(#!).*(?=$)
      scope: comment.line.shebang.ts
      captures:
        1: punctuation.definition.comment.ts
  single-line-comment-consuming-line-ending:
    - match: '(^[ \t]+)?((//)(?:\s*((@)internal)(?=\s|$))?)'
      captures:
        1: punctuation.whitespace.comment.leading.ts
        2: comment.line.double-slash.ts
        3: punctuation.definition.comment.ts
        4: storage.type.internaldeclaration.ts
        5: punctuation.decorator.internaldeclaration.ts
      push:
        - meta_content_scope: comment.line.double-slash.ts
        - match: (?=^)
          pop: true
  statements:
    - include: declaration
    - include: control-statement
    - include: after-operator-block-as-object-literal
    - include: decl-block
    - include: label
    - include: expression
    - include: punctuation-semicolon
    - include: string
    - include: comment
  string:
    - include: qstring-single
    - include: qstring-double
    - include: template
  string-character-escape:
    - match: '\\(x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]+\}|[0-2][0-7]{0,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.|$)'
      scope: constant.character.escape.ts
  super-literal:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))super\b(?!\$)'
      scope: variable.language.super.ts
  support-function-call-identifiers:
    - include: literal
    - include: support-objects
    - include: object-identifiers
    - include: punctuation-accessor
    - match: '(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))import(?=\s*[\(]\s*[\"\''\`]))'
      scope: keyword.operator.expression.import.ts
  support-objects:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(arguments)\b(?!\$)'
      scope: variable.language.arguments.ts
    - match: |-
        (?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(Array|ArrayBuffer|Atomics|BigInt|BigInt64Array|BigUint64Array|Boolean|DataView|Date|Float32Array
        |Float64Array|Function|Generator|GeneratorFunction|Int8Array|Int16Array|Int32Array|Intl|Map|Number|Object|Proxy
        |Reflect|RegExp|Set|SharedArrayBuffer|SIMD|String|Symbol|TypedArray
        |Uint8Array|Uint16Array|Uint32Array|Uint8ClampedArray|WeakMap|WeakSet)\b(?!\$)
      scope: support.class.builtin.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))((Eval|Internal|Range|Reference|Syntax|Type|URI)?Error)\b(?!\$)'
      scope: support.class.error.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(Promise)\b(?!\$)'
      scope: support.class.promise.ts
    - match: |-
        (?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(clear(Interval|Timeout)|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|escape|eval|
        isFinite|isNaN|parseFloat|parseInt|require|set(Interval|Timeout)|super|unescape|uneval)(?=\s*\()
      scope: support.function.ts
    - match: |-
        (?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(Math)(?:\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(?:
        (abs|acos|acosh|asin|asinh|atan|atan2|atanh|cbrt|ceil|clz32|cos|cosh|exp|
        expm1|floor|fround|hypot|imul|log|log10|log1p|log2|max|min|pow|random|
        round|sign|sin|sinh|sqrt|tan|tanh|trunc)
        |
        (E|LN10|LN2|LOG10E|LOG2E|PI|SQRT1_2|SQRT2)))?\b(?!\$)
      captures:
        1: support.constant.math.ts
        2: punctuation.accessor.ts
        3: punctuation.accessor.optional.ts
        4: support.function.math.ts
        5: support.constant.property.math.ts
    - match: |-
        (?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(console)(?:\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(
        assert|clear|count|debug|dir|error|group|groupCollapsed|groupEnd|info|log
        |profile|profileEnd|table|time|timeEnd|timeStamp|trace|warn))?\b(?!\$)
      captures:
        1: support.class.console.ts
        2: punctuation.accessor.ts
        3: punctuation.accessor.optional.ts
        4: support.function.console.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(JSON)(?:\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(parse|stringify))?\b(?!\$)'
      captures:
        1: support.constant.json.ts
        2: punctuation.accessor.ts
        3: punctuation.accessor.optional.ts
        4: support.function.json.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(import)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(meta)\b(?!\$)'
      captures:
        1: keyword.control.import.ts
        2: punctuation.accessor.ts
        3: punctuation.accessor.optional.ts
        4: support.variable.property.importmeta.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(new)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(target)\b(?!\$)'
      captures:
        1: keyword.operator.new.ts
        2: punctuation.accessor.ts
        3: punctuation.accessor.optional.ts
        4: support.variable.property.target.ts
    - match: |-
        (?x) (?:(\.)|(\?\.(?!\s*[[:digit:]]))) \s* (?:
        (?:(constructor|length|prototype|__proto__)\b(?!\$|\s*(<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?\())
        |
        (?:(EPSILON|MAX_SAFE_INTEGER|MAX_VALUE|MIN_SAFE_INTEGER|MIN_VALUE|NEGATIVE_INFINITY|POSITIVE_INFINITY)\b(?!\$)))
      captures:
        1: punctuation.accessor.ts
        2: punctuation.accessor.optional.ts
        3: support.variable.property.ts
        4: support.constant.ts
    - match: |-
        (?x) (?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.)) \b (?:
        (document|event|navigator|performance|screen|window)
        |
        (AnalyserNode|ArrayBufferView|Attr|AudioBuffer|AudioBufferSourceNode|AudioContext|AudioDestinationNode|AudioListener
        |AudioNode|AudioParam|BatteryManager|BeforeUnloadEvent|BiquadFilterNode|Blob|BufferSource|ByteString|CSS|CSSConditionRule
        |CSSCounterStyleRule|CSSGroupingRule|CSSMatrix|CSSMediaRule|CSSPageRule|CSSPrimitiveValue|CSSRule|CSSRuleList|CSSStyleDeclaration
        |CSSStyleRule|CSSStyleSheet|CSSSupportsRule|CSSValue|CSSValueList|CanvasGradient|CanvasImageSource|CanvasPattern
        |CanvasRenderingContext2D|ChannelMergerNode|ChannelSplitterNode|CharacterData|ChromeWorker|CloseEvent|Comment|CompositionEvent
        |Console|ConvolverNode|Coordinates|Credential|CredentialsContainer|Crypto|CryptoKey|CustomEvent|DOMError|DOMException
        |DOMHighResTimeStamp|DOMImplementation|DOMString|DOMStringList|DOMStringMap|DOMTimeStamp|DOMTokenList|DataTransfer
        |DataTransferItem|DataTransferItemList|DedicatedWorkerGlobalScope|DelayNode|DeviceProximityEvent|DirectoryEntry
        |DirectoryEntrySync|DirectoryReader|DirectoryReaderSync|Document|DocumentFragment|DocumentTouch|DocumentType|DragEvent
        |DynamicsCompressorNode|Element|Entry|EntrySync|ErrorEvent|Event|EventListener|EventSource|EventTarget|FederatedCredential
        |FetchEvent|File|FileEntry|FileEntrySync|FileException|FileList|FileReader|FileReaderSync|FileSystem|FileSystemSync
        |FontFace|FormData|GainNode|Gamepad|GamepadButton|GamepadEvent|Geolocation|GlobalEventHandlers|HTMLAnchorElement
        |HTMLAreaElement|HTMLAudioElement|HTMLBRElement|HTMLBaseElement|HTMLBodyElement|HTMLButtonElement|HTMLCanvasElement
        |HTMLCollection|HTMLContentElement|HTMLDListElement|HTMLDataElement|HTMLDataListElement|HTMLDialogElement|HTMLDivElement
        |HTMLDocument|HTMLElement|HTMLEmbedElement|HTMLFieldSetElement|HTMLFontElement|HTMLFormControlsCollection|HTMLFormElement
        |HTMLHRElement|HTMLHeadElement|HTMLHeadingElement|HTMLHtmlElement|HTMLIFrameElement|HTMLImageElement|HTMLInputElement
        |HTMLKeygenElement|HTMLLIElement|HTMLLabelElement|HTMLLegendElement|HTMLLinkElement|HTMLMapElement|HTMLMediaElement
        |HTMLMetaElement|HTMLMeterElement|HTMLModElement|HTMLOListElement|HTMLObjectElement|HTMLOptGroupElement|HTMLOptionElement
        |HTMLOptionsCollection|HTMLOutputElement|HTMLParagraphElement|HTMLParamElement|HTMLPreElement|HTMLProgressElement
        |HTMLQuoteElement|HTMLScriptElement|HTMLSelectElement|HTMLShadowElement|HTMLSourceElement|HTMLSpanElement|HTMLStyleElement
        |HTMLTableCaptionElement|HTMLTableCellElement|HTMLTableColElement|HTMLTableDataCellElement|HTMLTableElement|HTMLTableHeaderCellElement
        |HTMLTableRowElement|HTMLTableSectionElement|HTMLTextAreaElement|HTMLTimeElement|HTMLTitleElement|HTMLTrackElement
        |HTMLUListElement|HTMLUnknownElement|HTMLVideoElement|HashChangeEvent|History|IDBCursor|IDBCursorWithValue|IDBDatabase
        |IDBEnvironment|IDBFactory|IDBIndex|IDBKeyRange|IDBMutableFile|IDBObjectStore|IDBOpenDBRequest|IDBRequest|IDBTransaction
        |IDBVersionChangeEvent|IIRFilterNode|IdentityManager|ImageBitmap|ImageBitmapFactories|ImageData|Index|InputDeviceCapabilities
        |InputEvent|InstallEvent|InstallTrigger|KeyboardEvent|LinkStyle|LocalFileSystem|LocalFileSystemSync|Location|MIDIAccess
        |MIDIConnectionEvent|MIDIInput|MIDIInputMap|MIDIOutputMap|MediaElementAudioSourceNode|MediaError|MediaKeyMessageEvent
        |MediaKeySession|MediaKeyStatusMap|MediaKeySystemAccess|MediaKeySystemConfiguration|MediaKeys|MediaRecorder|MediaStream
        |MediaStreamAudioDestinationNode|MediaStreamAudioSourceNode|MessageChannel|MessageEvent|MessagePort|MouseEvent
        |MutationObserver|MutationRecord|NamedNodeMap|Navigator|NavigatorConcurrentHardware|NavigatorGeolocation|NavigatorID
        |NavigatorLanguage|NavigatorOnLine|Node|NodeFilter|NodeIterator|NodeList|NonDocumentTypeChildNode|Notification
        |OfflineAudioCompletionEvent|OfflineAudioContext|OscillatorNode|PageTransitionEvent|PannerNode|ParentNode|PasswordCredential
        |Path2D|PaymentAddress|PaymentRequest|PaymentResponse|Performance|PerformanceEntry|PerformanceFrameTiming|PerformanceMark
        |PerformanceMeasure|PerformanceNavigation|PerformanceNavigationTiming|PerformanceObserver|PerformanceObserverEntryList
        |PerformanceResourceTiming|PerformanceTiming|PeriodicSyncEvent|PeriodicWave|Plugin|Point|PointerEvent|PopStateEvent
        |PortCollection|Position|PositionError|PositionOptions|PresentationConnectionClosedEvent|PresentationConnectionList
        |PresentationReceiver|ProcessingInstruction|ProgressEvent|PromiseRejectionEvent|PushEvent|PushRegistrationManager
        |RTCCertificate|RTCConfiguration|RTCPeerConnection|RTCSessionDescriptionCallback|RTCStatsReport|RadioNodeList|RandomSource
        |Range|ReadableByteStream|RenderingContext|SVGAElement|SVGAngle|SVGAnimateColorElement|SVGAnimateElement|SVGAnimateMotionElement
        |SVGAnimateTransformElement|SVGAnimatedAngle|SVGAnimatedBoolean|SVGAnimatedEnumeration|SVGAnimatedInteger|SVGAnimatedLength
        |SVGAnimatedLengthList|SVGAnimatedNumber|SVGAnimatedNumberList|SVGAnimatedPoints|SVGAnimatedPreserveAspectRatio
        |SVGAnimatedRect|SVGAnimatedString|SVGAnimatedTransformList|SVGAnimationElement|SVGCircleElement|SVGClipPathElement
        |SVGCursorElement|SVGDefsElement|SVGDescElement|SVGElement|SVGEllipseElement|SVGEvent|SVGFilterElement|SVGFontElement
        |SVGFontFaceElement|SVGFontFaceFormatElement|SVGFontFaceNameElement|SVGFontFaceSrcElement|SVGFontFaceUriElement
        |SVGForeignObjectElement|SVGGElement|SVGGlyphElement|SVGGradientElement|SVGHKernElement|SVGImageElement|SVGLength
        |SVGLengthList|SVGLineElement|SVGLinearGradientElement|SVGMPathElement|SVGMaskElement|SVGMatrix|SVGMissingGlyphElement
        |SVGNumber|SVGNumberList|SVGPathElement|SVGPatternElement|SVGPoint|SVGPolygonElement|SVGPolylineElement|SVGPreserveAspectRatio
        |SVGRadialGradientElement|SVGRect|SVGRectElement|SVGSVGElement|SVGScriptElement|SVGSetElement|SVGStopElement|SVGStringList
        |SVGStylable|SVGStyleElement|SVGSwitchElement|SVGSymbolElement|SVGTRefElement|SVGTSpanElement|SVGTests|SVGTextElement
        |SVGTextPositioningElement|SVGTitleElement|SVGTransform|SVGTransformList|SVGTransformable|SVGUseElement|SVGVKernElement
        |SVGViewElement|ServiceWorker|ServiceWorkerContainer|ServiceWorkerGlobalScope|ServiceWorkerRegistration|ServiceWorkerState
        |ShadowRoot|SharedWorker|SharedWorkerGlobalScope|SourceBufferList|StereoPannerNode|Storage|StorageEvent|StyleSheet
        |StyleSheetList|SubtleCrypto|SyncEvent|Text|TextMetrics|TimeEvent|TimeRanges|Touch|TouchEvent|TouchList|Transferable
        |TreeWalker|UIEvent|USVString|VRDisplayCapabilities|ValidityState|WaveShaperNode|WebGL|WebGLActiveInfo|WebGLBuffer
        |WebGLContextEvent|WebGLFramebuffer|WebGLProgram|WebGLRenderbuffer|WebGLRenderingContext|WebGLShader|WebGLShaderPrecisionFormat
        |WebGLTexture|WebGLTimerQueryEXT|WebGLTransformFeedback|WebGLUniformLocation|WebGLVertexArrayObject|WebGLVertexArrayObjectOES
        |WebSocket|WebSockets|WebVTT|WheelEvent|Window|WindowBase64|WindowEventHandlers|WindowTimers|Worker|WorkerGlobalScope
        |WorkerLocation|WorkerNavigator|XMLHttpRequest|XMLHttpRequestEventTarget|XMLSerializer|XPathExpression|XPathResult
        |XSLTProcessor))\b(?!\$)
      captures:
        1: support.variable.dom.ts
        2: support.class.dom.ts
    - match: |-
        (?x) (?:(\.)|(\?\.(?!\s*[[:digit:]]))) \s* (?:
        (ATTRIBUTE_NODE|CDATA_SECTION_NODE|COMMENT_NODE|DOCUMENT_FRAGMENT_NODE|DOCUMENT_NODE|DOCUMENT_TYPE_NODE
        |DOMSTRING_SIZE_ERR|ELEMENT_NODE|ENTITY_NODE|ENTITY_REFERENCE_NODE|HIERARCHY_REQUEST_ERR|INDEX_SIZE_ERR
        |INUSE_ATTRIBUTE_ERR|INVALID_CHARACTER_ERR|NO_DATA_ALLOWED_ERR|NO_MODIFICATION_ALLOWED_ERR|NOT_FOUND_ERR
        |NOT_SUPPORTED_ERR|NOTATION_NODE|PROCESSING_INSTRUCTION_NODE|TEXT_NODE|WRONG_DOCUMENT_ERR)
        |
        (_content|[xyz]|abbr|above|accept|acceptCharset|accessKey|action|align|[av]Link(?:color)?|all|alt|anchors|appCodeName
        |appCore|applets|appMinorVersion|appName|appVersion|archive|areas|arguments|attributes|availHeight|availLeft|availTop
        |availWidth|axis|background|backgroundColor|backgroundImage|below|bgColor|body|border|borderBottomWidth|borderColor
        |borderLeftWidth|borderRightWidth|borderStyle|borderTopWidth|borderWidth|bottom|bufferDepth|callee|caller|caption
        |cellPadding|cells|cellSpacing|ch|characterSet|charset|checked|childNodes|chOff|cite|classes|className|clear
        |clientInformation|clip|clipBoardData|closed|code|codeBase|codeType|color|colorDepth|cols|colSpan|compact|complete
        |components|content|controllers|cookie|cookieEnabled|cords|cpuClass|crypto|current|data|dateTime|declare|defaultCharset
        |defaultChecked|defaultSelected|defaultStatus|defaultValue|defaultView|defer|description|dialogArguments|dialogHeight
        |dialogLeft|dialogTop|dialogWidth|dir|directories|disabled|display|docmain|doctype|documentElement|elements|embeds
        |enabledPlugin|encoding|enctype|entities|event|expando|external|face|fgColor|filename|firstChild|fontFamily|fontSize
        |fontWeight|form|formName|forms|frame|frameBorder|frameElement|frames|hasFocus|hash|headers|height|history|host
        |hostname|href|hreflang|hspace|htmlFor|httpEquiv|id|ids|ignoreCase|images|implementation|index|innerHeight|innerWidth
        |input|isMap|label|lang|language|lastChild|lastIndex|lastMatch|lastModified|lastParen|layer[sXY]|left|leftContext
        |lineHeight|link|linkColor|links|listStyleType|localName|location|locationbar|longDesc|lowsrc|lowSrc|marginBottom
        |marginHeight|marginLeft|marginRight|marginTop|marginWidth|maxLength|media|menubar|method|mimeTypes|multiline|multiple
        |name|nameProp|namespaces|namespaceURI|next|nextSibling|nodeName|nodeType|nodeValue|noHref|noResize|noShade|notationName
        |notations|noWrap|object|offscreenBuffering|onLine|onreadystatechange|opener|opsProfile|options|oscpu|outerHeight
        |outerWidth|ownerDocument|paddingBottom|paddingLeft|paddingRight|paddingTop|page[XY]|page[XY]Offset|parent|parentLayer
        |parentNode|parentWindow|pathname|personalbar|pixelDepth|pkcs11|platform|plugins|port|prefix|previous|previousDibling
        |product|productSub|profile|profileend|prompt|prompter|protocol|publicId|readOnly|readyState|referrer|rel|responseText
        |responseXML|rev|right|rightContext|rowIndex|rows|rowSpan|rules|scheme|scope|screen[XY]|screenLeft|screenTop|scripts
        |scrollbars|scrolling|sectionRowIndex|security|securityPolicy|selected|selectedIndex|selection|self|shape|siblingAbove
        |siblingBelow|size|source|specified|standby|start|status|statusbar|statusText|style|styleSheets|suffixes|summary
        |systemId|systemLanguage|tagName|tags|target|tBodies|text|textAlign|textDecoration|textIndent|textTransform|tFoot|tHead
        |title|toolbar|top|type|undefined|uniqueID|updateInterval|URL|URLUnencoded|useMap|userAgent|userLanguage|userProfile
        |vAlign|value|valueType|vendor|vendorSub|version|visibility|vspace|whiteSpace|width|X[MS]LDocument|zIndex))\b(?!\$|\s*(<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?\()
      captures:
        1: punctuation.accessor.ts
        2: punctuation.accessor.optional.ts
        3: support.constant.dom.ts
        4: support.variable.property.dom.ts
    - match: |-
        (?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(Buffer|EventEmitter|Server|Pipe|Socket|REPLServer|ReadStream|WriteStream|Stream
        |Inflate|Deflate|InflateRaw|DeflateRaw|GZip|GUnzip|Unzip|Zip)\b(?!\$)
      scope: support.class.node.ts
    - match: |-
        (?x)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(process)(?:(?:(\.)|(\?\.(?!\s*[[:digit:]])))(?:
          (arch|argv|config|connected|env|execArgv|execPath|exitCode|mainModule|pid|platform|release|stderr|stdin|stdout|title|version|versions)
          |
          (abort|chdir|cwd|disconnect|exit|[sg]ete?[gu]id|send|[sg]etgroups|initgroups|kill|memoryUsage|nextTick|umask|uptime|hrtime)
        ))?\b(?!\$)
      captures:
        1: support.variable.object.process.ts
        2: punctuation.accessor.ts
        3: punctuation.accessor.optional.ts
        4: support.variable.property.process.ts
        5: support.function.process.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(exports)|(module)(?:(?:(\.)|(\?\.(?!\s*[[:digit:]])))(exports|id|filename|loaded|parent|children))?)\b(?!\$)'
      captures:
        1: support.type.object.module.ts
        2: support.type.object.module.ts
        3: punctuation.accessor.ts
        4: punctuation.accessor.optional.ts
        5: support.type.object.module.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(global|GLOBAL|root|__dirname|__filename)\b(?!\$)'
      scope: support.variable.object.node.ts
    - match: |-
        (?x) (?:(\.)|(\?\.(?!\s*[[:digit:]]))) \s*
        (?:
         (on(?:Rowsinserted|Rowsdelete|Rowenter|Rowexit|Resize|Resizestart|Resizeend|Reset|
           Readystatechange|Mouseout|Mouseover|Mousedown|Mouseup|Mousemove|
           Before(?:cut|deactivate|unload|update|paste|print|editfocus|activate)|
           Blur|Scrolltop|Submit|Select|Selectstart|Selectionchange|Hover|Help|
           Change|Contextmenu|Controlselect|Cut|Cellchange|Clock|Close|Deactivate|
           Datasetchanged|Datasetcomplete|Dataavailable|Drop|Drag|Dragstart|Dragover|
           Dragdrop|Dragenter|Dragend|Dragleave|Dblclick|Unload|Paste|Propertychange|Error|
           Errorupdate|Keydown|Keyup|Keypress|Focus|Load|Activate|Afterupdate|Afterprint|Abort)
         ) |
         (shift|showModelessDialog|showModalDialog|showHelp|scroll|scrollX|scrollByPages|
           scrollByLines|scrollY|scrollTo|stop|strike|sizeToContent|sidebar|signText|sort|
           sup|sub|substr|substring|splice|split|send|set(?:Milliseconds|Seconds|Minutes|Hours|
           Month|Year|FullYear|Date|UTC(?:Milliseconds|Seconds|Minutes|Hours|Month|FullYear|Date)|
           Time|Hotkeys|Cursor|ZOptions|Active|Resizable|RequestHeader)|search|slice|
           savePreferences|small|home|handleEvent|navigate|char|charCodeAt|charAt|concat|
           contextual|confirm|compile|clear|captureEvents|call|createStyleSheet|createPopup|
           createEventObject|to(?:GMTString|UTCString|String|Source|UpperCase|LowerCase|LocaleString)|
           test|taint|taintEnabled|indexOf|italics|disableExternalCapture|dump|detachEvent|unshift|
           untaint|unwatch|updateCommands|join|javaEnabled|pop|push|plugins.refresh|paddings|parse|
           print|prompt|preference|enableExternalCapture|exec|execScript|valueOf|UTC|find|file|
           fileModifiedDate|fileSize|fileCreatedDate|fileUpdatedDate|fixed|fontsize|fontcolor|
           forward|fromCharCode|watch|link|load|lastIndexOf|anchor|attachEvent|atob|apply|alert|
           abort|routeEvents|resize|resizeBy|resizeTo|recalc|returnValue|replace|reverse|reload|
           releaseCapture|releaseEvents|go|get(?:Milliseconds|Seconds|Minutes|Hours|Month|Day|Year|FullYear|
           Time|Date|TimezoneOffset|UTC(?:Milliseconds|Seconds|Minutes|Hours|Day|Month|FullYear|Date)|
           Attention|Selection|ResponseHeader|AllResponseHeaders)|moveBy|moveBelow|moveTo|
           moveToAbsolute|moveAbove|mergeAttributes|match|margins|btoa|big|bold|borderWidths|blink|back
         ) |
         (acceptNode|add|addEventListener|addTextTrack|adoptNode|after|animate|append|
           appendChild|appendData|before|blur|canPlayType|captureStream|
           caretPositionFromPoint|caretRangeFromPoint|checkValidity|clear|click|
           cloneContents|cloneNode|cloneRange|close|closest|collapse|
           compareBoundaryPoints|compareDocumentPosition|comparePoint|contains|
           convertPointFromNode|convertQuadFromNode|convertRectFromNode|createAttribute|
           createAttributeNS|createCaption|createCDATASection|createComment|
           createContextualFragment|createDocument|createDocumentFragment|
           createDocumentType|createElement|createElementNS|createEntityReference|
           createEvent|createExpression|createHTMLDocument|createNodeIterator|
           createNSResolver|createProcessingInstruction|createRange|createShadowRoot|
           createTBody|createTextNode|createTFoot|createTHead|createTreeWalker|delete|
           deleteCaption|deleteCell|deleteContents|deleteData|deleteRow|deleteTFoot|
           deleteTHead|detach|disconnect|dispatchEvent|elementFromPoint|elementsFromPoint|
           enableStyleSheetsForSet|entries|evaluate|execCommand|exitFullscreen|
           exitPointerLock|expand|extractContents|fastSeek|firstChild|focus|forEach|get|
           getAll|getAnimations|getAttribute|getAttributeNames|getAttributeNode|
           getAttributeNodeNS|getAttributeNS|getBoundingClientRect|getBoxQuads|
           getClientRects|getContext|getDestinationInsertionPoints|getElementById|
           getElementsByClassName|getElementsByName|getElementsByTagName|
           getElementsByTagNameNS|getItem|getNamedItem|getSelection|getStartDate|
           getVideoPlaybackQuality|has|hasAttribute|hasAttributeNS|hasAttributes|
           hasChildNodes|hasFeature|hasFocus|importNode|initEvent|insertAdjacentElement|
           insertAdjacentHTML|insertAdjacentText|insertBefore|insertCell|insertData|
           insertNode|insertRow|intersectsNode|isDefaultNamespace|isEqualNode|
           isPointInRange|isSameNode|item|key|keys|lastChild|load|lookupNamespaceURI|
           lookupPrefix|matches|move|moveAttribute|moveAttributeNode|moveChild|
           moveNamedItem|namedItem|nextNode|nextSibling|normalize|observe|open|
           parentNode|pause|play|postMessage|prepend|preventDefault|previousNode|
           previousSibling|probablySupportsContext|queryCommandEnabled|
           queryCommandIndeterm|queryCommandState|queryCommandSupported|queryCommandValue|
           querySelector|querySelectorAll|registerContentHandler|registerElement|
           registerProtocolHandler|releaseCapture|releaseEvents|remove|removeAttribute|
           removeAttributeNode|removeAttributeNS|removeChild|removeEventListener|
           removeItem|replace|replaceChild|replaceData|replaceWith|reportValidity|
           requestFullscreen|requestPointerLock|reset|scroll|scrollBy|scrollIntoView|
           scrollTo|seekToNextFrame|select|selectNode|selectNodeContents|set|setAttribute|
           setAttributeNode|setAttributeNodeNS|setAttributeNS|setCapture|
           setCustomValidity|setEnd|setEndAfter|setEndBefore|setItem|setNamedItem|
           setRangeText|setSelectionRange|setSinkId|setStart|setStartAfter|setStartBefore|
           slice|splitText|stepDown|stepUp|stopImmediatePropagation|stopPropagation|
           submit|substringData|supports|surroundContents|takeRecords|terminate|toBlob|
           toDataURL|toggle|toString|values|write|writeln
         ) |
         (all|catch|finally|race|reject|resolve|then
         )
        )(?=\s*\()
      captures:
        1: punctuation.accessor.ts
        2: punctuation.accessor.optional.ts
        3: support.function.event-handler.ts
        4: support.function.ts
        5: support.function.dom.ts
        6: support.function.promise.ts
  switch-statement:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?=\bswitch\s*\()'
      push:
        - meta_scope: switch-statement.expr.ts
        - match: '\}'
          captures:
            0: punctuation.definition.block.ts
          pop: true
        - include: comment
        - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(switch)\s*(\()'
          captures:
            1: keyword.control.switch.ts
            2: meta.brace.round.ts
          push:
            - meta_scope: switch-expression.expr.ts
            - match: \)
              captures:
                0: meta.brace.round.ts
              pop: true
            - include: expression
        - match: '\{'
          captures:
            0: punctuation.definition.block.ts
          push:
            - meta_scope: switch-block.expr.ts
            - match: '(?=\})'
              pop: true
            - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(case|default(?=:))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
              captures:
                1: keyword.control.switch.ts
              push:
                - meta_scope: case-clause.expr.ts
                - match: (?=:)
                  pop: true
                - include: expression
            - match: '(:)\s*(\{)'
              captures:
                1: case-clause.expr.ts punctuation.definition.section.case-statement.ts
                2: meta.block.ts punctuation.definition.block.ts
              push:
                - meta_content_scope: meta.block.ts
                - match: '\}'
                  captures:
                    0: meta.block.ts punctuation.definition.block.ts
                  pop: true
                - include: statements
            - match: (:)
              captures:
                0: case-clause.expr.ts punctuation.definition.section.case-statement.ts
            - include: statements
  template:
    - match: '(?=(([_$[:alpha:]][_$[:alnum:]]*\s*\??\.\s*)*|(\??\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*)(<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))(([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>)*(?<!=)\>))*(?<!=)\>)*(?<!=)>\s*)?`)'
      push:
        - meta_scope: string.template.ts
        - match: (?=`)
          pop: true
        - match: '(?=(([_$[:alpha:]][_$[:alnum:]]*\s*\??\.\s*)*|(\??\.\s*)?)([_$[:alpha:]][_$[:alnum:]]*))'
          push:
            - match: '(?=(<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))(([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>)*(?<!=)\>))*(?<!=)\>)*(?<!=)>\s*)?`)'
              pop: true
            - include: support-function-call-identifiers
            - match: "([_$[:alpha:]][_$[:alnum:]]*)"
              scope: entity.name.function.tagged-template.ts
        - include: type-arguments
    - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?=(<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))(([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>|\<\s*(((keyof|infer|awaited|typeof|readonly)\s+)|(([_$[:alpha:]][_$[:alnum:]]*|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\''([^\''\\]|\\.)*\'')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))(?=\s*([\<\>\,\.\[]|=>|&(?!&)|\|(?!\|)))))([^<>\(]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(?<==)\>)*(?<!=)\>))*(?<!=)\>)*(?<!=)>\s*)`)'
      captures:
        1: entity.name.function.tagged-template.ts
      push:
        - meta_scope: string.template.ts
        - match: (?=`)
          pop: true
        - include: type-arguments
    - match: "([_$[:alpha:]][_$[:alnum:]]*)?(`)"
      captures:
        1: entity.name.function.tagged-template.ts
        2: punctuation.definition.string.template.begin.ts
      push:
        - meta_scope: string.template.ts
        - match: "`"
          captures:
            0: punctuation.definition.string.template.end.ts
          pop: true
        - include: template-substitution-element
        - include: string-character-escape
  template-substitution-element:
    - match: '\$\{'
      captures:
        0: punctuation.definition.template-expression.begin.ts
      push:
        - meta_scope: meta.template.expression.ts
        - meta_content_scope: meta.embedded.line.ts
        - match: '\}'
          captures:
            0: punctuation.definition.template-expression.end.ts
          pop: true
        - include: expression
  ternary-expression:
    - match: '(?!\?\.\s*[^[:digit:]])(\?)(?!\?)'
      captures:
        1: keyword.operator.ternary.ts
      push:
        - match: \s*(:)
          captures:
            1: keyword.operator.ternary.ts
          pop: true
        - include: expression
  this-literal:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))this\b(?!\$)'
      scope: variable.language.this.ts
  type:
    - include: comment
    - include: string
    - include: numeric-literal
    - include: type-primitive
    - include: type-builtin-literals
    - include: type-parameters
    - include: type-tuple
    - include: type-object
    - include: type-conditional
    - include: type-operators
    - include: type-fn-type-parameters
    - include: type-paren-or-function-parameters
    - include: type-function-return-type
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(readonly)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*'
      captures:
        1: storage.modifier.ts
    - include: type-name
  type-alias-declaration:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(type)\b\s+([_$[:alpha:]][_$[:alnum:]]*)\s*'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: storage.type.type.ts
        4: entity.name.type.alias.ts
      push:
        - meta_scope: meta.type.declaration.ts
        - match: '(?=\}|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))'
          pop: true
        - include: comment
        - include: type-parameters
        - match: (=)\s*
          captures:
            1: keyword.operator.assignment.ts
          push:
            - match: '(?=\}|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))'
              pop: true
            - include: type
  type-annotation:
    - match: (:)(?=\s*\S)
      captures:
        1: keyword.operator.type.annotation.ts
      push:
        - meta_scope: meta.type.annotation.ts
        - match: '(?<![:|&])((?=$|^|[,);\}\]]|//)|(?==[^>])|((?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)))'
          pop: true
        - include: type
    - match: (:)
      captures:
        1: keyword.operator.type.annotation.ts
      push:
        - meta_scope: meta.type.annotation.ts
        - match: '(?<![:|&])((?=[,);\}\]]|//)|(?==[^>])|(?=^\s*$)|((?<=\S)(?=\s*$))|((?<=[\}>\]\)]|[_$[:alpha:]])\s*(?=\{)))'
          pop: true
        - include: type
  type-arguments:
    - match: \<
      captures:
        0: punctuation.definition.typeparameters.begin.ts
      push:
        - meta_scope: meta.type.parameters.ts
        - match: \>
          captures:
            0: punctuation.definition.typeparameters.end.ts
          pop: true
        - include: type-arguments-body
  type-arguments-body:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(_)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      captures:
        0: keyword.operator.type.ts
    - include: type
    - include: punctuation-comma
  type-builtin-literals:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(this|true|false|undefined|null|object)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: support.type.builtin.ts
  type-conditional:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(extends)\s+'
      captures:
        1: storage.modifier.ts
      push:
        - match: (?<=:)
          pop: true
        - match: \?
          captures:
            0: keyword.operator.ternary.ts
          push:
            - match: ":"
              captures:
                0: keyword.operator.ternary.ts
              pop: true
            - include: type
        - include: type
  type-fn-type-parameters:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(new)\b(?=\s*\<)'
      captures:
        1: meta.type.constructor.ts keyword.control.new.ts
      push:
        - match: (?<=>)
          pop: true
        - include: comment
        - include: type-parameters
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(new)\b\s*(?=\()'
      captures:
        1: keyword.control.new.ts
      push:
        - meta_scope: meta.type.constructor.ts
        - match: (?<=\))
          pop: true
        - include: function-parameters
    - match: |-
        (?x)(
          (?=
            [(]\s*(
              ([)]) |
              (\.\.\.) |
              ([_$[:alnum:]]+\s*(
                ([:,?=])|
                ([)]\s*=>)
              ))
            )
          )
        )
      push:
        - meta_scope: meta.type.function.ts
        - match: (?<=\))
          pop: true
        - include: function-parameters
  type-function-return-type:
    - match: (=>)(?=\s*\S)
      captures:
        1: storage.type.function.arrow.ts
      push:
        - meta_scope: meta.type.function.return.ts
        - match: '(?<!=>)(?<![|&])(?=[,\]\)\{\}=;>:\?]|//|$)'
          pop: true
        - include: type-function-return-type-core
    - match: "=>"
      captures:
        0: storage.type.function.arrow.ts
      push:
        - meta_scope: meta.type.function.return.ts
        - match: '(?<!=>)(?<![|&])((?=[,\]\)\{\}=;:\?>]|//|^\s*$)|((?<=\S)(?=\s*$)))'
          pop: true
        - include: type-function-return-type-core
  type-function-return-type-core:
    - include: comment
    - match: '(?<==>)(?=\s*\{)'
      push:
        - match: '(?<=\})'
          pop: true
        - include: type-object
    - include: type-predicate-operator
    - include: type
  type-name:
    - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))\s*(<)'
      captures:
        1: entity.name.type.module.ts
        2: punctuation.accessor.ts
        3: punctuation.accessor.optional.ts
        4: meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
      push:
        - meta_content_scope: meta.type.parameters.ts
        - match: (>)
          captures:
            1: meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
          pop: true
        - include: type-arguments-body
    - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(<)'
      captures:
        1: entity.name.type.ts
        2: meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
      push:
        - meta_content_scope: meta.type.parameters.ts
        - match: (>)
          captures:
            1: meta.type.parameters.ts punctuation.definition.typeparameters.end.ts
          pop: true
        - include: type-arguments-body
    - match: '([_$[:alpha:]][_$[:alnum:]]*)\s*(?:(\.)|(\?\.(?!\s*[[:digit:]])))'
      captures:
        1: entity.name.type.module.ts
        2: punctuation.accessor.ts
        3: punctuation.accessor.optional.ts
    - match: "[_$[:alpha:]][_$[:alnum:]]*"
      scope: entity.name.type.ts
  type-object:
    - match: '\{'
      captures:
        0: punctuation.definition.block.ts
      push:
        - meta_scope: meta.object.type.ts
        - match: '\}'
          captures:
            0: punctuation.definition.block.ts
          pop: true
        - include: comment
        - include: method-declaration
        - include: indexer-declaration
        - include: indexer-mapped-type-declaration
        - include: field-declaration
        - include: type-annotation
        - match: \.\.\.
          captures:
            0: keyword.operator.spread.ts
          push:
            - match: '(?=\}|;|,|$)|(?<=\})'
              pop: true
            - include: type
        - include: punctuation-comma
        - include: punctuation-semicolon
        - include: type
  type-operators:
    - include: typeof-operator
    - match: '([&|])(?=\s*\{)'
      captures:
        0: keyword.operator.type.ts
      push:
        - match: '(?<=\})'
          pop: true
        - include: type-object
    - match: "[&|]"
      captures:
        0: keyword.operator.type.ts
      push:
        - match: (?=\S)
          pop: true
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))keyof(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.operator.expression.keyof.ts
    - match: (\?|\:)
      scope: keyword.operator.ternary.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))infer(?=\s+[_$[:alpha:]])'
      scope: keyword.operator.expression.infer.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))awaited(?=\s+[_$[:alpha:]])'
      scope: keyword.operator.expression.awaited.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))import(?=\s*\()'
      scope: keyword.operator.expression.import.ts
  type-parameters:
    - match: (<)
      captures:
        1: punctuation.definition.typeparameters.begin.ts
      push:
        - meta_scope: meta.type.parameters.ts
        - match: (>)
          captures:
            1: punctuation.definition.typeparameters.end.ts
          pop: true
        - include: comment
        - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(extends)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
          scope: storage.modifier.ts
        - include: type
        - include: punctuation-comma
        - match: (=)(?!>)
          scope: keyword.operator.assignment.ts
  type-paren-or-function-parameters:
    - match: \(
      captures:
        0: meta.brace.round.ts
      push:
        - meta_scope: meta.type.paren.cover.ts
        - match: \)
          captures:
            0: meta.brace.round.ts
          pop: true
        - match: |-
            (?x)(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(public|private|protected|readonly)\s+)?(?:(\.\.\.)\s*)?(?<!=|:)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(this)|([_$[:alpha:]][_$[:alnum:]]*))\s*(\??)(?=\s*(:\s*(
              (<) |
              ([(]\s*(
                ([)]) |
                (\.\.\.) |
                ([_$[:alnum:]]+\s*(
                  ([:,?=])|
                  ([)]\s*=>)
                ))
              ))
            )) |
            (:\s*(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))Function(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))) |
            (:\s*((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*))))))))
          captures:
            1: storage.modifier.ts
            2: keyword.operator.rest.ts
            3: entity.name.function.ts variable.language.this.ts
            4: entity.name.function.ts
            5: keyword.operator.optional.ts
        - match: '(?x)(?:(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(public|private|protected|readonly)\s+)?(?:(\.\.\.)\s*)?(?<!=|:)(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(this)|([_$[:alpha:]][_$[:alnum:]]*))\s*(\??)(?=:)'
          captures:
            1: storage.modifier.ts
            2: keyword.operator.rest.ts
            3: variable.parameter.ts variable.language.this.ts
            4: variable.parameter.ts
            5: keyword.operator.optional.ts
        - include: type-annotation
        - match: ","
          scope: punctuation.separator.parameter.ts
        - include: type
  type-predicate-operator:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(asserts)\s+)?(?!asserts)(?:(this)|([_$[:alpha:]][_$[:alnum:]]*))\s(is)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      captures:
        1: keyword.operator.type.asserts.ts
        2: variable.parameter.ts variable.language.this.ts
        3: variable.parameter.ts
        4: keyword.operator.expression.is.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(asserts)\s+(?!is)(?:(this)|([_$[:alpha:]][_$[:alnum:]]*))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      captures:
        1: keyword.operator.type.asserts.ts
        2: variable.parameter.ts variable.language.this.ts
        3: variable.parameter.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))asserts(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.operator.type.asserts.ts
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))is(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.operator.expression.is.ts
  type-primitive:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(string|number|bigint|boolean|symbol|any|void|never|unknown)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: support.type.primitive.ts
  type-tuple:
    - match: '\['
      captures:
        0: meta.brace.square.ts
      push:
        - meta_scope: meta.type.tuple.ts
        - match: '\]'
          captures:
            0: meta.brace.square.ts
          pop: true
        - match: \.\.\.
          scope: keyword.operator.rest.ts
        - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))([_$[:alpha:]][_$[:alnum:]]*)\s*(\?)?\s*(:)'
          captures:
            1: entity.name.label.ts
            2: keyword.operator.optional.ts
            3: punctuation.separator.label.ts
        - include: type
        - include: punctuation-comma
  typeof-operator:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))typeof(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: keyword.operator.expression.typeof.ts
  undefined-literal:
    - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))undefined(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))'
      scope: constant.language.undefined.ts
  var-expr:
    - match: '(?=(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))'
      push:
        - meta_scope: meta.var.expr.ts
        - match: '(?!(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))((?=;|}|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+)|^\s*$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))|((?<!^let|[^\._$[:alnum:]]let|^var|[^\._$[:alnum:]]var)(?=\s*$)))'
          pop: true
        - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(var|let)(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*'
          captures:
            1: keyword.control.export.ts
            2: storage.modifier.ts
            3: storage.type.ts
          push:
            - match: (?=\S)
              pop: true
        - include: destructuring-variable
        - include: var-single-variable
        - include: variable-initializer
        - include: comment
        - match: (,)\s*((?!\S)|(?=\/\/))
          captures:
            1: punctuation.separator.comma.ts
          push:
            - match: '(?<!,)(((?==|;|}|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+)|^\s*$))|((?<=\S)(?=\s*$)))'
              pop: true
            - include: single-line-comment-consuming-line-ending
            - include: comment
            - include: destructuring-variable
            - include: var-single-variable
            - include: punctuation-comma
        - include: punctuation-comma
    - match: '(?=(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))'
      captures:
        1: keyword.control.export.ts
        2: storage.modifier.ts
        3: storage.type.ts
      push:
        - meta_scope: meta.var.expr.ts
        - match: '(?!(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.)))((?=;|}|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+)|^\s*$|;|(?:^\s*(?:abstract|async|class|const|declare|enum|export|function|import|interface|let|module|namespace|return|type|var)\b))|((?<!^const|[^\._$[:alnum:]]const)(?=\s*$)))'
          pop: true
        - match: '(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(\bexport)\s+)?(?:(\bdeclare)\s+)?\b(const(?!\s+enum\b))(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))\s*'
          captures:
            1: keyword.control.export.ts
            2: storage.modifier.ts
            3: storage.type.ts
          push:
            - match: (?=\S)
              pop: true
        - include: destructuring-const
        - include: var-single-const
        - include: variable-initializer
        - include: comment
        - match: (,)\s*((?!\S)|(?=\/\/))
          captures:
            1: punctuation.separator.comma.ts
          push:
            - match: '(?<!,)(((?==|;|}|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+)|^\s*$))|((?<=\S)(?=\s*$)))'
              pop: true
            - include: single-line-comment-consuming-line-ending
            - include: comment
            - include: destructuring-const
            - include: var-single-const
            - include: punctuation-comma
        - include: punctuation-comma
  var-single-const:
    - match: |-
        (?x)([_$[:alpha:]][_$[:alnum:]]*)(?=\s*
        # function assignment |
        (=\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        )) |
        # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
        (:\s*(
          (<) |
          ([(]\s*(
            ([)]) |
            (\.\.\.) |
            ([_$[:alnum:]]+\s*(
              ([:,?=])|
              ([)]\s*=>)
            ))
          ))
        )) |
        (:\s*(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))Function(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))) |
        (:\s*((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*))))))) |
        (:\s*(=>|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(<[^<>]*>)|[^<>(),=])+=\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        )))
      captures:
        1: meta.definition.variable.ts variable.other.constant.ts entity.name.function.ts
      push:
        - meta_scope: meta.var-single-variable.expr.ts
        - match: '(?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: var-single-variable-type-annotation
    - match: "([_$[:alpha:]][_$[:alnum:]]*)"
      captures:
        1: meta.definition.variable.ts variable.other.constant.ts
      push:
        - meta_scope: meta.var-single-variable.expr.ts
        - match: '(?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: var-single-variable-type-annotation
  var-single-variable:
    - match: |-
        (?x)([_$[:alpha:]][_$[:alnum:]]*)(\!)?(?=\s*
        # function assignment |
        (=\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        )) |
        # typeannotation is fn type: < | () | (... | (param: | (param, | (param? | (param= | (param) =>
        (:\s*(
          (<) |
          ([(]\s*(
            ([)]) |
            (\.\.\.) |
            ([_$[:alnum:]]+\s*(
              ([:,?=])|
              ([)]\s*=>)
            ))
          ))
        )) |
        (:\s*(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))Function(?![_$[:alnum:]])(?:(?=\.\.\.)|(?!\.))) |
        (:\s*((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*))))))) |
        (:\s*(=>|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(<[^<>]*>)|[^<>(),=])+=\s*(
          ((async\s+)?(
            (function\s*[(<*]) |
            (function\s+) |
            ([_$[:alpha:]][_$[:alnum:]]*\s*=>)
          )) |
          ((async\s*)?(
            ((<\s*$)|((<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?[\(]\s*((([\{\[]\s*)?$)|((\{([^\{\}]|(\{[^\{\}]*\}))*\})\s*((:\s*\{?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))|((\[([^\[\]]|(\[[^\[\]]*\]))*\])\s*((:\s*\[?$)|((\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+\s*)?=\s*)))))) |
            # sure shot arrow functions even if => is on new line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?
          [(]\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*
          (
            ([)]\s*:) |                                                                                       # ():
            ((\.\.\.\s*)?[_$[:alpha:]][_$[:alnum:]]*\s*:)                                                                  # [(]param: | [(]...param:
          )
        ) |

        # arrow function possible to detect only with => on same line
        (
          (<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<]|\<\s*([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\[([^\[\]]|(\[[^\[\]]*\]))*\]))([^=<>]|=[^<])*\>)*\>)*>\s*)?                                                                                 # typeparameters
          \(\s*(\/\*([^\*]|(\*[^\/]))*\*\/\s*)*(([_$[:alpha:]]|(\{([^\{\}]|(\{[^\{\}]*\}))*\})|(\[([^\[\]]|(\[[^\[\]]*\]))*\])|(\.\.\.\s*[_$[:alpha:]]))([^()\'\"\`]|(\(([^\(\)]|(\([^\(\)]*\)))*\))|(\'([^\'\\]|\\.)*\')|(\"([^\"\\]|\\.)*\")|(\`([^\`\\]|\\.)*\`))*)?\)   # parameters
          (\s*:\s*([^<>\(\)\{\}]|\<([^<>]|\<[^<>]+\>)+\>|\([^\(\)]+\)|\{[^\{\}]+\})+)?                                                                        # return type
          \s*=>                                                                                               # arrow operator
        )
          ))
        )))
      captures:
        1: meta.definition.variable.ts entity.name.function.ts
        2: keyword.operator.definiteassignment.ts
      push:
        - meta_scope: meta.var-single-variable.expr.ts
        - match: '(?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: var-single-variable-type-annotation
    - match: '([[:upper:]][_$[:digit:][:upper:]]*)(?![_$[:alnum:]])(\!)?'
      captures:
        1: meta.definition.variable.ts variable.other.constant.ts
        2: keyword.operator.definiteassignment.ts
      push:
        - meta_scope: meta.var-single-variable.expr.ts
        - match: '(?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: var-single-variable-type-annotation
    - match: '([_$[:alpha:]][_$[:alnum:]]*)(\!)?'
      captures:
        1: meta.definition.variable.ts variable.other.readwrite.ts
        2: keyword.operator.definiteassignment.ts
      push:
        - meta_scope: meta.var-single-variable.expr.ts
        - match: '(?=$|^|[;,=}]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: var-single-variable-type-annotation
  var-single-variable-type-annotation:
    - include: type-annotation
    - include: string
    - include: comment
  variable-initializer:
    - match: (?<!=|!)(=)(?!=)(?=\s*\S)(?!\s*.*=>\s*$)
      captures:
        1: keyword.operator.assignment.ts
      push:
        - match: '(?=$|^|[,);}\]]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))'
          pop: true
        - include: expression
    - match: (?<!=|!)(=)(?!=)
      captures:
        1: keyword.operator.assignment.ts
      push:
        - match: '(?=[,);}\]]|((?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(of|in)\s+))|(?=^\s*$)|(?<=\S)(?<!=)(?=\s*$)'
          pop: true
        - include: expression