@putout/babel 4.2.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bundle/index.js CHANGED
@@ -1003,568 +1003,13 @@ var require_jsesc = __commonJS({
1003
1003
  });
1004
1004
 
1005
1005
  // node_modules/ms/index.js
1006
- var require_ms = __commonJS({
1007
- 'node_modules/ms/index.js'(exports2, module2) {
1008
- var s = 1e3;
1009
- var m = s * 60;
1010
- var h = m * 60;
1011
- var d = h * 24;
1012
- var w = d * 7;
1013
- var y = d * 365.25;
1014
-
1015
- module2.exports = function(val, options) {
1016
- options = options || {};
1017
- var type = typeof val;
1018
-
1019
- if (type === 'string' && val.length > 0) {
1020
- return parse3(val);
1021
- } else if (type === 'number' && isFinite(val)) {
1022
- return options.long ? fmtLong(val) : fmtShort(val);
1023
- }
1024
-
1025
- throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val));
1026
- };
1027
- function parse3(str) {
1028
- str = String(str);
1029
-
1030
- if (str.length > 100) {
1031
- return;
1032
- }
1033
-
1034
- var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(str);
1035
-
1036
- if (!match) {
1037
- return;
1038
- }
1039
-
1040
- var n2 = parseFloat(match[1]);
1041
- var type = (match[2] || 'ms').toLowerCase();
1042
-
1043
- switch(type) {
1044
- case 'years':
1045
- case 'year':
1046
- case 'yrs':
1047
- case 'yr':
1048
- case 'y':
1049
- return n2 * y;
1050
-
1051
- case 'weeks':
1052
- case 'week':
1053
- case 'w':
1054
- return n2 * w;
1055
-
1056
- case 'days':
1057
- case 'day':
1058
- case 'd':
1059
- return n2 * d;
1060
-
1061
- case 'hours':
1062
- case 'hour':
1063
- case 'hrs':
1064
- case 'hr':
1065
- case 'h':
1066
- return n2 * h;
1067
-
1068
- case 'minutes':
1069
- case 'minute':
1070
- case 'mins':
1071
- case 'min':
1072
- case 'm':
1073
- return n2 * m;
1074
-
1075
- case 'seconds':
1076
- case 'second':
1077
- case 'secs':
1078
- case 'sec':
1079
- case 's':
1080
- return n2 * s;
1081
-
1082
- case 'milliseconds':
1083
- case 'millisecond':
1084
- case 'msecs':
1085
- case 'msec':
1086
- case 'ms':
1087
- return n2;
1088
-
1089
- default:
1090
- return void 0;
1091
- }
1092
- }
1093
-
1094
- function fmtShort(ms) {
1095
- var msAbs = Math.abs(ms);
1096
-
1097
- if (msAbs >= d) {
1098
- return Math.round(ms / d) + 'd';
1099
- }
1100
-
1101
- if (msAbs >= h) {
1102
- return Math.round(ms / h) + 'h';
1103
- }
1104
-
1105
- if (msAbs >= m) {
1106
- return Math.round(ms / m) + 'm';
1107
- }
1108
-
1109
- if (msAbs >= s) {
1110
- return Math.round(ms / s) + 's';
1111
- }
1112
-
1113
- return ms + 'ms';
1114
- }
1115
-
1116
- function fmtLong(ms) {
1117
- var msAbs = Math.abs(ms);
1118
-
1119
- if (msAbs >= d) {
1120
- return plural(ms, msAbs, d, 'day');
1121
- }
1122
-
1123
- if (msAbs >= h) {
1124
- return plural(ms, msAbs, h, 'hour');
1125
- }
1126
-
1127
- if (msAbs >= m) {
1128
- return plural(ms, msAbs, m, 'minute');
1129
- }
1130
-
1131
- if (msAbs >= s) {
1132
- return plural(ms, msAbs, s, 'second');
1133
- }
1134
-
1135
- return ms + ' ms';
1136
- }
1137
-
1138
- function plural(ms, msAbs, n2, name) {
1139
- var isPlural = msAbs >= n2 * 1.5;
1140
- return Math.round(ms / n2) + ' ' + name + (isPlural ? 's' : '');
1141
- }
1142
- },
1143
- });
1006
+ var require_ms = () => () => {};
1144
1007
 
1145
1008
  // node_modules/debug/src/common.js
1146
- var require_common = __commonJS({
1147
- 'node_modules/debug/src/common.js'(exports2, module2) {
1148
- function setup2(env) {
1149
- createDebug.debug = createDebug;
1150
- createDebug.default = createDebug;
1151
- createDebug.coerce = coerce;
1152
- createDebug.disable = disable;
1153
- createDebug.enable = enable;
1154
- createDebug.enabled = enabled;
1155
- createDebug.humanize = require_ms();
1156
- createDebug.destroy = destroy;
1157
- Object
1158
- .keys(env)
1159
- .forEach((key) => {
1160
- createDebug[key] = env[key];
1161
- });
1162
- createDebug.names = [];
1163
- createDebug.skips = [];
1164
- createDebug.formatters = {};
1165
- function selectColor(namespace) {
1166
- let hash = 0;
1167
-
1168
- for (let i = 0; i < namespace.length; i++) {
1169
- hash = (hash << 5) - hash + namespace.charCodeAt(i);
1170
- hash |= 0;
1171
- }
1172
-
1173
- return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
1174
- }
1175
-
1176
- createDebug.selectColor = selectColor;
1177
- function createDebug(namespace) {
1178
- let prevTime;
1179
- let enableOverride = null;
1180
- let namespacesCache;
1181
- let enabledCache;
1182
-
1183
- function debug2(...args) {
1184
- if (!debug2.enabled) {
1185
- return;
1186
- }
1187
-
1188
- const self = debug2;
1189
- const curr = Number( /* @__PURE__ */new Date());
1190
- const ms = curr - (prevTime || curr);
1191
-
1192
- self.diff = ms;
1193
- self.prev = prevTime;
1194
- self.curr = curr;
1195
- prevTime = curr;
1196
- args[0] = createDebug.coerce(args[0]);
1197
-
1198
- if (typeof args[0] !== 'string') {
1199
- args.unshift('%O');
1200
- }
1201
-
1202
- let index2 = 0;
1203
-
1204
- args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
1205
- if (match === '%%') {
1206
- return '%';
1207
- }
1208
-
1209
- index2++;
1210
- const formatter = createDebug.formatters[format];
1211
-
1212
- if (typeof formatter === 'function') {
1213
- const val = args[index2];
1214
-
1215
- match = formatter.call(self, val);
1216
- args.splice(index2, 1);
1217
- index2--;
1218
- }
1219
-
1220
- return match;
1221
- });
1222
- createDebug.formatArgs.call(self, args);
1223
- const logFn = self.log || createDebug.log;
1224
- logFn.apply(self, args);
1225
- }
1226
-
1227
- debug2.namespace = namespace;
1228
- debug2.useColors = createDebug.useColors();
1229
- debug2.color = createDebug.selectColor(namespace);
1230
- debug2.extend = extend;
1231
- debug2.destroy = createDebug.destroy;
1232
- Object.defineProperty(debug2, 'enabled', {
1233
- enumerable: true,
1234
- configurable: false,
1235
- get: () => {
1236
- if (enableOverride !== null) {
1237
- return enableOverride;
1238
- }
1239
-
1240
- if (namespacesCache !== createDebug.namespaces) {
1241
- namespacesCache = createDebug.namespaces;
1242
- enabledCache = createDebug.enabled(namespace);
1243
- }
1244
-
1245
- return enabledCache;
1246
- },
1247
- set: (v) => {
1248
- enableOverride = v;
1249
- },
1250
- });
1251
-
1252
- if (typeof createDebug.init === 'function') {
1253
- createDebug.init(debug2);
1254
- }
1255
-
1256
- return debug2;
1257
- }
1258
-
1259
- function extend(namespace, delimiter) {
1260
- const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
1261
-
1262
- newDebug.log = this.log;
1263
- return newDebug;
1264
- }
1265
-
1266
- function enable(namespaces) {
1267
- createDebug.save(namespaces);
1268
- createDebug.namespaces = namespaces;
1269
- createDebug.names = [];
1270
- createDebug.skips = [];
1271
- const split = (typeof namespaces === 'string' ? namespaces : '')
1272
- .trim()
1273
- .replace(/\s+/g, ',')
1274
- .split(',')
1275
- .filter(Boolean);
1276
-
1277
- for (const ns of split) {
1278
- if (ns[0] === '-') {
1279
- createDebug.skips.push(ns.slice(1));
1280
- } else {
1281
- createDebug.names.push(ns);
1282
- }
1283
- }
1284
- }
1285
-
1286
- function matchesTemplate(search, template) {
1287
- let searchIndex = 0;
1288
- let templateIndex = 0;
1289
- let starIndex = -1;
1290
- let matchIndex = 0;
1291
-
1292
- while (searchIndex < search.length) {
1293
- if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
1294
- if (template[templateIndex] === '*') {
1295
- starIndex = templateIndex;
1296
- matchIndex = searchIndex;
1297
- templateIndex++;
1298
- } else {
1299
- searchIndex++;
1300
- templateIndex++;
1301
- }
1302
- } else if (starIndex !== -1) {
1303
- templateIndex = starIndex + 1;
1304
- matchIndex++;
1305
- searchIndex = matchIndex;
1306
- } else {
1307
- return false;
1308
- }
1309
- }
1310
-
1311
- while (templateIndex < template.length && template[templateIndex] === '*') {
1312
- templateIndex++;
1313
- }
1314
-
1315
- return templateIndex === template.length;
1316
- }
1317
-
1318
- function disable() {
1319
- const namespaces = [
1320
- ...createDebug.names,
1321
- ...createDebug.skips.map((namespace) => '-' + namespace),
1322
- ].join(',');
1323
-
1324
- createDebug.enable('');
1325
- return namespaces;
1326
- }
1327
-
1328
- function enabled(name) {
1329
- for (const skip2 of createDebug.skips) {
1330
- if (matchesTemplate(name, skip2)) {
1331
- return false;
1332
- }
1333
- }
1334
-
1335
- for (const ns of createDebug.names) {
1336
- if (matchesTemplate(name, ns)) {
1337
- return true;
1338
- }
1339
- }
1340
-
1341
- return false;
1342
- }
1343
-
1344
- function coerce(val) {
1345
- if (val instanceof Error) {
1346
- return val.stack || val.message;
1347
- }
1348
-
1349
- return val;
1350
- }
1351
-
1352
- function destroy() {
1353
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
1354
- }
1355
-
1356
- createDebug.enable(createDebug.load());
1357
-
1358
- return createDebug;
1359
- }
1360
-
1361
- module2.exports = setup2;
1362
- },
1363
- });
1009
+ var require_common = () => () => {};
1364
1010
 
1365
1011
  // node_modules/debug/src/browser.js
1366
- var require_browser = __commonJS({
1367
- 'node_modules/debug/src/browser.js'(exports2, module2) {
1368
- exports2.formatArgs = formatArgs;
1369
- exports2.save = save;
1370
- exports2.load = load;
1371
- exports2.useColors = useColors;
1372
- exports2.storage = localstorage();
1373
- exports2.destroy = /* @__PURE__ */(() => {
1374
- let warned = false;
1375
-
1376
- return () => {
1377
- if (!warned) {
1378
- warned = true;
1379
- console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
1380
- }
1381
- };
1382
- })();
1383
- exports2.colors = [
1384
- '#0000CC',
1385
- '#0000FF',
1386
- '#0033CC',
1387
- '#0033FF',
1388
- '#0066CC',
1389
- '#0066FF',
1390
- '#0099CC',
1391
- '#0099FF',
1392
- '#00CC00',
1393
- '#00CC33',
1394
- '#00CC66',
1395
- '#00CC99',
1396
- '#00CCCC',
1397
- '#00CCFF',
1398
- '#3300CC',
1399
- '#3300FF',
1400
- '#3333CC',
1401
- '#3333FF',
1402
- '#3366CC',
1403
- '#3366FF',
1404
- '#3399CC',
1405
- '#3399FF',
1406
- '#33CC00',
1407
- '#33CC33',
1408
- '#33CC66',
1409
- '#33CC99',
1410
- '#33CCCC',
1411
- '#33CCFF',
1412
- '#6600CC',
1413
- '#6600FF',
1414
- '#6633CC',
1415
- '#6633FF',
1416
- '#66CC00',
1417
- '#66CC33',
1418
- '#9900CC',
1419
- '#9900FF',
1420
- '#9933CC',
1421
- '#9933FF',
1422
- '#99CC00',
1423
- '#99CC33',
1424
- '#CC0000',
1425
- '#CC0033',
1426
- '#CC0066',
1427
- '#CC0099',
1428
- '#CC00CC',
1429
- '#CC00FF',
1430
- '#CC3300',
1431
- '#CC3333',
1432
- '#CC3366',
1433
- '#CC3399',
1434
- '#CC33CC',
1435
- '#CC33FF',
1436
- '#CC6600',
1437
- '#CC6633',
1438
- '#CC9900',
1439
- '#CC9933',
1440
- '#CCCC00',
1441
- '#CCCC33',
1442
- '#FF0000',
1443
- '#FF0033',
1444
- '#FF0066',
1445
- '#FF0099',
1446
- '#FF00CC',
1447
- '#FF00FF',
1448
- '#FF3300',
1449
- '#FF3333',
1450
- '#FF3366',
1451
- '#FF3399',
1452
- '#FF33CC',
1453
- '#FF33FF',
1454
- '#FF6600',
1455
- '#FF6633',
1456
- '#FF9900',
1457
- '#FF9933',
1458
- '#FFCC00',
1459
- '#FFCC33',
1460
- ];
1461
- function useColors() {
1462
- if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
1463
- return true;
1464
- }
1465
-
1466
- if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
1467
- return false;
1468
- }
1469
-
1470
- let m;
1471
-
1472
- return typeof document !== 'undefined'
1473
- && document.documentElement
1474
- && document.documentElement.style
1475
- && document.documentElement.style.WebkitAppearance
1476
- || // Is firebug? http://stackoverflow.com/a/398120/376773
1477
- typeof window !== 'undefined'
1478
- && window.console
1479
- && (window.console.firebug
1480
- || window.console.exception
1481
- && window.console.table)
1482
- || // Is firefox >= v31?
1483
- // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
1484
- typeof navigator !== 'undefined'
1485
- && navigator.userAgent
1486
- && (m = navigator.userAgent
1487
- .toLowerCase()
1488
- .match(/firefox\/(\d+)/))
1489
- && parseInt(m[1], 10) >= 31
1490
- || // Double check webkit in userAgent just in case we are in a worker
1491
- typeof navigator !== 'undefined'
1492
- && navigator.userAgent
1493
- && navigator.userAgent
1494
- .toLowerCase()
1495
- .match(/applewebkit\/(\d+)/);
1496
- }
1497
-
1498
- function formatArgs(args) {
1499
- args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module2.exports.humanize(this.diff);
1500
-
1501
- if (!this.useColors) {
1502
- return;
1503
- }
1504
-
1505
- const c = 'color: ' + this.color;
1506
- args.splice(1, 0, c, 'color: inherit');
1507
- let index2 = 0;
1508
- let lastC = 0;
1509
-
1510
- args[0].replace(/%[a-zA-Z%]/g, (match) => {
1511
- if (match === '%%') {
1512
- return;
1513
- }
1514
-
1515
- index2++;
1516
-
1517
- if (match === '%c') {
1518
- lastC = index2;
1519
- }
1520
- });
1521
- args.splice(lastC, 0, c);
1522
- }
1523
-
1524
- exports2.log = console.debug || console.log || (() => {});
1525
- function save(namespaces) {
1526
- try {
1527
- if (namespaces) {
1528
- exports2.storage.setItem('debug', namespaces);
1529
- } else {
1530
- exports2.storage.removeItem('debug');
1531
- }
1532
- } catch(error) {}
1533
- }
1534
-
1535
- function load() {
1536
- let r;
1537
-
1538
- try {
1539
- r = exports2.storage.getItem('debug') || exports2.storage.getItem('DEBUG');
1540
- } catch(error) {}
1541
-
1542
-
1543
- if (!r && typeof process !== 'undefined' && 'env' in process) {
1544
- r = process.env.DEBUG;
1545
- }
1546
-
1547
- return r;
1548
- }
1549
-
1550
- function localstorage() {
1551
- try {
1552
- return localStorage;
1553
- } catch(error) {}
1554
- }
1555
-
1556
- module2.exports = require_common()(exports2);
1557
- var {formatters} = module2.exports;
1558
-
1559
- formatters.j = function(v) {
1560
- try {
1561
- return JSON.stringify(v);
1562
- } catch(error) {
1563
- return '[UnexpectedJSONParseError]: ' + error.message;
1564
- }
1565
- };
1566
- },
1567
- });
1012
+ var require_browser = () => () => {};
1568
1013
 
1569
1014
  // node_modules/has-flag/index.js
1570
1015
  var require_has_flag = __commonJS({
@@ -1713,212 +1158,7 @@ var require_supports_color = __commonJS({
1713
1158
  });
1714
1159
 
1715
1160
  // node_modules/debug/src/node.js
1716
- var require_node = __commonJS({
1717
- 'node_modules/debug/src/node.js'(exports2, module2) {
1718
- var tty = require('tty');
1719
- var util = require('util');
1720
-
1721
- exports2.init = init;
1722
- exports2.log = log;
1723
- exports2.formatArgs = formatArgs;
1724
- exports2.save = save;
1725
- exports2.load = load;
1726
- exports2.useColors = useColors;
1727
- exports2.destroy = util.deprecate(() => {}, 'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
1728
- exports2.colors = [
1729
- 6,
1730
- 2,
1731
- 3,
1732
- 4,
1733
- 5,
1734
- 1,
1735
- ];
1736
- try {
1737
- const supportsColor = require_supports_color();
1738
-
1739
- if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
1740
- exports2.colors = [
1741
- 20,
1742
- 21,
1743
- 26,
1744
- 27,
1745
- 32,
1746
- 33,
1747
- 38,
1748
- 39,
1749
- 40,
1750
- 41,
1751
- 42,
1752
- 43,
1753
- 44,
1754
- 45,
1755
- 56,
1756
- 57,
1757
- 62,
1758
- 63,
1759
- 68,
1760
- 69,
1761
- 74,
1762
- 75,
1763
- 76,
1764
- 77,
1765
- 78,
1766
- 79,
1767
- 80,
1768
- 81,
1769
- 92,
1770
- 93,
1771
- 98,
1772
- 99,
1773
- 112,
1774
- 113,
1775
- 128,
1776
- 129,
1777
- 134,
1778
- 135,
1779
- 148,
1780
- 149,
1781
- 160,
1782
- 161,
1783
- 162,
1784
- 163,
1785
- 164,
1786
- 165,
1787
- 166,
1788
- 167,
1789
- 168,
1790
- 169,
1791
- 170,
1792
- 171,
1793
- 172,
1794
- 173,
1795
- 178,
1796
- 179,
1797
- 184,
1798
- 185,
1799
- 196,
1800
- 197,
1801
- 198,
1802
- 199,
1803
- 200,
1804
- 201,
1805
- 202,
1806
- 203,
1807
- 204,
1808
- 205,
1809
- 206,
1810
- 207,
1811
- 208,
1812
- 209,
1813
- 214,
1814
- 215,
1815
- 220,
1816
- 221,
1817
- ];
1818
- }
1819
- } catch(error) {}
1820
-
1821
-
1822
- exports2.inspectOpts = Object
1823
- .keys(process.env)
1824
- .filter((key) => {
1825
- return /^debug_/i.test(key);
1826
- })
1827
- .reduce((obj, key) => {
1828
- const prop = key
1829
- .substring(6)
1830
- .toLowerCase()
1831
- .replace(/_([a-z])/g, (_, k) => {
1832
- return k.toUpperCase();
1833
- });
1834
-
1835
- let val = process.env[key];
1836
-
1837
- if (/^(yes|on|true|enabled)$/i.test(val)) {
1838
- val = true;
1839
- } else if (/^(no|off|false|disabled)$/i.test(val)) {
1840
- val = false;
1841
- } else if (val === 'null') {
1842
- val = null;
1843
- } else {
1844
- val = Number(val);
1845
- }
1846
-
1847
- obj[prop] = val;
1848
- return obj;
1849
- }, {});
1850
- function useColors() {
1851
- return 'colors' in exports2.inspectOpts ? Boolean(exports2.inspectOpts.colors) : tty.isatty(process.stderr.fd);
1852
- }
1853
-
1854
- function formatArgs(args) {
1855
- const {namespace: name, useColors: useColors2} = this;
1856
-
1857
- if (useColors2) {
1858
- const c = this.color;
1859
- const colorCode = '\x1B[3' + (c < 8 ? c : '8;5;' + c);
1860
- const prefix2 = ` ${colorCode};1m${name} \x1B[0m`;
1861
-
1862
- args[0] = prefix2 + args[0]
1863
- .split('\n')
1864
- .join('\n' + prefix2);
1865
- args.push(colorCode + 'm+' + module2.exports.humanize(this.diff) + '\x1B[0m');
1866
- } else {
1867
- args[0] = getDate() + name + ' ' + args[0];
1868
- }
1869
- }
1870
-
1871
- function getDate() {
1872
- if (exports2.inspectOpts.hideDate) {
1873
- return '';
1874
- }
1875
-
1876
- return /* @__PURE__ */new Date().toISOString() + ' ';
1877
- }
1878
-
1879
- function log(...args) {
1880
- return process.stderr.write(util.formatWithOptions(exports2.inspectOpts, ...args) + '\n');
1881
- }
1882
-
1883
- function save(namespaces) {
1884
- if (namespaces) {
1885
- process.env.DEBUG = namespaces;
1886
- } else {
1887
- delete process.env.DEBUG;
1888
- }
1889
- }
1890
-
1891
- function load() {
1892
- return process.env.DEBUG;
1893
- }
1894
-
1895
- function init(debug2) {
1896
- debug2.inspectOpts = {};
1897
- const keys2 = Object.keys(exports2.inspectOpts);
1898
-
1899
- for (let i = 0; i < keys2.length; i++) {
1900
- debug2.inspectOpts[keys2[i]] = exports2.inspectOpts[keys2[i]];
1901
- }
1902
- }
1903
-
1904
- module2.exports = require_common()(exports2);
1905
- var {formatters} = module2.exports;
1906
-
1907
- formatters.o = function(v) {
1908
- this.inspectOpts.colors = this.useColors;
1909
- return util
1910
- .inspect(v, this
1911
- .inspectOpts)
1912
- .split('\n')
1913
- .map((str) => str.trim())
1914
- .join(' ');
1915
- };
1916
- formatters.O = function(v) {
1917
- this.inspectOpts.colors = this.useColors;
1918
- return util.inspect(v, this.inspectOpts);
1919
- };
1920
- },
1921
- });
1161
+ var require_node = () => () => {};
1922
1162
 
1923
1163
  // node_modules/debug/src/index.js
1924
1164
  var require_src = __commonJS({
@@ -8259,117 +7499,25 @@ function isPrivate(node, opts) {
8259
7499
  return opts == null || shallowEqual(node, opts);
8260
7500
  }
8261
7501
 
8262
- function isFlow(node, opts) {
7502
+ function isFlow() {}
7503
+
7504
+ function isFlowType() {}
7505
+
7506
+ function isFlowBaseAnnotation() {}
7507
+
7508
+ function isFlowDeclaration() {}
7509
+
7510
+ function isFlowPredicate() {}
7511
+
7512
+ function isEnumBody(node, opts) {
8263
7513
  if (!node)
8264
7514
  return false;
8265
7515
 
8266
7516
  switch(node.type) {
8267
- case 'AnyTypeAnnotation':
8268
- case 'ArrayTypeAnnotation':
8269
- case 'BooleanTypeAnnotation':
8270
- case 'BooleanLiteralTypeAnnotation':
8271
- case 'NullLiteralTypeAnnotation':
8272
- case 'ClassImplements':
8273
- case 'DeclareClass':
8274
- case 'DeclareFunction':
8275
- case 'DeclareInterface':
8276
- case 'DeclareModule':
8277
- case 'DeclareModuleExports':
8278
- case 'DeclareTypeAlias':
8279
- case 'DeclareOpaqueType':
8280
- case 'DeclareVariable':
8281
- case 'DeclareExportDeclaration':
8282
- case 'DeclareExportAllDeclaration':
8283
- case 'DeclaredPredicate':
8284
- case 'ExistsTypeAnnotation':
8285
- case 'FunctionTypeAnnotation':
8286
- case 'FunctionTypeParam':
8287
- case 'GenericTypeAnnotation':
8288
- case 'InferredPredicate':
8289
- case 'InterfaceExtends':
8290
- case 'InterfaceDeclaration':
8291
- case 'InterfaceTypeAnnotation':
8292
- case 'IntersectionTypeAnnotation':
8293
- case 'MixedTypeAnnotation':
8294
- case 'EmptyTypeAnnotation':
8295
- case 'NullableTypeAnnotation':
8296
- case 'NumberLiteralTypeAnnotation':
8297
- case 'NumberTypeAnnotation':
8298
- case 'ObjectTypeAnnotation':
8299
- case 'ObjectTypeInternalSlot':
8300
- case 'ObjectTypeCallProperty':
8301
- case 'ObjectTypeIndexer':
8302
- case 'ObjectTypeProperty':
8303
- case 'ObjectTypeSpreadProperty':
8304
- case 'OpaqueType':
8305
- case 'QualifiedTypeIdentifier':
8306
- case 'StringLiteralTypeAnnotation':
8307
- case 'StringTypeAnnotation':
8308
- case 'SymbolTypeAnnotation':
8309
- case 'ThisTypeAnnotation':
8310
- case 'TupleTypeAnnotation':
8311
- case 'TypeofTypeAnnotation':
8312
- case 'TypeAlias':
8313
- case 'TypeAnnotation':
8314
- case 'TypeCastExpression':
8315
- case 'TypeParameter':
8316
- case 'TypeParameterDeclaration':
8317
- case 'TypeParameterInstantiation':
8318
- case 'UnionTypeAnnotation':
8319
- case 'Variance':
8320
- case 'VoidTypeAnnotation':
8321
- case 'EnumDeclaration':
8322
7517
  case 'EnumBooleanBody':
8323
7518
  case 'EnumNumberBody':
8324
7519
  case 'EnumStringBody':
8325
- case 'EnumSymbolBody':
8326
- case 'EnumBooleanMember':
8327
- case 'EnumNumberMember':
8328
- case 'EnumStringMember':
8329
- case 'EnumDefaultedMember':
8330
- case 'IndexedAccessType':
8331
- case 'OptionalIndexedAccessType':
8332
- break;
8333
-
8334
- default:
8335
- return false;
8336
- }
8337
-
8338
-
8339
- return opts == null || shallowEqual(node, opts);
8340
- }
8341
-
8342
- function isFlowType(node, opts) {
8343
- if (!node)
8344
- return false;
8345
-
8346
- switch(node.type) {
8347
- case 'AnyTypeAnnotation':
8348
- case 'ArrayTypeAnnotation':
8349
- case 'BooleanTypeAnnotation':
8350
- case 'BooleanLiteralTypeAnnotation':
8351
- case 'NullLiteralTypeAnnotation':
8352
- case 'ExistsTypeAnnotation':
8353
- case 'FunctionTypeAnnotation':
8354
- case 'GenericTypeAnnotation':
8355
- case 'InterfaceTypeAnnotation':
8356
- case 'IntersectionTypeAnnotation':
8357
- case 'MixedTypeAnnotation':
8358
- case 'EmptyTypeAnnotation':
8359
- case 'NullableTypeAnnotation':
8360
- case 'NumberLiteralTypeAnnotation':
8361
- case 'NumberTypeAnnotation':
8362
- case 'ObjectTypeAnnotation':
8363
- case 'StringLiteralTypeAnnotation':
8364
- case 'StringTypeAnnotation':
8365
- case 'SymbolTypeAnnotation':
8366
- case 'ThisTypeAnnotation':
8367
- case 'TupleTypeAnnotation':
8368
- case 'TypeofTypeAnnotation':
8369
- case 'UnionTypeAnnotation':
8370
- case 'VoidTypeAnnotation':
8371
- case 'IndexedAccessType':
8372
- case 'OptionalIndexedAccessType':
7520
+ case 'EnumSymbolBody':
8373
7521
  break;
8374
7522
 
8375
7523
  default:
@@ -8380,21 +7528,15 @@ function isFlowType(node, opts) {
8380
7528
  return opts == null || shallowEqual(node, opts);
8381
7529
  }
8382
7530
 
8383
- function isFlowBaseAnnotation(node, opts) {
7531
+ function isEnumMember(node, opts) {
8384
7532
  if (!node)
8385
7533
  return false;
8386
7534
 
8387
7535
  switch(node.type) {
8388
- case 'AnyTypeAnnotation':
8389
- case 'BooleanTypeAnnotation':
8390
- case 'NullLiteralTypeAnnotation':
8391
- case 'MixedTypeAnnotation':
8392
- case 'EmptyTypeAnnotation':
8393
- case 'NumberTypeAnnotation':
8394
- case 'StringTypeAnnotation':
8395
- case 'SymbolTypeAnnotation':
8396
- case 'ThisTypeAnnotation':
8397
- case 'VoidTypeAnnotation':
7536
+ case 'EnumBooleanMember':
7537
+ case 'EnumNumberMember':
7538
+ case 'EnumStringMember':
7539
+ case 'EnumDefaultedMember':
8398
7540
  break;
8399
7541
 
8400
7542
  default:
@@ -8405,90 +7547,7 @@ function isFlowBaseAnnotation(node, opts) {
8405
7547
  return opts == null || shallowEqual(node, opts);
8406
7548
  }
8407
7549
 
8408
- function isFlowDeclaration(node, opts) {
8409
- if (!node)
8410
- return false;
8411
-
8412
- switch(node.type) {
8413
- case 'DeclareClass':
8414
- case 'DeclareFunction':
8415
- case 'DeclareInterface':
8416
- case 'DeclareModule':
8417
- case 'DeclareModuleExports':
8418
- case 'DeclareTypeAlias':
8419
- case 'DeclareOpaqueType':
8420
- case 'DeclareVariable':
8421
- case 'DeclareExportDeclaration':
8422
- case 'DeclareExportAllDeclaration':
8423
- case 'InterfaceDeclaration':
8424
- case 'OpaqueType':
8425
- case 'TypeAlias':
8426
- break;
8427
-
8428
- default:
8429
- return false;
8430
- }
8431
-
8432
-
8433
- return opts == null || shallowEqual(node, opts);
8434
- }
8435
-
8436
- function isFlowPredicate(node, opts) {
8437
- if (!node)
8438
- return false;
8439
-
8440
- switch(node.type) {
8441
- case 'DeclaredPredicate':
8442
- case 'InferredPredicate':
8443
- break;
8444
-
8445
- default:
8446
- return false;
8447
- }
8448
-
8449
-
8450
- return opts == null || shallowEqual(node, opts);
8451
- }
8452
-
8453
- function isEnumBody(node, opts) {
8454
- if (!node)
8455
- return false;
8456
-
8457
- switch(node.type) {
8458
- case 'EnumBooleanBody':
8459
- case 'EnumNumberBody':
8460
- case 'EnumStringBody':
8461
- case 'EnumSymbolBody':
8462
- break;
8463
-
8464
- default:
8465
- return false;
8466
- }
8467
-
8468
-
8469
- return opts == null || shallowEqual(node, opts);
8470
- }
8471
-
8472
- function isEnumMember(node, opts) {
8473
- if (!node)
8474
- return false;
8475
-
8476
- switch(node.type) {
8477
- case 'EnumBooleanMember':
8478
- case 'EnumNumberMember':
8479
- case 'EnumStringMember':
8480
- case 'EnumDefaultedMember':
8481
- break;
8482
-
8483
- default:
8484
- return false;
8485
- }
8486
-
8487
-
8488
- return opts == null || shallowEqual(node, opts);
8489
- }
8490
-
8491
- function isJSX(node, opts) {
7550
+ function isJSX(node, opts) {
8492
7551
  if (!node)
8493
7552
  return false;
8494
7553
 
@@ -22431,59 +21490,6 @@ var reservedTypes = /* @__PURE__ */new Set([
22431
21490
  'void',
22432
21491
  ]);
22433
21492
 
22434
- var FlowErrors = ParseErrorEnum`flow`({
22435
- AmbiguousConditionalArrow: 'Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.',
22436
- AmbiguousDeclareModuleKind: 'Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module.',
22437
- AssignReservedType: ({reservedType}) => `Cannot overwrite reserved type ${reservedType}.`,
22438
- DeclareClassElement: 'The `declare` modifier can only appear on class fields.',
22439
- DeclareClassFieldInitializer: 'Initializers are not allowed in fields with the `declare` modifier.',
22440
- DuplicateDeclareModuleExports: 'Duplicate `declare module.exports` statement.',
22441
- EnumBooleanMemberNotInitialized: ({memberName, enumName}) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
22442
- EnumDuplicateMemberName: ({memberName, enumName}) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
22443
- EnumInconsistentMemberValues: ({enumName}) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
22444
- EnumInvalidExplicitType: ({invalidEnumType, enumName}) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
22445
- EnumInvalidExplicitTypeUnknownSupplied: ({enumName}) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
22446
- EnumInvalidMemberInitializerPrimaryType: ({enumName, memberName, explicitType}) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
22447
- EnumInvalidMemberInitializerSymbolType: ({enumName, memberName}) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
22448
- EnumInvalidMemberInitializerUnknownType: ({enumName, memberName}) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
22449
- EnumInvalidMemberName: ({enumName, memberName, suggestion}) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
22450
- EnumNumberMemberNotInitialized: ({enumName, memberName}) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
22451
- EnumStringMemberInconsistentlyInitialized: ({enumName}) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
22452
- GetterMayNotHaveThisParam: 'A getter cannot have a `this` parameter.',
22453
- ImportReflectionHasImportType: 'An `import module` declaration can not use `type` or `typeof` keyword.',
22454
- ImportTypeShorthandOnlyInPureImport: 'The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements.',
22455
- InexactInsideExact: 'Explicit inexact syntax cannot appear inside an explicit exact object type.',
22456
- InexactInsideNonObject: 'Explicit inexact syntax cannot appear in class or interface definitions.',
22457
- InexactVariance: 'Explicit inexact syntax cannot have variance.',
22458
- InvalidNonTypeImportInDeclareModule: 'Imports within a `declare module` body must always be `import type` or `import typeof`.',
22459
- MissingTypeParamDefault: 'Type parameter declaration needs a default, since a preceding type parameter declaration has a default.',
22460
- NestedDeclareModule: '`declare module` cannot be used inside another `declare module`.',
22461
- NestedFlowComment: 'Cannot have a flow comment inside another flow comment.',
22462
- PatternIsOptional: Object.assign({
22463
- message: 'A binding pattern parameter cannot be optional in an implementation signature.',
22464
- }, {}),
22465
- SetterMayNotHaveThisParam: 'A setter cannot have a `this` parameter.',
22466
- SpreadVariance: 'Spread properties cannot have variance.',
22467
- ThisParamAnnotationRequired: 'A type annotation is required for the `this` parameter.',
22468
- ThisParamBannedInConstructor: 'Constructors cannot have a `this` parameter; constructors don\'t bind `this` like other functions.',
22469
- ThisParamMayNotBeOptional: 'The `this` parameter cannot be optional.',
22470
- ThisParamMustBeFirst: 'The `this` parameter must be the first function parameter.',
22471
- ThisParamNoDefault: 'The `this` parameter may not have a default value.',
22472
- TypeBeforeInitializer: 'Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.',
22473
- TypeCastInPattern: 'The type cast expression is expected to be wrapped with parenthesis.',
22474
- UnexpectedExplicitInexactInObject: 'Explicit inexact syntax must appear at the end of an inexact object.',
22475
- UnexpectedReservedType: ({reservedType}) => `Unexpected reserved type ${reservedType}.`,
22476
- UnexpectedReservedUnderscore: '`_` is only allowed as a type argument to call or new.',
22477
- UnexpectedSpaceBetweenModuloChecks: 'Spaces between `%` and `checks` are not allowed here.',
22478
- UnexpectedSpreadType: 'Spread operator cannot appear in class or interface definitions.',
22479
- UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
22480
- UnexpectedTokenAfterTypeParameter: 'Expected an arrow function after this type parameter declaration.',
22481
- UnexpectedTypeParameterBeforeAsyncArrowFunction: 'Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.',
22482
- UnsupportedDeclareExportKind: ({unsupportedExportKind, suggestion}) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
22483
- UnsupportedStatementInDeclareModule: 'Only declares and type imports are allowed inside declare module.',
22484
- UnterminatedFlowComment: 'Unterminated flow-comment.',
22485
- });
22486
-
22487
21493
  function isEsModuleType(bodyElement) {
22488
21494
  return bodyElement.type === 'DeclareExportAllDeclaration'
22489
21495
  || bodyElement.type === 'DeclareExportDeclaration'
@@ -22516,2893 +21522,6 @@ function partition(list, test) {
22516
21522
 
22517
21523
  var FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
22518
21524
 
22519
- var flow = (superClass) => class FlowParserMixin extends superClass {
22520
- constructor() {
22521
- super(...arguments);
22522
- __publicField(this, 'flowPragma');
22523
- }
22524
-
22525
- getScopeHandler() {
22526
- return FlowScopeHandler;
22527
- }
22528
-
22529
- shouldParseTypes() {
22530
- return this.getPluginOption('flow', 'all') || this.flowPragma === 'flow';
22531
- }
22532
-
22533
- finishToken(type, val) {
22534
- if (type !== 134 && type !== 13 && type !== 28) {
22535
- if (this.flowPragma === void 0) {
22536
- this.flowPragma = null;
22537
- }
22538
- }
22539
-
22540
- super.finishToken(type, val);
22541
- }
22542
-
22543
- addComment(comment) {
22544
- if (this.flowPragma === void 0) {
22545
- const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
22546
-
22547
- if (!matches);
22548
- else if (matches[1] === 'flow') {
22549
- this.flowPragma = 'flow';
22550
- } else if (matches[1] === 'noflow') {
22551
- this.flowPragma = 'noflow';
22552
- } else {
22553
- throw new Error('Unexpected flow pragma');
22554
- }
22555
-
22556
- }
22557
-
22558
- super.addComment(comment);
22559
- }
22560
-
22561
- flowParseTypeInitialiser(tok) {
22562
- const oldInType = this.state.inType;
22563
-
22564
- this.state.inType = true;
22565
- this.expect(tok || 14);
22566
- const type = this.flowParseType();
22567
-
22568
- this.state.inType = oldInType;
22569
- return type;
22570
- }
22571
-
22572
- flowParsePredicate() {
22573
- const node = this.startNode();
22574
- const moduloLoc = this.state.startLoc;
22575
- this.next();
22576
- this.expectContextual(110);
22577
-
22578
- if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
22579
- this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
22580
- }
22581
-
22582
- if (this.eat(10)) {
22583
- node.value = super.parseExpression();
22584
- this.expect(11);
22585
- return this.finishNode(node, 'DeclaredPredicate');
22586
- } else {
22587
- return this.finishNode(node, 'InferredPredicate');
22588
- }
22589
- }
22590
-
22591
- flowParseTypeAndPredicateInitialiser() {
22592
- const oldInType = this.state.inType;
22593
-
22594
- this.state.inType = true;
22595
- this.expect(14);
22596
- let type = null;
22597
- let predicate = null;
22598
-
22599
- if (this.match(54)) {
22600
- this.state.inType = oldInType;
22601
- predicate = this.flowParsePredicate();
22602
- } else {
22603
- type = this.flowParseType();
22604
- this.state.inType = oldInType;
22605
-
22606
- if (this.match(54)) {
22607
- predicate = this.flowParsePredicate();
22608
- }
22609
- }
22610
-
22611
- return [type, predicate];
22612
- }
22613
-
22614
- flowParseDeclareClass(node) {
22615
- this.next();
22616
- this.flowParseInterfaceish(node, true);
22617
- return this.finishNode(node, 'DeclareClass');
22618
- }
22619
-
22620
- flowParseDeclareFunction(node) {
22621
- this.next();
22622
- const id = node.id = this.parseIdentifier();
22623
- const typeNode = this.startNode();
22624
- const typeContainer = this.startNode();
22625
-
22626
- if (this.match(47)) {
22627
- typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
22628
- } else {
22629
- typeNode.typeParameters = null;
22630
- }
22631
-
22632
- this.expect(10);
22633
- const tmp = this.flowParseFunctionTypeParams();
22634
-
22635
- typeNode.params = tmp.params;
22636
- typeNode.rest = tmp.rest;
22637
- typeNode.this = tmp._this;
22638
- this.expect(11);
22639
- [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
22640
- typeContainer.typeAnnotation = this.finishNode(typeNode, 'FunctionTypeAnnotation');
22641
- id.typeAnnotation = this.finishNode(typeContainer, 'TypeAnnotation');
22642
- this.resetEndLocation(id);
22643
- this.semicolon();
22644
- this.scope.declareName(node.id.name, 2048, node.id.loc.start);
22645
- return this.finishNode(node, 'DeclareFunction');
22646
- }
22647
-
22648
- flowParseDeclare(node, insideModule) {
22649
- if (this.match(80)) {
22650
- return this.flowParseDeclareClass(node);
22651
- } else if (this.match(68)) {
22652
- return this.flowParseDeclareFunction(node);
22653
- } else if (this.match(74)) {
22654
- return this.flowParseDeclareVariable(node);
22655
- } else if (this.eatContextual(127)) {
22656
- if (this.match(16)) {
22657
- return this.flowParseDeclareModuleExports(node);
22658
- } else {
22659
- if (insideModule) {
22660
- this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
22661
- }
22662
-
22663
- return this.flowParseDeclareModule(node);
22664
- }
22665
- } else if (this.isContextual(130)) {
22666
- return this.flowParseDeclareTypeAlias(node);
22667
- } else if (this.isContextual(131)) {
22668
- return this.flowParseDeclareOpaqueType(node);
22669
- } else if (this.isContextual(129)) {
22670
- return this.flowParseDeclareInterface(node);
22671
- } else if (this.match(82)) {
22672
- return this.flowParseDeclareExportDeclaration(node, insideModule);
22673
- } else {
22674
- this.unexpected();
22675
- }
22676
-
22677
-
22678
-
22679
-
22680
-
22681
-
22682
- }
22683
-
22684
- flowParseDeclareVariable(node) {
22685
- this.next();
22686
- node.id = this.flowParseTypeAnnotatableIdentifier(true);
22687
- this.scope.declareName(node.id.name, 5, node.id.loc.start);
22688
- this.semicolon();
22689
- return this.finishNode(node, 'DeclareVariable');
22690
- }
22691
-
22692
- flowParseDeclareModule(node) {
22693
- this.scope.enter(0);
22694
-
22695
- if (this.match(134)) {
22696
- node.id = super.parseExprAtom();
22697
- } else {
22698
- node.id = this.parseIdentifier();
22699
- }
22700
-
22701
- const bodyNode = node.body = this.startNode();
22702
- const body = bodyNode.body = [];
22703
-
22704
- this.expect(5);
22705
- while (!this.match(8)) {
22706
- let bodyNode2 = this.startNode();
22707
-
22708
- if (this.match(83)) {
22709
- this.next();
22710
-
22711
- if (!this.isContextual(130) && !this.match(87)) {
22712
- this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
22713
- }
22714
-
22715
- super.parseImport(bodyNode2);
22716
- } else {
22717
- this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
22718
- bodyNode2 = this.flowParseDeclare(bodyNode2, true);
22719
- }
22720
-
22721
- body.push(bodyNode2);
22722
- }
22723
-
22724
- this.scope.exit();
22725
- this.expect(8);
22726
- this.finishNode(bodyNode, 'BlockStatement');
22727
- let kind = null;
22728
- let hasModuleExport = false;
22729
-
22730
- body.forEach((bodyElement) => {
22731
- if (isEsModuleType(bodyElement)) {
22732
- if (kind === 'CommonJS') {
22733
- this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
22734
- }
22735
-
22736
- kind = 'ES';
22737
- } else if (bodyElement.type === 'DeclareModuleExports') {
22738
- if (hasModuleExport) {
22739
- this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
22740
- }
22741
-
22742
- if (kind === 'ES') {
22743
- this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
22744
- }
22745
-
22746
- kind = 'CommonJS';
22747
- hasModuleExport = true;
22748
- }
22749
- });
22750
- node.kind = kind || 'CommonJS';
22751
- return this.finishNode(node, 'DeclareModule');
22752
- }
22753
-
22754
- flowParseDeclareExportDeclaration(node, insideModule) {
22755
- this.expect(82);
22756
-
22757
- if (this.eat(65)) {
22758
- if (this.match(68) || this.match(80)) {
22759
- node.declaration = this.flowParseDeclare(this.startNode());
22760
- } else {
22761
- node.declaration = this.flowParseType();
22762
- this.semicolon();
22763
- }
22764
-
22765
- node.default = true;
22766
- return this.finishNode(node, 'DeclareExportDeclaration');
22767
- } else {
22768
- if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
22769
- const label = this.state.value;
22770
-
22771
- throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
22772
- unsupportedExportKind: label,
22773
- suggestion: exportSuggestions[label],
22774
- });
22775
- }
22776
-
22777
- if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
22778
- node.declaration = this.flowParseDeclare(this.startNode());
22779
- node.default = false;
22780
- return this.finishNode(node, 'DeclareExportDeclaration');
22781
- } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
22782
- node = this.parseExport(node, null);
22783
-
22784
- if (node.type === 'ExportNamedDeclaration') {
22785
- node.default = false;
22786
- delete node.exportKind;
22787
- return this.castNodeTo(node, 'DeclareExportDeclaration');
22788
- } else {
22789
- return this.castNodeTo(node, 'DeclareExportAllDeclaration');
22790
- }
22791
- }
22792
- }
22793
-
22794
- this.unexpected();
22795
- }
22796
-
22797
- flowParseDeclareModuleExports(node) {
22798
- this.next();
22799
- this.expectContextual(111);
22800
- node.typeAnnotation = this.flowParseTypeAnnotation();
22801
- this.semicolon();
22802
- return this.finishNode(node, 'DeclareModuleExports');
22803
- }
22804
-
22805
- flowParseDeclareTypeAlias(node) {
22806
- this.next();
22807
- const finished = this.flowParseTypeAlias(node);
22808
- this.castNodeTo(finished, 'DeclareTypeAlias');
22809
- return finished;
22810
- }
22811
-
22812
- flowParseDeclareOpaqueType(node) {
22813
- this.next();
22814
- const finished = this.flowParseOpaqueType(node, true);
22815
- this.castNodeTo(finished, 'DeclareOpaqueType');
22816
- return finished;
22817
- }
22818
-
22819
- flowParseDeclareInterface(node) {
22820
- this.next();
22821
- this.flowParseInterfaceish(node, false);
22822
- return this.finishNode(node, 'DeclareInterface');
22823
- }
22824
-
22825
- flowParseInterfaceish(node, isClass3) {
22826
- node.id = this.flowParseRestrictedIdentifier(!isClass3, true);
22827
- this.scope.declareName(node.id.name, isClass3 ? 17 : 8201, node.id.loc.start);
22828
-
22829
- if (this.match(47)) {
22830
- node.typeParameters = this.flowParseTypeParameterDeclaration();
22831
- } else {
22832
- node.typeParameters = null;
22833
- }
22834
-
22835
- node.extends = [];
22836
-
22837
- if (this.eat(81)) {
22838
- do {
22839
- node.extends.push(this.flowParseInterfaceExtends());
22840
- } while (!isClass3 && this.eat(12))
22841
- }
22842
-
22843
- if (isClass3) {
22844
- node.implements = [];
22845
- node.mixins = [];
22846
-
22847
- if (this.eatContextual(117)) {
22848
- do {
22849
- node.mixins.push(this.flowParseInterfaceExtends());
22850
- } while (this.eat(12))
22851
- }
22852
-
22853
- if (this.eatContextual(113)) {
22854
- do {
22855
- node.implements.push(this.flowParseInterfaceExtends());
22856
- } while (this.eat(12))
22857
- }
22858
- }
22859
-
22860
- node.body = this.flowParseObjectType({
22861
- allowStatic: isClass3,
22862
- allowExact: false,
22863
- allowSpread: false,
22864
- allowProto: isClass3,
22865
- allowInexact: false,
22866
- });
22867
- }
22868
-
22869
- flowParseInterfaceExtends() {
22870
- const node = this.startNode();
22871
-
22872
- node.id = this.flowParseQualifiedTypeIdentifier();
22873
-
22874
- if (this.match(47)) {
22875
- node.typeParameters = this.flowParseTypeParameterInstantiation();
22876
- } else {
22877
- node.typeParameters = null;
22878
- }
22879
-
22880
- return this.finishNode(node, 'InterfaceExtends');
22881
- }
22882
-
22883
- flowParseInterface(node) {
22884
- this.flowParseInterfaceish(node, false);
22885
- return this.finishNode(node, 'InterfaceDeclaration');
22886
- }
22887
-
22888
- checkNotUnderscore(word) {
22889
- if (word === '_') {
22890
- this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
22891
- }
22892
- }
22893
-
22894
- checkReservedType(word, startLoc, declaration) {
22895
- if (!reservedTypes.has(word))
22896
- return;
22897
-
22898
- this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
22899
- reservedType: word,
22900
- });
22901
- }
22902
-
22903
- flowParseRestrictedIdentifier(liberal, declaration) {
22904
- this.checkReservedType(this.state.value, this.state.startLoc, declaration);
22905
- return this.parseIdentifier(liberal);
22906
- }
22907
-
22908
- flowParseTypeAlias(node) {
22909
- node.id = this.flowParseRestrictedIdentifier(false, true);
22910
- this.scope.declareName(node.id.name, 8201, node.id.loc.start);
22911
-
22912
- if (this.match(47)) {
22913
- node.typeParameters = this.flowParseTypeParameterDeclaration();
22914
- } else {
22915
- node.typeParameters = null;
22916
- }
22917
-
22918
- node.right = this.flowParseTypeInitialiser(29);
22919
- this.semicolon();
22920
- return this.finishNode(node, 'TypeAlias');
22921
- }
22922
-
22923
- flowParseOpaqueType(node, declare) {
22924
- this.expectContextual(130);
22925
- node.id = this.flowParseRestrictedIdentifier(true, true);
22926
- this.scope.declareName(node.id.name, 8201, node.id.loc.start);
22927
-
22928
- if (this.match(47)) {
22929
- node.typeParameters = this.flowParseTypeParameterDeclaration();
22930
- } else {
22931
- node.typeParameters = null;
22932
- }
22933
-
22934
- node.supertype = null;
22935
-
22936
- if (this.match(14)) {
22937
- node.supertype = this.flowParseTypeInitialiser(14);
22938
- }
22939
-
22940
- node.impltype = null;
22941
-
22942
- if (!declare) {
22943
- node.impltype = this.flowParseTypeInitialiser(29);
22944
- }
22945
-
22946
- this.semicolon();
22947
- return this.finishNode(node, 'OpaqueType');
22948
- }
22949
-
22950
- flowParseTypeParameter(requireDefault = false) {
22951
- const nodeStartLoc = this.state.startLoc;
22952
- const node = this.startNode();
22953
- const variance2 = this.flowParseVariance();
22954
- const ident = this.flowParseTypeAnnotatableIdentifier();
22955
-
22956
- node.name = ident.name;
22957
- node.variance = variance2;
22958
- node.bound = ident.typeAnnotation;
22959
-
22960
- if (this.match(29)) {
22961
- this.eat(29);
22962
- node.default = this.flowParseType();
22963
- } else {
22964
- if (requireDefault) {
22965
- this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
22966
- }
22967
- }
22968
-
22969
- return this.finishNode(node, 'TypeParameter');
22970
- }
22971
-
22972
- flowParseTypeParameterDeclaration() {
22973
- const oldInType = this.state.inType;
22974
- const node = this.startNode();
22975
-
22976
- node.params = [];
22977
- this.state.inType = true;
22978
-
22979
- if (this.match(47) || this.match(143)) {
22980
- this.next();
22981
- } else {
22982
- this.unexpected();
22983
- }
22984
-
22985
- let defaultRequired = false;
22986
-
22987
- do {
22988
- const typeParameter2 = this.flowParseTypeParameter(defaultRequired);
22989
- node.params.push(typeParameter2);
22990
-
22991
- if (typeParameter2.default) {
22992
- defaultRequired = true;
22993
- }
22994
-
22995
- if (!this.match(48)) {
22996
- this.expect(12);
22997
- }
22998
- } while (!this.match(48))
22999
- this.expect(48);
23000
- this.state.inType = oldInType;
23001
- return this.finishNode(node, 'TypeParameterDeclaration');
23002
- }
23003
-
23004
- flowInTopLevelContext(cb) {
23005
- if (this.curContext() !== types.brace) {
23006
- const oldContext = this.state.context;
23007
-
23008
- this.state.context = [oldContext[0]];
23009
- try {
23010
- return cb();
23011
- } finally {
23012
- this.state.context = oldContext;
23013
- }
23014
- } else {
23015
- return cb();
23016
- }
23017
- }
23018
-
23019
- flowParseTypeParameterInstantiationInExpression() {
23020
- if (this.reScan_lt() !== 47)
23021
- return;
23022
-
23023
- return this.flowParseTypeParameterInstantiation();
23024
- }
23025
-
23026
- flowParseTypeParameterInstantiation() {
23027
- const node = this.startNode();
23028
- const oldInType = this.state.inType;
23029
-
23030
- this.state.inType = true;
23031
- node.params = [];
23032
- this.flowInTopLevelContext(() => {
23033
- this.expect(47);
23034
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
23035
-
23036
- this.state.noAnonFunctionType = false;
23037
- while (!this.match(48)) {
23038
- node.params.push(this.flowParseType());
23039
-
23040
- if (!this.match(48)) {
23041
- this.expect(12);
23042
- }
23043
- }
23044
-
23045
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
23046
- });
23047
- this.state.inType = oldInType;
23048
-
23049
- if (!this.state.inType && this.curContext() === types.brace) {
23050
- this.reScan_lt_gt();
23051
- }
23052
-
23053
- this.expect(48);
23054
- return this.finishNode(node, 'TypeParameterInstantiation');
23055
- }
23056
-
23057
- flowParseTypeParameterInstantiationCallOrNew() {
23058
- if (this.reScan_lt() !== 47)
23059
- return;
23060
-
23061
- const node = this.startNode();
23062
- const oldInType = this.state.inType;
23063
-
23064
- node.params = [];
23065
- this.state.inType = true;
23066
- this.expect(47);
23067
- while (!this.match(48)) {
23068
- node.params.push(this.flowParseTypeOrImplicitInstantiation());
23069
-
23070
- if (!this.match(48)) {
23071
- this.expect(12);
23072
- }
23073
- }
23074
-
23075
- this.expect(48);
23076
- this.state.inType = oldInType;
23077
- return this.finishNode(node, 'TypeParameterInstantiation');
23078
- }
23079
-
23080
- flowParseInterfaceType() {
23081
- const node = this.startNode();
23082
- this.expectContextual(129);
23083
- node.extends = [];
23084
-
23085
- if (this.eat(81)) {
23086
- do {
23087
- node.extends.push(this.flowParseInterfaceExtends());
23088
- } while (this.eat(12))
23089
- }
23090
-
23091
- node.body = this.flowParseObjectType({
23092
- allowStatic: false,
23093
- allowExact: false,
23094
- allowSpread: false,
23095
- allowProto: false,
23096
- allowInexact: false,
23097
- });
23098
- return this.finishNode(node, 'InterfaceTypeAnnotation');
23099
- }
23100
-
23101
- flowParseObjectPropertyKey() {
23102
- return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
23103
- }
23104
-
23105
- flowParseObjectTypeIndexer(node, isStatic2, variance2) {
23106
- node.static = isStatic2;
23107
-
23108
- if (this.lookahead().type === 14) {
23109
- node.id = this.flowParseObjectPropertyKey();
23110
- node.key = this.flowParseTypeInitialiser();
23111
- } else {
23112
- node.id = null;
23113
- node.key = this.flowParseType();
23114
- }
23115
-
23116
- this.expect(3);
23117
- node.value = this.flowParseTypeInitialiser();
23118
- node.variance = variance2;
23119
- return this.finishNode(node, 'ObjectTypeIndexer');
23120
- }
23121
-
23122
- flowParseObjectTypeInternalSlot(node, isStatic2) {
23123
- node.static = isStatic2;
23124
- node.id = this.flowParseObjectPropertyKey();
23125
- this.expect(3);
23126
- this.expect(3);
23127
-
23128
- if (this.match(47) || this.match(10)) {
23129
- node.method = true;
23130
- node.optional = false;
23131
- node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
23132
- } else {
23133
- node.method = false;
23134
-
23135
- if (this.eat(17)) {
23136
- node.optional = true;
23137
- }
23138
-
23139
- node.value = this.flowParseTypeInitialiser();
23140
- }
23141
-
23142
- return this.finishNode(node, 'ObjectTypeInternalSlot');
23143
- }
23144
-
23145
- flowParseObjectTypeMethodish(node) {
23146
- node.params = [];
23147
- node.rest = null;
23148
- node.typeParameters = null;
23149
- node.this = null;
23150
-
23151
- if (this.match(47)) {
23152
- node.typeParameters = this.flowParseTypeParameterDeclaration();
23153
- }
23154
-
23155
- this.expect(10);
23156
-
23157
- if (this.match(78)) {
23158
- node.this = this.flowParseFunctionTypeParam(true);
23159
- node.this.name = null;
23160
-
23161
- if (!this.match(11)) {
23162
- this.expect(12);
23163
- }
23164
- }
23165
-
23166
- while (!this.match(11) && !this.match(21)) {
23167
- node.params.push(this.flowParseFunctionTypeParam(false));
23168
-
23169
- if (!this.match(11)) {
23170
- this.expect(12);
23171
- }
23172
- }
23173
-
23174
- if (this.eat(21)) {
23175
- node.rest = this.flowParseFunctionTypeParam(false);
23176
- }
23177
-
23178
- this.expect(11);
23179
- node.returnType = this.flowParseTypeInitialiser();
23180
- return this.finishNode(node, 'FunctionTypeAnnotation');
23181
- }
23182
-
23183
- flowParseObjectTypeCallProperty(node, isStatic2) {
23184
- const valueNode = this.startNode();
23185
-
23186
- node.static = isStatic2;
23187
- node.value = this.flowParseObjectTypeMethodish(valueNode);
23188
- return this.finishNode(node, 'ObjectTypeCallProperty');
23189
- }
23190
-
23191
- flowParseObjectType({allowStatic, allowExact, allowSpread, allowProto, allowInexact}) {
23192
- const oldInType = this.state.inType;
23193
-
23194
- this.state.inType = true;
23195
- const nodeStart = this.startNode();
23196
-
23197
- nodeStart.callProperties = [];
23198
- nodeStart.properties = [];
23199
- nodeStart.indexers = [];
23200
- nodeStart.internalSlots = [];
23201
- let endDelim;
23202
- let exact;
23203
- let inexact = false;
23204
-
23205
- if (allowExact && this.match(6)) {
23206
- this.expect(6);
23207
- endDelim = 9;
23208
- exact = true;
23209
- } else {
23210
- this.expect(5);
23211
- endDelim = 8;
23212
- exact = false;
23213
- }
23214
-
23215
- nodeStart.exact = exact;
23216
- while (!this.match(endDelim)) {
23217
- let isStatic2 = false;
23218
- let protoStartLoc = null;
23219
- let inexactStartLoc = null;
23220
- const node = this.startNode();
23221
-
23222
- if (allowProto && this.isContextual(118)) {
23223
- const lookahead = this.lookahead();
23224
-
23225
- if (lookahead.type !== 14 && lookahead.type !== 17) {
23226
- this.next();
23227
- protoStartLoc = this.state.startLoc;
23228
- allowStatic = false;
23229
- }
23230
- }
23231
-
23232
- if (allowStatic && this.isContextual(106)) {
23233
- const lookahead = this.lookahead();
23234
-
23235
- if (lookahead.type !== 14 && lookahead.type !== 17) {
23236
- this.next();
23237
- isStatic2 = true;
23238
- }
23239
- }
23240
-
23241
- const variance2 = this.flowParseVariance();
23242
-
23243
- if (this.eat(0)) {
23244
- if (protoStartLoc != null) {
23245
- this.unexpected(protoStartLoc);
23246
- }
23247
-
23248
- if (this.eat(0)) {
23249
- if (variance2) {
23250
- this.unexpected(variance2.loc.start);
23251
- }
23252
-
23253
- nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic2));
23254
- } else {
23255
- nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic2, variance2));
23256
- }
23257
- } else if (this.match(10) || this.match(47)) {
23258
- if (protoStartLoc != null) {
23259
- this.unexpected(protoStartLoc);
23260
- }
23261
-
23262
- if (variance2) {
23263
- this.unexpected(variance2.loc.start);
23264
- }
23265
-
23266
- nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic2));
23267
- } else {
23268
- let kind = 'init';
23269
-
23270
- if (this.isContextual(99) || this.isContextual(104)) {
23271
- const lookahead = this.lookahead();
23272
-
23273
- if (tokenIsLiteralPropertyName(lookahead.type)) {
23274
- kind = this.state.value;
23275
- this.next();
23276
- }
23277
- }
23278
-
23279
- const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic2, protoStartLoc, variance2, kind, allowSpread, allowInexact ?? !exact);
23280
-
23281
- if (propOrInexact === null) {
23282
- inexact = true;
23283
- inexactStartLoc = this.state.lastTokStartLoc;
23284
- } else {
23285
- nodeStart.properties.push(propOrInexact);
23286
- }
23287
- }
23288
-
23289
- this.flowObjectTypeSemicolon();
23290
-
23291
- if (inexactStartLoc && !this.match(8) && !this.match(9)) {
23292
- this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
23293
- }
23294
- }
23295
-
23296
- this.expect(endDelim);
23297
-
23298
- if (allowSpread) {
23299
- nodeStart.inexact = inexact;
23300
- }
23301
-
23302
- const out = this.finishNode(nodeStart, 'ObjectTypeAnnotation');
23303
-
23304
- this.state.inType = oldInType;
23305
- return out;
23306
- }
23307
-
23308
- flowParseObjectTypeProperty(node, isStatic2, protoStartLoc, variance2, kind, allowSpread, allowInexact) {
23309
- if (this.eat(21)) {
23310
- const isInexactToken = this.match(12)
23311
- || this.match(13)
23312
- || this.match(8)
23313
- || this.match(9);
23314
-
23315
- if (isInexactToken) {
23316
- if (!allowSpread) {
23317
- this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
23318
- } else if (!allowInexact) {
23319
- this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
23320
- }
23321
-
23322
- if (variance2) {
23323
- this.raise(FlowErrors.InexactVariance, variance2);
23324
- }
23325
-
23326
- return null;
23327
- }
23328
-
23329
- if (!allowSpread) {
23330
- this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
23331
- }
23332
-
23333
- if (protoStartLoc != null) {
23334
- this.unexpected(protoStartLoc);
23335
- }
23336
-
23337
- if (variance2) {
23338
- this.raise(FlowErrors.SpreadVariance, variance2);
23339
- }
23340
-
23341
- node.argument = this.flowParseType();
23342
- return this.finishNode(node, 'ObjectTypeSpreadProperty');
23343
- } else {
23344
- node.key = this.flowParseObjectPropertyKey();
23345
- node.static = isStatic2;
23346
- node.proto = protoStartLoc != null;
23347
- node.kind = kind;
23348
- let optional = false;
23349
-
23350
- if (this.match(47) || this.match(10)) {
23351
- node.method = true;
23352
-
23353
- if (protoStartLoc != null) {
23354
- this.unexpected(protoStartLoc);
23355
- }
23356
-
23357
- if (variance2) {
23358
- this.unexpected(variance2.loc.start);
23359
- }
23360
-
23361
- node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
23362
-
23363
- if (kind === 'get' || kind === 'set') {
23364
- this.flowCheckGetterSetterParams(node);
23365
- }
23366
-
23367
- if (!allowSpread && node.key.name === 'constructor' && node.value.this) {
23368
- this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
23369
- }
23370
- } else {
23371
- if (kind !== 'init')
23372
- this.unexpected();
23373
-
23374
- node.method = false;
23375
-
23376
- if (this.eat(17)) {
23377
- optional = true;
23378
- }
23379
-
23380
- node.value = this.flowParseTypeInitialiser();
23381
- node.variance = variance2;
23382
- }
23383
-
23384
- node.optional = optional;
23385
- return this.finishNode(node, 'ObjectTypeProperty');
23386
- }
23387
- }
23388
-
23389
- flowCheckGetterSetterParams(property) {
23390
- const paramCount = property.kind === 'get' ? 0 : 1;
23391
- const length = property.value.params.length + (property.value.rest ? 1 : 0);
23392
-
23393
- if (property.value.this) {
23394
- this.raise(property.kind === 'get' ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
23395
- }
23396
-
23397
- if (length !== paramCount) {
23398
- this.raise(property.kind === 'get' ? Errors.BadGetterArity : Errors.BadSetterArity, property);
23399
- }
23400
-
23401
- if (property.kind === 'set' && property.value.rest) {
23402
- this.raise(Errors.BadSetterRestParameter, property);
23403
- }
23404
- }
23405
-
23406
- flowObjectTypeSemicolon() {
23407
- if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
23408
- this.unexpected();
23409
- }
23410
- }
23411
-
23412
- flowParseQualifiedTypeIdentifier(startLoc, id) {
23413
- startLoc ?? (startLoc = this.state.startLoc);
23414
- let node = id || this.flowParseRestrictedIdentifier(true);
23415
-
23416
- while (this.eat(16)) {
23417
- const node2 = this.startNodeAt(startLoc);
23418
-
23419
- node2.qualification = node;
23420
- node2.id = this.flowParseRestrictedIdentifier(true);
23421
- node = this.finishNode(node2, 'QualifiedTypeIdentifier');
23422
- }
23423
-
23424
- return node;
23425
- }
23426
-
23427
- flowParseGenericType(startLoc, id) {
23428
- const node = this.startNodeAt(startLoc);
23429
-
23430
- node.typeParameters = null;
23431
- node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
23432
-
23433
- if (this.match(47)) {
23434
- node.typeParameters = this.flowParseTypeParameterInstantiation();
23435
- }
23436
-
23437
- return this.finishNode(node, 'GenericTypeAnnotation');
23438
- }
23439
-
23440
- flowParseTypeofType() {
23441
- const node = this.startNode();
23442
- this.expect(87);
23443
- node.argument = this.flowParsePrimaryType();
23444
- return this.finishNode(node, 'TypeofTypeAnnotation');
23445
- }
23446
-
23447
- flowParseTupleType() {
23448
- const node = this.startNode();
23449
-
23450
- node.types = [];
23451
- this.expect(0);
23452
- while (this.state.pos < this.length && !this.match(3)) {
23453
- node.types.push(this.flowParseType());
23454
-
23455
- if (this.match(3))
23456
- break;
23457
-
23458
- this.expect(12);
23459
- }
23460
-
23461
- this.expect(3);
23462
- return this.finishNode(node, 'TupleTypeAnnotation');
23463
- }
23464
-
23465
- flowParseFunctionTypeParam(first) {
23466
- let name = null;
23467
- let optional = false;
23468
- let typeAnnotation2 = null;
23469
- const node = this.startNode();
23470
- const lh = this.lookahead();
23471
- const isThis = this.state.type === 78;
23472
-
23473
- if (lh.type === 14 || lh.type === 17) {
23474
- if (isThis && !first) {
23475
- this.raise(FlowErrors.ThisParamMustBeFirst, node);
23476
- }
23477
-
23478
- name = this.parseIdentifier(isThis);
23479
-
23480
- if (this.eat(17)) {
23481
- optional = true;
23482
-
23483
- if (isThis) {
23484
- this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
23485
- }
23486
- }
23487
-
23488
- typeAnnotation2 = this.flowParseTypeInitialiser();
23489
- } else {
23490
- typeAnnotation2 = this.flowParseType();
23491
- }
23492
-
23493
- node.name = name;
23494
- node.optional = optional;
23495
- node.typeAnnotation = typeAnnotation2;
23496
- return this.finishNode(node, 'FunctionTypeParam');
23497
- }
23498
-
23499
- reinterpretTypeAsFunctionTypeParam(type) {
23500
- const node = this.startNodeAt(type.loc.start);
23501
-
23502
- node.name = null;
23503
- node.optional = false;
23504
- node.typeAnnotation = type;
23505
- return this.finishNode(node, 'FunctionTypeParam');
23506
- }
23507
-
23508
- flowParseFunctionTypeParams(params = []) {
23509
- let rest = null;
23510
- let _this = null;
23511
-
23512
- if (this.match(78)) {
23513
- _this = this.flowParseFunctionTypeParam(true);
23514
- _this.name = null;
23515
-
23516
- if (!this.match(11)) {
23517
- this.expect(12);
23518
- }
23519
- }
23520
-
23521
- while (!this.match(11) && !this.match(21)) {
23522
- params.push(this.flowParseFunctionTypeParam(false));
23523
-
23524
- if (!this.match(11)) {
23525
- this.expect(12);
23526
- }
23527
- }
23528
-
23529
- if (this.eat(21)) {
23530
- rest = this.flowParseFunctionTypeParam(false);
23531
- }
23532
-
23533
- return {
23534
- params,
23535
- rest,
23536
- _this,
23537
- };
23538
- }
23539
-
23540
- flowIdentToTypeAnnotation(startLoc, node, id) {
23541
- switch(id.name) {
23542
- case 'any':
23543
- return this.finishNode(node, 'AnyTypeAnnotation');
23544
-
23545
- case 'bool':
23546
- case 'boolean':
23547
- return this.finishNode(node, 'BooleanTypeAnnotation');
23548
-
23549
- case 'mixed':
23550
- return this.finishNode(node, 'MixedTypeAnnotation');
23551
-
23552
- case 'empty':
23553
- return this.finishNode(node, 'EmptyTypeAnnotation');
23554
-
23555
- case 'number':
23556
- return this.finishNode(node, 'NumberTypeAnnotation');
23557
-
23558
- case 'string':
23559
- return this.finishNode(node, 'StringTypeAnnotation');
23560
-
23561
- case 'symbol':
23562
- return this.finishNode(node, 'SymbolTypeAnnotation');
23563
-
23564
- default:
23565
- this.checkNotUnderscore(id.name);
23566
- return this.flowParseGenericType(startLoc, id);
23567
- }
23568
- }
23569
-
23570
- flowParsePrimaryType() {
23571
- const startLoc = this.state.startLoc;
23572
- const node = this.startNode();
23573
- let tmp;
23574
- let type;
23575
- let isGroupedType = false;
23576
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
23577
-
23578
- switch(this.state.type) {
23579
- case 5:
23580
- return this.flowParseObjectType({
23581
- allowStatic: false,
23582
- allowExact: false,
23583
- allowSpread: true,
23584
- allowProto: false,
23585
- allowInexact: true,
23586
- });
23587
-
23588
- case 6:
23589
- return this.flowParseObjectType({
23590
- allowStatic: false,
23591
- allowExact: true,
23592
- allowSpread: true,
23593
- allowProto: false,
23594
- allowInexact: false,
23595
- });
23596
-
23597
- case 0:
23598
- this.state.noAnonFunctionType = false;
23599
- type = this.flowParseTupleType();
23600
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
23601
- return type;
23602
-
23603
- case 47: {
23604
- const node2 = this.startNode();
23605
-
23606
- node2.typeParameters = this.flowParseTypeParameterDeclaration();
23607
- this.expect(10);
23608
- tmp = this.flowParseFunctionTypeParams();
23609
- node2.params = tmp.params;
23610
- node2.rest = tmp.rest;
23611
- node2.this = tmp._this;
23612
- this.expect(11);
23613
- this.expect(19);
23614
- node2.returnType = this.flowParseType();
23615
- return this.finishNode(node2, 'FunctionTypeAnnotation');
23616
- }
23617
-
23618
- case 10: {
23619
- const node2 = this.startNode();
23620
- this.next();
23621
-
23622
- if (!this.match(11) && !this.match(21)) {
23623
- if (tokenIsIdentifier(this.state.type) || this.match(78)) {
23624
- const token = this.lookahead().type;
23625
- isGroupedType = token !== 17 && token !== 14;
23626
- } else {
23627
- isGroupedType = true;
23628
- }
23629
- }
23630
-
23631
- if (isGroupedType) {
23632
- this.state.noAnonFunctionType = false;
23633
- type = this.flowParseType();
23634
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
23635
-
23636
- if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
23637
- this.expect(11);
23638
- return type;
23639
- } else {
23640
- this.eat(12);
23641
- }
23642
- }
23643
-
23644
- if (type) {
23645
- tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
23646
- } else {
23647
- tmp = this.flowParseFunctionTypeParams();
23648
- }
23649
-
23650
- node2.params = tmp.params;
23651
- node2.rest = tmp.rest;
23652
- node2.this = tmp._this;
23653
- this.expect(11);
23654
- this.expect(19);
23655
- node2.returnType = this.flowParseType();
23656
- node2.typeParameters = null;
23657
- return this.finishNode(node2, 'FunctionTypeAnnotation');
23658
- }
23659
-
23660
- case 134:
23661
- return this.parseLiteral(this.state.value, 'StringLiteralTypeAnnotation');
23662
-
23663
- case 85:
23664
- case 86:
23665
- node.value = this.match(85);
23666
- this.next();
23667
- return this.finishNode(node, 'BooleanLiteralTypeAnnotation');
23668
-
23669
- case 53:
23670
- if (this.state.value === '-') {
23671
- this.next();
23672
-
23673
- if (this.match(135)) {
23674
- return this.parseLiteralAtNode(-this.state.value, 'NumberLiteralTypeAnnotation', node);
23675
- }
23676
-
23677
- if (this.match(136)) {
23678
- return this.parseLiteralAtNode(-this.state.value, 'BigIntLiteralTypeAnnotation', node);
23679
- }
23680
-
23681
- throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
23682
- }
23683
-
23684
- this.unexpected();
23685
- return;
23686
-
23687
- case 135:
23688
- return this.parseLiteral(this.state.value, 'NumberLiteralTypeAnnotation');
23689
-
23690
- case 136:
23691
- return this.parseLiteral(this.state.value, 'BigIntLiteralTypeAnnotation');
23692
-
23693
- case 88:
23694
- this.next();
23695
- return this.finishNode(node, 'VoidTypeAnnotation');
23696
-
23697
- case 84:
23698
- this.next();
23699
- return this.finishNode(node, 'NullLiteralTypeAnnotation');
23700
-
23701
- case 78:
23702
- this.next();
23703
- return this.finishNode(node, 'ThisTypeAnnotation');
23704
-
23705
- case 55:
23706
- this.next();
23707
- return this.finishNode(node, 'ExistsTypeAnnotation');
23708
-
23709
- case 87:
23710
- return this.flowParseTypeofType();
23711
-
23712
- default:
23713
- if (tokenIsKeyword(this.state.type)) {
23714
- const label = tokenLabelName(this.state.type);
23715
- this.next();
23716
- return super.createIdentifier(node, label);
23717
- } else if (tokenIsIdentifier(this.state.type)) {
23718
- if (this.isContextual(129)) {
23719
- return this.flowParseInterfaceType();
23720
- }
23721
-
23722
- return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
23723
- }
23724
- }
23725
-
23726
- this.unexpected();
23727
- }
23728
-
23729
- flowParsePostfixType() {
23730
- const startLoc = this.state.startLoc;
23731
- let type = this.flowParsePrimaryType();
23732
- let seenOptionalIndexedAccess = false;
23733
-
23734
- while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
23735
- const node = this.startNodeAt(startLoc);
23736
- const optional = this.eat(18);
23737
-
23738
- seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
23739
- this.expect(0);
23740
-
23741
- if (!optional && this.match(3)) {
23742
- node.elementType = type;
23743
- this.next();
23744
- type = this.finishNode(node, 'ArrayTypeAnnotation');
23745
- } else {
23746
- node.objectType = type;
23747
- node.indexType = this.flowParseType();
23748
- this.expect(3);
23749
-
23750
- if (seenOptionalIndexedAccess) {
23751
- node.optional = optional;
23752
- type = this.finishNode(node, 'OptionalIndexedAccessType');
23753
- } else {
23754
- type = this.finishNode(node, 'IndexedAccessType');
23755
- }
23756
- }
23757
- }
23758
-
23759
- return type;
23760
- }
23761
-
23762
- flowParsePrefixType() {
23763
- const node = this.startNode();
23764
-
23765
- if (this.eat(17)) {
23766
- node.typeAnnotation = this.flowParsePrefixType();
23767
- return this.finishNode(node, 'NullableTypeAnnotation');
23768
- } else {
23769
- return this.flowParsePostfixType();
23770
- }
23771
- }
23772
-
23773
- flowParseAnonFunctionWithoutParens() {
23774
- const param = this.flowParsePrefixType();
23775
-
23776
- if (!this.state.noAnonFunctionType && this.eat(19)) {
23777
- const node = this.startNodeAt(param.loc.start);
23778
-
23779
- node.params = [
23780
- this.reinterpretTypeAsFunctionTypeParam(param),
23781
- ];
23782
- node.rest = null;
23783
- node.this = null;
23784
- node.returnType = this.flowParseType();
23785
- node.typeParameters = null;
23786
- return this.finishNode(node, 'FunctionTypeAnnotation');
23787
- }
23788
-
23789
- return param;
23790
- }
23791
-
23792
- flowParseIntersectionType() {
23793
- const node = this.startNode();
23794
- this.eat(45);
23795
- const type = this.flowParseAnonFunctionWithoutParens();
23796
-
23797
- node.types = [type];
23798
- while (this.eat(45)) {
23799
- node.types.push(this.flowParseAnonFunctionWithoutParens());
23800
- }
23801
-
23802
- return node.types.length === 1 ? type : this.finishNode(node, 'IntersectionTypeAnnotation');
23803
- }
23804
-
23805
- flowParseUnionType() {
23806
- const node = this.startNode();
23807
- this.eat(43);
23808
- const type = this.flowParseIntersectionType();
23809
-
23810
- node.types = [type];
23811
- while (this.eat(43)) {
23812
- node.types.push(this.flowParseIntersectionType());
23813
- }
23814
-
23815
- return node.types.length === 1 ? type : this.finishNode(node, 'UnionTypeAnnotation');
23816
- }
23817
-
23818
- flowParseType() {
23819
- const oldInType = this.state.inType;
23820
-
23821
- this.state.inType = true;
23822
- const type = this.flowParseUnionType();
23823
-
23824
- this.state.inType = oldInType;
23825
- return type;
23826
- }
23827
-
23828
- flowParseTypeOrImplicitInstantiation() {
23829
- if (this.state.type === 132 && this.state.value === '_') {
23830
- const startLoc = this.state.startLoc;
23831
- const node = this.parseIdentifier();
23832
-
23833
- return this.flowParseGenericType(startLoc, node);
23834
- } else {
23835
- return this.flowParseType();
23836
- }
23837
- }
23838
-
23839
- flowParseTypeAnnotation() {
23840
- const node = this.startNode();
23841
-
23842
- node.typeAnnotation = this.flowParseTypeInitialiser();
23843
- return this.finishNode(node, 'TypeAnnotation');
23844
- }
23845
-
23846
- flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
23847
- const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
23848
-
23849
- if (this.match(14)) {
23850
- ident.typeAnnotation = this.flowParseTypeAnnotation();
23851
- this.resetEndLocation(ident);
23852
- }
23853
-
23854
- return ident;
23855
- }
23856
-
23857
- typeCastToParameter(node) {
23858
- node.expression.typeAnnotation = node.typeAnnotation;
23859
- this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
23860
- return node.expression;
23861
- }
23862
-
23863
- flowParseVariance() {
23864
- let variance2 = null;
23865
-
23866
- if (this.match(53)) {
23867
- variance2 = this.startNode();
23868
-
23869
- if (this.state.value === '+') {
23870
- variance2.kind = 'plus';
23871
- } else {
23872
- variance2.kind = 'minus';
23873
- }
23874
-
23875
- this.next();
23876
- return this.finishNode(variance2, 'Variance');
23877
- }
23878
-
23879
- return variance2;
23880
- }
23881
-
23882
- parseFunctionBody(node, allowExpressionBody, isMethod3 = false) {
23883
- if (allowExpressionBody) {
23884
- this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod3));
23885
- return;
23886
- }
23887
-
23888
- super.parseFunctionBody(node, false, isMethod3);
23889
- }
23890
-
23891
- parseFunctionBodyAndFinish(node, type, isMethod3 = false) {
23892
- if (this.match(14)) {
23893
- const typeNode = this.startNode();
23894
-
23895
- [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
23896
- node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, 'TypeAnnotation') : null;
23897
- }
23898
-
23899
- return super.parseFunctionBodyAndFinish(node, type, isMethod3);
23900
- }
23901
-
23902
- parseStatementLike(flags) {
23903
- if (this.state.strict && this.isContextual(129)) {
23904
- const lookahead = this.lookahead();
23905
-
23906
- if (tokenIsKeywordOrIdentifier(lookahead.type)) {
23907
- const node = this.startNode();
23908
- this.next();
23909
- return this.flowParseInterface(node);
23910
- }
23911
- } else if (this.isContextual(126)) {
23912
- const node = this.startNode();
23913
- this.next();
23914
- return this.flowParseEnumDeclaration(node);
23915
- }
23916
-
23917
- const stmt = super.parseStatementLike(flags);
23918
-
23919
- if (this.flowPragma === void 0 && !this.isValidDirective(stmt)) {
23920
- this.flowPragma = null;
23921
- }
23922
-
23923
- return stmt;
23924
- }
23925
-
23926
- parseExpressionStatement(node, expr, decorators) {
23927
- if (expr.type === 'Identifier') {
23928
- if (expr.name === 'declare') {
23929
- if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
23930
- return this.flowParseDeclare(node);
23931
- }
23932
- } else if (tokenIsIdentifier(this.state.type)) {
23933
- if (expr.name === 'interface') {
23934
- return this.flowParseInterface(node);
23935
- } else if (expr.name === 'type') {
23936
- return this.flowParseTypeAlias(node);
23937
- } else if (expr.name === 'opaque') {
23938
- return this.flowParseOpaqueType(node, false);
23939
- }
23940
-
23941
- }
23942
- }
23943
-
23944
- return super.parseExpressionStatement(node, expr, decorators);
23945
- }
23946
-
23947
- shouldParseExportDeclaration() {
23948
- const {type} = this.state;
23949
-
23950
- if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
23951
- return !this.state.containsEsc;
23952
- }
23953
-
23954
- return super.shouldParseExportDeclaration();
23955
- }
23956
-
23957
- isExportDefaultSpecifier() {
23958
- const {type} = this.state;
23959
-
23960
- if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
23961
- return this.state.containsEsc;
23962
- }
23963
-
23964
- return super.isExportDefaultSpecifier();
23965
- }
23966
-
23967
- parseExportDefaultExpression() {
23968
- if (this.isContextual(126)) {
23969
- const node = this.startNode();
23970
- this.next();
23971
- return this.flowParseEnumDeclaration(node);
23972
- }
23973
-
23974
- return super.parseExportDefaultExpression();
23975
- }
23976
-
23977
- parseConditional(expr, startLoc, refExpressionErrors) {
23978
- if (!this.match(17))
23979
- return expr;
23980
-
23981
- if (this.state.maybeInArrowParameters) {
23982
- const nextCh = this.lookaheadCharCode();
23983
-
23984
- if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
23985
- this.setOptionalParametersError(refExpressionErrors);
23986
- return expr;
23987
- }
23988
- }
23989
-
23990
- this.expect(17);
23991
- const state = this.state.clone();
23992
- const originalNoArrowAt = this.state.noArrowAt;
23993
- const node = this.startNodeAt(startLoc);
23994
-
23995
- let {consequent, failed} = this.tryParseConditionalConsequent();
23996
-
23997
- let [valid, invalid] = this.getArrowLikeExpressions(consequent);
23998
-
23999
- if (failed || invalid.length > 0) {
24000
- const noArrowAt = [...originalNoArrowAt];
24001
-
24002
- if (invalid.length > 0) {
24003
- this.state = state;
24004
- this.state.noArrowAt = noArrowAt;
24005
- for (let i = 0; i < invalid.length; i++) {
24006
- noArrowAt.push(invalid[i].start);
24007
- }
24008
-
24009
- ({
24010
- consequent,
24011
- failed,
24012
- } = this.tryParseConditionalConsequent());
24013
- [valid, invalid] = this.getArrowLikeExpressions(consequent);
24014
- }
24015
-
24016
- if (failed && valid.length > 1) {
24017
- this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
24018
- }
24019
-
24020
- if (failed && valid.length === 1) {
24021
- this.state = state;
24022
- noArrowAt.push(valid[0].start);
24023
- this.state.noArrowAt = noArrowAt;
24024
- ({
24025
- consequent,
24026
- failed,
24027
- } = this.tryParseConditionalConsequent());
24028
- }
24029
- }
24030
-
24031
- this.getArrowLikeExpressions(consequent, true);
24032
- this.state.noArrowAt = originalNoArrowAt;
24033
- this.expect(14);
24034
- node.test = expr;
24035
- node.consequent = consequent;
24036
- node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(void 0, void 0));
24037
-
24038
- return this.finishNode(node, 'ConditionalExpression');
24039
- }
24040
-
24041
- tryParseConditionalConsequent() {
24042
- this.state.noArrowParamsConversionAt.push(this.state.start);
24043
- const consequent = this.parseMaybeAssignAllowIn();
24044
- const failed = !this.match(14);
24045
-
24046
- this.state.noArrowParamsConversionAt.pop();
24047
- return {
24048
- consequent,
24049
- failed,
24050
- };
24051
- }
24052
-
24053
- getArrowLikeExpressions(node, disallowInvalid) {
24054
- const stack = [node];
24055
- const arrows = [];
24056
-
24057
- while (stack.length !== 0) {
24058
- const node2 = stack.pop();
24059
-
24060
- if (node2.type === 'ArrowFunctionExpression' && node2.body.type !== 'BlockStatement') {
24061
- if (node2.typeParameters || !node2.returnType) {
24062
- this.finishArrowValidation(node2);
24063
- } else {
24064
- arrows.push(node2);
24065
- }
24066
-
24067
- stack.push(node2.body);
24068
- } else if (node2.type === 'ConditionalExpression') {
24069
- stack.push(node2.consequent);
24070
- stack.push(node2.alternate);
24071
- }
24072
- }
24073
-
24074
- if (disallowInvalid) {
24075
- arrows.forEach((node2) => this.finishArrowValidation(node2));
24076
- return [
24077
- arrows,
24078
- [],
24079
- ];
24080
- }
24081
-
24082
- return partition(arrows, (node2) => node2.params.every((param) => this.isAssignable(param, true)));
24083
- }
24084
-
24085
- finishArrowValidation(node) {
24086
- this.toAssignableList(node.params, node.extra?.trailingCommaLoc, false);
24087
- this.scope.enter(514 | 4);
24088
- super.checkParams(node, false, true);
24089
- this.scope.exit();
24090
- }
24091
-
24092
- forwardNoArrowParamsConversionAt(node, parse3) {
24093
- let result;
24094
-
24095
- if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
24096
- this.state.noArrowParamsConversionAt.push(this.state.start);
24097
- result = parse3();
24098
- this.state.noArrowParamsConversionAt.pop();
24099
- } else {
24100
- result = parse3();
24101
- }
24102
-
24103
- return result;
24104
- }
24105
-
24106
- parseParenItem(node, startLoc) {
24107
- const newNode = super.parseParenItem(node, startLoc);
24108
-
24109
- if (this.eat(17)) {
24110
- newNode.optional = true;
24111
- this.resetEndLocation(node);
24112
- }
24113
-
24114
- if (this.match(14)) {
24115
- const typeCastNode = this.startNodeAt(startLoc);
24116
-
24117
- typeCastNode.expression = newNode;
24118
- typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
24119
- return this.finishNode(typeCastNode, 'TypeCastExpression');
24120
- }
24121
-
24122
- return newNode;
24123
- }
24124
-
24125
- assertModuleNodeAllowed(node) {
24126
- if (node.type === 'ImportDeclaration' && (node.importKind === 'type' || node.importKind === 'typeof') || node.type === 'ExportNamedDeclaration' && node.exportKind === 'type' || node.type === 'ExportAllDeclaration' && node.exportKind === 'type') {
24127
- return;
24128
- }
24129
-
24130
- super.assertModuleNodeAllowed(node);
24131
- }
24132
-
24133
- parseExportDeclaration(node) {
24134
- if (this.isContextual(130)) {
24135
- node.exportKind = 'type';
24136
- const declarationNode = this.startNode();
24137
- this.next();
24138
-
24139
- if (this.match(5)) {
24140
- node.specifiers = this.parseExportSpecifiers(true);
24141
- super.parseExportFrom(node);
24142
- return null;
24143
- } else {
24144
- return this.flowParseTypeAlias(declarationNode);
24145
- }
24146
- } else if (this.isContextual(131)) {
24147
- node.exportKind = 'type';
24148
- const declarationNode = this.startNode();
24149
- this.next();
24150
- return this.flowParseOpaqueType(declarationNode, false);
24151
- } else if (this.isContextual(129)) {
24152
- node.exportKind = 'type';
24153
- const declarationNode = this.startNode();
24154
- this.next();
24155
- return this.flowParseInterface(declarationNode);
24156
- } else if (this.isContextual(126)) {
24157
- node.exportKind = 'value';
24158
- const declarationNode = this.startNode();
24159
- this.next();
24160
- return this.flowParseEnumDeclaration(declarationNode);
24161
- } else {
24162
- return super.parseExportDeclaration(node);
24163
- }
24164
-
24165
-
24166
- }
24167
-
24168
- eatExportStar(node) {
24169
- if (super.eatExportStar(node))
24170
- return true;
24171
-
24172
- if (this.isContextual(130) && this.lookahead().type === 55) {
24173
- node.exportKind = 'type';
24174
- this.next();
24175
- this.next();
24176
- return true;
24177
- }
24178
-
24179
- return false;
24180
- }
24181
-
24182
- maybeParseExportNamespaceSpecifier(node) {
24183
- const {startLoc} = this.state;
24184
-
24185
- const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
24186
-
24187
- if (hasNamespace && node.exportKind === 'type') {
24188
- this.unexpected(startLoc);
24189
- }
24190
-
24191
- return hasNamespace;
24192
- }
24193
-
24194
- parseClassId(node, isStatement5, optionalId) {
24195
- super.parseClassId(node, isStatement5, optionalId);
24196
-
24197
- if (this.match(47)) {
24198
- node.typeParameters = this.flowParseTypeParameterDeclaration();
24199
- }
24200
- }
24201
-
24202
- parseClassMember(classBody2, member, state) {
24203
- const {startLoc} = this.state;
24204
-
24205
- if (this.isContextual(125)) {
24206
- if (super.parseClassMemberFromModifier(classBody2, member)) {
24207
- return;
24208
- }
24209
-
24210
- member.declare = true;
24211
- }
24212
-
24213
- super.parseClassMember(classBody2, member, state);
24214
-
24215
- if (member.declare) {
24216
- if (member.type !== 'ClassProperty' && member.type !== 'ClassPrivateProperty' && member.type !== 'PropertyDefinition') {
24217
- this.raise(FlowErrors.DeclareClassElement, startLoc);
24218
- } else if (member.value) {
24219
- this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
24220
- }
24221
- }
24222
- }
24223
-
24224
- isIterator(word) {
24225
- return word === 'iterator' || word === 'asyncIterator';
24226
- }
24227
-
24228
- readIterator() {
24229
- const word = super.readWord1();
24230
- const fullWord = '@@' + word;
24231
-
24232
- if (!this.isIterator(word) || !this.state.inType) {
24233
- this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
24234
- identifierName: fullWord,
24235
- });
24236
- }
24237
-
24238
- this.finishToken(132, fullWord);
24239
- }
24240
-
24241
- getTokenFromCode(code2) {
24242
- const next = this.input.charCodeAt(this.state.pos + 1);
24243
-
24244
- if (code2 === 123 && next === 124) {
24245
- this.finishOp(6, 2);
24246
- } else if (this.state.inType && (code2 === 62 || code2 === 60)) {
24247
- this.finishOp(code2 === 62 ? 48 : 47, 1);
24248
- } else if (this.state.inType && code2 === 63) {
24249
- if (next === 46) {
24250
- this.finishOp(18, 2);
24251
- } else {
24252
- this.finishOp(17, 1);
24253
- }
24254
- } else if (isIteratorStart(code2, next, this.input.charCodeAt(this.state.pos + 2))) {
24255
- this.state.pos += 2;
24256
- this.readIterator();
24257
- } else {
24258
- super.getTokenFromCode(code2);
24259
- }
24260
-
24261
-
24262
- }
24263
-
24264
- isAssignable(node, isBinding3) {
24265
- if (node.type === 'TypeCastExpression') {
24266
- return this.isAssignable(node.expression, isBinding3);
24267
- } else {
24268
- return super.isAssignable(node, isBinding3);
24269
- }
24270
- }
24271
-
24272
- toAssignable(node, isLHS = false) {
24273
- if (!isLHS && node.type === 'AssignmentExpression' && node.left.type === 'TypeCastExpression') {
24274
- node.left = this.typeCastToParameter(node.left);
24275
- }
24276
-
24277
- super.toAssignable(node, isLHS);
24278
- }
24279
-
24280
- toAssignableList(exprList, trailingCommaLoc, isLHS) {
24281
- for (let i = 0; i < exprList.length; i++) {
24282
- const expr = exprList[i];
24283
-
24284
- if (expr?.type === 'TypeCastExpression') {
24285
- exprList[i] = this.typeCastToParameter(expr);
24286
- }
24287
- }
24288
-
24289
- super.toAssignableList(exprList, trailingCommaLoc, isLHS);
24290
- }
24291
-
24292
- toReferencedList(exprList, isParenthesizedExpr) {
24293
- for (let i = 0; i < exprList.length; i++) {
24294
- const expr = exprList[i];
24295
-
24296
- if (expr && expr.type === 'TypeCastExpression' && !expr.extra?.parenthesized && (exprList.length > 1 || !isParenthesizedExpr)) {
24297
- this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
24298
- }
24299
- }
24300
-
24301
- return exprList;
24302
- }
24303
-
24304
- parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
24305
- const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
24306
-
24307
- if (canBePattern && !this.state.maybeInArrowParameters) {
24308
- this.toReferencedList(node.elements);
24309
- }
24310
-
24311
- return node;
24312
- }
24313
-
24314
- isValidLVal(type, isParenthesized, binding) {
24315
- return type === 'TypeCastExpression' || super.isValidLVal(type, isParenthesized, binding);
24316
- }
24317
-
24318
- parseClassProperty(node) {
24319
- if (this.match(14)) {
24320
- node.typeAnnotation = this.flowParseTypeAnnotation();
24321
- }
24322
-
24323
- return super.parseClassProperty(node);
24324
- }
24325
-
24326
- parseClassPrivateProperty(node) {
24327
- if (this.match(14)) {
24328
- node.typeAnnotation = this.flowParseTypeAnnotation();
24329
- }
24330
-
24331
- return super.parseClassPrivateProperty(node);
24332
- }
24333
-
24334
- isClassMethod() {
24335
- return this.match(47) || super.isClassMethod();
24336
- }
24337
-
24338
- isClassProperty() {
24339
- return this.match(14) || super.isClassProperty();
24340
- }
24341
-
24342
- isNonstaticConstructor(method) {
24343
- return !this.match(14) && super.isNonstaticConstructor(method);
24344
- }
24345
-
24346
- pushClassMethod(classBody2, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
24347
- if (method.variance) {
24348
- this.unexpected(method.variance.loc.start);
24349
- }
24350
-
24351
- delete method.variance;
24352
-
24353
- if (this.match(47)) {
24354
- method.typeParameters = this.flowParseTypeParameterDeclaration();
24355
- }
24356
-
24357
- super.pushClassMethod(classBody2, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
24358
-
24359
- if (method.params && isConstructor) {
24360
- const params = method.params;
24361
-
24362
- if (params.length > 0 && this.isThisParam(params[0])) {
24363
- this.raise(FlowErrors.ThisParamBannedInConstructor, method);
24364
- }
24365
- } else if (method.type === 'MethodDefinition' && isConstructor && method.value.params) {
24366
- const params = method.value.params;
24367
-
24368
- if (params.length > 0 && this.isThisParam(params[0])) {
24369
- this.raise(FlowErrors.ThisParamBannedInConstructor, method);
24370
- }
24371
- }
24372
- }
24373
-
24374
- pushClassPrivateMethod(classBody2, method, isGenerator, isAsync) {
24375
- if (method.variance) {
24376
- this.unexpected(method.variance.loc.start);
24377
- }
24378
-
24379
- delete method.variance;
24380
-
24381
- if (this.match(47)) {
24382
- method.typeParameters = this.flowParseTypeParameterDeclaration();
24383
- }
24384
-
24385
- super.pushClassPrivateMethod(classBody2, method, isGenerator, isAsync);
24386
- }
24387
-
24388
- parseClassSuper(node) {
24389
- super.parseClassSuper(node);
24390
-
24391
- if (node.superClass && (this.match(47) || this.match(51))) {
24392
- {
24393
- node.superTypeArguments = this.flowParseTypeParameterInstantiationInExpression();
24394
- }
24395
- }
24396
-
24397
- if (this.isContextual(113)) {
24398
- this.next();
24399
- const implemented = node.implements = [];
24400
-
24401
- do {
24402
- const node2 = this.startNode();
24403
-
24404
- node2.id = this.flowParseRestrictedIdentifier(true);
24405
-
24406
- if (this.match(47)) {
24407
- node2.typeParameters = this.flowParseTypeParameterInstantiation();
24408
- } else {
24409
- node2.typeParameters = null;
24410
- }
24411
-
24412
- implemented.push(this.finishNode(node2, 'ClassImplements'));
24413
- } while (this.eat(12))
24414
- }
24415
- }
24416
-
24417
- checkGetterSetterParams(method) {
24418
- super.checkGetterSetterParams(method);
24419
- const params = this.getObjectOrClassMethodParams(method);
24420
-
24421
- if (params.length > 0) {
24422
- const param = params[0];
24423
-
24424
- if (this.isThisParam(param) && method.kind === 'get') {
24425
- this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
24426
- } else if (this.isThisParam(param)) {
24427
- this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
24428
- }
24429
- }
24430
- }
24431
-
24432
- parsePropertyNamePrefixOperator(node) {
24433
- node.variance = this.flowParseVariance();
24434
- }
24435
-
24436
- parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern3, isAccessor2, refExpressionErrors) {
24437
- if (prop.variance) {
24438
- this.unexpected(prop.variance.loc.start);
24439
- }
24440
-
24441
- delete prop.variance;
24442
- let typeParameters;
24443
-
24444
- if (this.match(47) && !isAccessor2) {
24445
- typeParameters = this.flowParseTypeParameterDeclaration();
24446
-
24447
- if (!this.match(10))
24448
- this.unexpected();
24449
- }
24450
-
24451
- const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern3, isAccessor2, refExpressionErrors);
24452
-
24453
- if (typeParameters) {
24454
- (result.value || result).typeParameters = typeParameters;
24455
- }
24456
-
24457
- return result;
24458
- }
24459
-
24460
- parseFunctionParamType(param) {
24461
- if (this.eat(17)) {
24462
- if (param.type !== 'Identifier') {
24463
- this.raise(FlowErrors.PatternIsOptional, param);
24464
- }
24465
-
24466
- if (this.isThisParam(param)) {
24467
- this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
24468
- }
24469
-
24470
- param.optional = true;
24471
- }
24472
-
24473
- if (this.match(14)) {
24474
- param.typeAnnotation = this.flowParseTypeAnnotation();
24475
- } else if (this.isThisParam(param)) {
24476
- this.raise(FlowErrors.ThisParamAnnotationRequired, param);
24477
- }
24478
-
24479
- if (this.match(29) && this.isThisParam(param)) {
24480
- this.raise(FlowErrors.ThisParamNoDefault, param);
24481
- }
24482
-
24483
- this.resetEndLocation(param);
24484
- return param;
24485
- }
24486
-
24487
- parseMaybeDefault(startLoc, left) {
24488
- const node = super.parseMaybeDefault(startLoc, left);
24489
-
24490
- if (node.type === 'AssignmentPattern' && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
24491
- this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
24492
- }
24493
-
24494
- return node;
24495
- }
24496
-
24497
- checkImportReflection(node) {
24498
- super.checkImportReflection(node);
24499
-
24500
- if (node.module && node.importKind !== 'value') {
24501
- this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
24502
- }
24503
- }
24504
-
24505
- parseImportSpecifierLocal(node, specifier, type) {
24506
- specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
24507
- node.specifiers.push(this.finishImportSpecifier(specifier, type));
24508
- }
24509
-
24510
- isPotentialImportPhase(isExport) {
24511
- if (super.isPotentialImportPhase(isExport))
24512
- return true;
24513
-
24514
- if (this.isContextual(130)) {
24515
- if (!isExport)
24516
- return true;
24517
-
24518
- const ch = this.lookaheadCharCode();
24519
-
24520
- return ch === 123 || ch === 42;
24521
- }
24522
-
24523
- return !isExport && this.isContextual(87);
24524
- }
24525
-
24526
- applyImportPhase(node, isExport, phase, loc) {
24527
- super.applyImportPhase(node, isExport, phase, loc);
24528
-
24529
- if (isExport) {
24530
- if (!phase && this.match(65)) {
24531
- return;
24532
- }
24533
-
24534
- node.exportKind = phase === 'type' ? phase : 'value';
24535
- } else {
24536
- if (phase === 'type' && this.match(55))
24537
- this.unexpected();
24538
-
24539
- node.importKind = phase === 'type' || phase === 'typeof' ? phase : 'value';
24540
- }
24541
- }
24542
-
24543
- parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
24544
- const firstIdent = specifier.imported;
24545
- let specifierTypeKind = null;
24546
-
24547
- if (firstIdent.type === 'Identifier') {
24548
- if (firstIdent.name === 'type') {
24549
- specifierTypeKind = 'type';
24550
- } else if (firstIdent.name === 'typeof') {
24551
- specifierTypeKind = 'typeof';
24552
- }
24553
- }
24554
-
24555
- let isBinding3 = false;
24556
-
24557
- if (this.isContextual(93) && !this.isLookaheadContextual('as')) {
24558
- const as_ident = this.parseIdentifier(true);
24559
-
24560
- if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
24561
- specifier.imported = as_ident;
24562
- specifier.importKind = specifierTypeKind;
24563
- specifier.local = this.cloneIdentifier(as_ident);
24564
- } else {
24565
- specifier.imported = firstIdent;
24566
- specifier.importKind = null;
24567
- specifier.local = this.parseIdentifier();
24568
- }
24569
- } else {
24570
- if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
24571
- specifier.imported = this.parseIdentifier(true);
24572
- specifier.importKind = specifierTypeKind;
24573
- } else {
24574
- if (importedIsString) {
24575
- throw this.raise(Errors.ImportBindingIsString, specifier, {
24576
- importName: firstIdent.value,
24577
- });
24578
- }
24579
-
24580
- specifier.imported = firstIdent;
24581
- specifier.importKind = null;
24582
- }
24583
-
24584
- if (this.eatContextual(93)) {
24585
- specifier.local = this.parseIdentifier();
24586
- } else {
24587
- isBinding3 = true;
24588
- specifier.local = this.cloneIdentifier(specifier.imported);
24589
- }
24590
- }
24591
-
24592
- const specifierIsTypeImport = hasTypeImportKind(specifier);
24593
-
24594
- if (isInTypeOnlyImport && specifierIsTypeImport) {
24595
- this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
24596
- }
24597
-
24598
- if (isInTypeOnlyImport || specifierIsTypeImport) {
24599
- this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
24600
- }
24601
-
24602
- if (isBinding3 && !isInTypeOnlyImport && !specifierIsTypeImport) {
24603
- this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
24604
- }
24605
-
24606
- return this.finishImportSpecifier(specifier, 'ImportSpecifier');
24607
- }
24608
-
24609
- parseBindingAtom() {
24610
- switch(this.state.type) {
24611
- case 78:
24612
- return this.parseIdentifier(true);
24613
-
24614
- default:
24615
- return super.parseBindingAtom();
24616
- }
24617
- }
24618
-
24619
- parseFunctionParams(node, isConstructor) {
24620
- const kind = node.kind;
24621
-
24622
- if (kind !== 'get' && kind !== 'set' && this.match(47)) {
24623
- node.typeParameters = this.flowParseTypeParameterDeclaration();
24624
- }
24625
-
24626
- super.parseFunctionParams(node, isConstructor);
24627
- }
24628
-
24629
- parseVarId(decl, kind) {
24630
- super.parseVarId(decl, kind);
24631
-
24632
- if (this.match(14)) {
24633
- decl.id.typeAnnotation = this.flowParseTypeAnnotation();
24634
- this.resetEndLocation(decl.id);
24635
- }
24636
- }
24637
-
24638
- parseAsyncArrowFromCallExpression(node, call2) {
24639
- if (this.match(14)) {
24640
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
24641
-
24642
- this.state.noAnonFunctionType = true;
24643
- node.returnType = this.flowParseTypeAnnotation();
24644
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
24645
- }
24646
-
24647
- return super.parseAsyncArrowFromCallExpression(node, call2);
24648
- }
24649
-
24650
- shouldParseAsyncArrow() {
24651
- return this.match(14) || super.shouldParseAsyncArrow();
24652
- }
24653
-
24654
- parseMaybeAssign(refExpressionErrors, afterLeftParse) {
24655
- let state = null;
24656
- let jsx2;
24657
-
24658
- if (this.hasPlugin('jsx') && (this.match(143) || this.match(47))) {
24659
- state = this.state.clone();
24660
- jsx2 = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
24661
-
24662
- if (!jsx2.error)
24663
- return jsx2.node;
24664
-
24665
- const {context} = this.state;
24666
-
24667
- const currentContext = context[context.length - 1];
24668
-
24669
- if (currentContext === types.j_oTag || currentContext === types.j_expr) {
24670
- context.pop();
24671
- }
24672
- }
24673
-
24674
- if (jsx2?.error || this.match(47)) {
24675
- state = state || this.state.clone();
24676
- let typeParameters;
24677
- const arrow = this.tryParse((abort) => {
24678
- typeParameters = this.flowParseTypeParameterDeclaration();
24679
- const arrowExpression2 = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
24680
- const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
24681
- this.resetStartLocationFromNode(result, typeParameters);
24682
- return result;
24683
- });
24684
-
24685
- if (arrowExpression2.extra?.parenthesized)
24686
- abort();
24687
-
24688
- const expr = this.maybeUnwrapTypeCastExpression(arrowExpression2);
24689
-
24690
- if (expr.type !== 'ArrowFunctionExpression')
24691
- abort();
24692
-
24693
- expr.typeParameters = typeParameters;
24694
- this.resetStartLocationFromNode(expr, typeParameters);
24695
- return arrowExpression2;
24696
- }, state);
24697
-
24698
- let arrowExpression = null;
24699
-
24700
- if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === 'ArrowFunctionExpression') {
24701
- if (!arrow.error && !arrow.aborted) {
24702
- if (arrow.node.async) {
24703
- this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
24704
- }
24705
-
24706
- return arrow.node;
24707
- }
24708
-
24709
- arrowExpression = arrow.node;
24710
- }
24711
-
24712
- if (jsx2?.node) {
24713
- this.state = jsx2.failState;
24714
- return jsx2.node;
24715
- }
24716
-
24717
- if (arrowExpression) {
24718
- this.state = arrow.failState;
24719
- return arrowExpression;
24720
- }
24721
-
24722
- if (jsx2?.thrown)
24723
- throw jsx2.error;
24724
-
24725
- if (arrow.thrown)
24726
- throw arrow.error;
24727
-
24728
- throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
24729
- }
24730
-
24731
- return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
24732
- }
24733
-
24734
- parseArrow(node) {
24735
- if (this.match(14)) {
24736
- const result = this.tryParse(() => {
24737
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
24738
-
24739
- this.state.noAnonFunctionType = true;
24740
- const typeNode = this.startNode();
24741
-
24742
- [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
24743
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
24744
-
24745
- if (this.canInsertSemicolon())
24746
- this.unexpected();
24747
-
24748
- if (!this.match(19))
24749
- this.unexpected();
24750
-
24751
- return typeNode;
24752
- });
24753
-
24754
- if (result.thrown)
24755
- return null;
24756
-
24757
- if (result.error)
24758
- this.state = result.failState;
24759
-
24760
- node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, 'TypeAnnotation') : null;
24761
- }
24762
-
24763
- return super.parseArrow(node);
24764
- }
24765
-
24766
- shouldParseArrow(params) {
24767
- return this.match(14) || super.shouldParseArrow(params);
24768
- }
24769
-
24770
- setArrowFunctionParameters(node, params) {
24771
- if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
24772
- node.params = params;
24773
- } else {
24774
- super.setArrowFunctionParameters(node, params);
24775
- }
24776
- }
24777
-
24778
- checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
24779
- if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
24780
- return;
24781
- }
24782
-
24783
- for (let i = 0; i < node.params.length; i++) {
24784
- if (this.isThisParam(node.params[i]) && i > 0) {
24785
- this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
24786
- }
24787
- }
24788
-
24789
- super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
24790
- }
24791
-
24792
- parseParenAndDistinguishExpression(canBeArrow) {
24793
- return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
24794
- }
24795
-
24796
- parseSubscripts(base, startLoc, noCalls) {
24797
- if (base.type === 'Identifier' && base.name === 'async' && this.state.noArrowAt.includes(startLoc.index)) {
24798
- this.next();
24799
- const node = this.startNodeAt(startLoc);
24800
-
24801
- node.callee = base;
24802
- node.arguments = super.parseCallExpressionArguments();
24803
- base = this.finishNode(node, 'CallExpression');
24804
- } else if (base.type === 'Identifier' && base.name === 'async' && this.match(47)) {
24805
- const state = this.state.clone();
24806
- const arrow = this.tryParse((abort) => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
24807
-
24808
- if (!arrow.error && !arrow.aborted)
24809
- return arrow.node;
24810
-
24811
- const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
24812
-
24813
- if (result.node && !result.error)
24814
- return result.node;
24815
-
24816
- if (arrow.node) {
24817
- this.state = arrow.failState;
24818
- return arrow.node;
24819
- }
24820
-
24821
- if (result.node) {
24822
- this.state = result.failState;
24823
- return result.node;
24824
- }
24825
-
24826
- throw arrow.error || result.error;
24827
- }
24828
-
24829
- return super.parseSubscripts(base, startLoc, noCalls);
24830
- }
24831
-
24832
- parseSubscript(base, startLoc, noCalls, subscriptState) {
24833
- if (this.match(18) && this.isLookaheadToken_lt()) {
24834
- subscriptState.optionalChainMember = true;
24835
-
24836
- if (noCalls) {
24837
- subscriptState.stop = true;
24838
- return base;
24839
- }
24840
-
24841
- this.next();
24842
- const node = this.startNodeAt(startLoc);
24843
-
24844
- node.callee = base;
24845
- node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
24846
- this.expect(10);
24847
- node.arguments = this.parseCallExpressionArguments();
24848
- node.optional = true;
24849
- return this.finishCallExpression(node, true);
24850
- } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
24851
- const node = this.startNodeAt(startLoc);
24852
-
24853
- node.callee = base;
24854
- const result = this.tryParse(() => {
24855
- node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
24856
- this.expect(10);
24857
- node.arguments = super.parseCallExpressionArguments();
24858
-
24859
- if (subscriptState.optionalChainMember) {
24860
- node.optional = false;
24861
- }
24862
-
24863
- return this.finishCallExpression(node, subscriptState.optionalChainMember);
24864
- });
24865
-
24866
- if (result.node) {
24867
- if (result.error)
24868
- this.state = result.failState;
24869
-
24870
- return result.node;
24871
- }
24872
- }
24873
-
24874
- return super.parseSubscript(base, startLoc, noCalls, subscriptState);
24875
- }
24876
-
24877
- parseNewCallee(node) {
24878
- super.parseNewCallee(node);
24879
- let targs = null;
24880
-
24881
- if (this.shouldParseTypes() && this.match(47)) {
24882
- targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
24883
- }
24884
-
24885
- node.typeArguments = targs;
24886
- }
24887
-
24888
- parseAsyncArrowWithTypeParameters(startLoc) {
24889
- const node = this.startNodeAt(startLoc);
24890
- this.parseFunctionParams(node, false);
24891
-
24892
- if (!this.parseArrow(node))
24893
- return;
24894
-
24895
- return super.parseArrowExpression(node, void 0, true);
24896
- }
24897
-
24898
- readToken_mult_modulo(code2) {
24899
- const next = this.input.charCodeAt(this.state.pos + 1);
24900
-
24901
- if (code2 === 42 && next === 47 && this.state.hasFlowComment) {
24902
- this.state.hasFlowComment = false;
24903
- this.state.pos += 2;
24904
- this.nextToken();
24905
- return;
24906
- }
24907
-
24908
- super.readToken_mult_modulo(code2);
24909
- }
24910
-
24911
- readToken_pipe_amp(code2) {
24912
- const next = this.input.charCodeAt(this.state.pos + 1);
24913
-
24914
- if (code2 === 124 && next === 125) {
24915
- this.finishOp(9, 2);
24916
- return;
24917
- }
24918
-
24919
- super.readToken_pipe_amp(code2);
24920
- }
24921
-
24922
- parseTopLevel(file2, program3) {
24923
- const fileNode = super.parseTopLevel(file2, program3);
24924
-
24925
- if (this.state.hasFlowComment) {
24926
- this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
24927
- }
24928
-
24929
- return fileNode;
24930
- }
24931
-
24932
- skipBlockComment() {
24933
- if (this.hasPlugin('flowComments') && this.skipFlowComment()) {
24934
- if (this.state.hasFlowComment) {
24935
- throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
24936
- }
24937
-
24938
- this.hasFlowCommentCompletion();
24939
- const commentSkip = this.skipFlowComment();
24940
-
24941
- if (commentSkip) {
24942
- this.state.pos += commentSkip;
24943
- this.state.hasFlowComment = true;
24944
- }
24945
-
24946
- return;
24947
- }
24948
-
24949
- return super.skipBlockComment(this.state.hasFlowComment ? '*-/' : '*/');
24950
- }
24951
-
24952
- skipFlowComment() {
24953
- const {pos} = this.state;
24954
-
24955
- let shiftToFirstNonWhiteSpace = 2;
24956
-
24957
- while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
24958
- shiftToFirstNonWhiteSpace++;
24959
- }
24960
-
24961
- const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
24962
- const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
24963
-
24964
- if (ch2 === 58 && ch3 === 58) {
24965
- return shiftToFirstNonWhiteSpace + 2;
24966
- }
24967
-
24968
- if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === 'flow-include') {
24969
- return shiftToFirstNonWhiteSpace + 12;
24970
- }
24971
-
24972
- if (ch2 === 58 && ch3 !== 58) {
24973
- return shiftToFirstNonWhiteSpace;
24974
- }
24975
-
24976
- return false;
24977
- }
24978
-
24979
- hasFlowCommentCompletion() {
24980
- const end = this.input.indexOf('*/', this.state.pos);
24981
-
24982
- if (end === -1) {
24983
- throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
24984
- }
24985
- }
24986
-
24987
- flowEnumErrorBooleanMemberNotInitialized(loc, {enumName, memberName}) {
24988
- this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
24989
- memberName,
24990
- enumName,
24991
- });
24992
- }
24993
-
24994
- flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
24995
- return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === 'symbol' ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
24996
- }
24997
-
24998
- flowEnumErrorNumberMemberNotInitialized(loc, details) {
24999
- this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
25000
- }
25001
-
25002
- flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
25003
- this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
25004
- }
25005
-
25006
- flowEnumMemberInit() {
25007
- const startLoc = this.state.startLoc;
25008
- const endOfInit = () => this.match(12) || this.match(8);
25009
-
25010
- switch(this.state.type) {
25011
- case 135: {
25012
- const literal = this.parseNumericLiteral(this.state.value);
25013
-
25014
- if (endOfInit()) {
25015
- return {
25016
- type: 'number',
25017
- loc: literal.loc.start,
25018
- value: literal,
25019
- };
25020
- }
25021
-
25022
- return {
25023
- type: 'invalid',
25024
- loc: startLoc,
25025
- };
25026
- }
25027
-
25028
- case 134: {
25029
- const literal = this.parseStringLiteral(this.state.value);
25030
-
25031
- if (endOfInit()) {
25032
- return {
25033
- type: 'string',
25034
- loc: literal.loc.start,
25035
- value: literal,
25036
- };
25037
- }
25038
-
25039
- return {
25040
- type: 'invalid',
25041
- loc: startLoc,
25042
- };
25043
- }
25044
-
25045
- case 85:
25046
- case 86: {
25047
- const literal = this.parseBooleanLiteral(this.match(85));
25048
-
25049
- if (endOfInit()) {
25050
- return {
25051
- type: 'boolean',
25052
- loc: literal.loc.start,
25053
- value: literal,
25054
- };
25055
- }
25056
-
25057
- return {
25058
- type: 'invalid',
25059
- loc: startLoc,
25060
- };
25061
- }
25062
-
25063
- default:
25064
- return {
25065
- type: 'invalid',
25066
- loc: startLoc,
25067
- };
25068
- }
25069
- }
25070
-
25071
- flowEnumMemberRaw() {
25072
- const loc = this.state.startLoc;
25073
- const id = this.parseIdentifier(true);
25074
- const init = this.eat(29) ? this.flowEnumMemberInit() : {
25075
- type: 'none',
25076
- loc,
25077
- };
25078
-
25079
- return {
25080
- id,
25081
- init,
25082
- };
25083
- }
25084
-
25085
- flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
25086
- const {explicitType} = context;
25087
-
25088
- if (explicitType === null) {
25089
- return;
25090
- }
25091
-
25092
- if (explicitType !== expectedType) {
25093
- this.flowEnumErrorInvalidMemberInitializer(loc, context);
25094
- }
25095
- }
25096
-
25097
- flowEnumMembers({enumName, explicitType}) {
25098
- const seenNames = /* @__PURE__ */new Set();
25099
- const members = {
25100
- booleanMembers: [],
25101
- numberMembers: [],
25102
- stringMembers: [],
25103
- defaultedMembers: [],
25104
- };
25105
-
25106
- let hasUnknownMembers = false;
25107
-
25108
- while (!this.match(8)) {
25109
- if (this.eat(21)) {
25110
- hasUnknownMembers = true;
25111
- break;
25112
- }
25113
-
25114
- const memberNode = this.startNode();
25115
- const {id, init} = this.flowEnumMemberRaw();
25116
-
25117
- const memberName = id.name;
25118
-
25119
- if (memberName === '') {
25120
- continue;
25121
- }
25122
-
25123
- if (/^[a-z]/.test(memberName)) {
25124
- this.raise(FlowErrors.EnumInvalidMemberName, id, {
25125
- memberName,
25126
- suggestion: memberName[0].toUpperCase() + memberName.slice(1),
25127
- enumName,
25128
- });
25129
- }
25130
-
25131
- if (seenNames.has(memberName)) {
25132
- this.raise(FlowErrors.EnumDuplicateMemberName, id, {
25133
- memberName,
25134
- enumName,
25135
- });
25136
- }
25137
-
25138
- seenNames.add(memberName);
25139
- const context = {
25140
- enumName,
25141
- explicitType,
25142
- memberName,
25143
- };
25144
-
25145
- memberNode.id = id;
25146
- switch(init.type) {
25147
- case 'boolean': {
25148
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'boolean');
25149
- memberNode.init = init.value;
25150
- members.booleanMembers.push(this.finishNode(memberNode, 'EnumBooleanMember'));
25151
- break;
25152
- }
25153
-
25154
- case 'number': {
25155
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'number');
25156
- memberNode.init = init.value;
25157
- members.numberMembers.push(this.finishNode(memberNode, 'EnumNumberMember'));
25158
- break;
25159
- }
25160
-
25161
- case 'string': {
25162
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'string');
25163
- memberNode.init = init.value;
25164
- members.stringMembers.push(this.finishNode(memberNode, 'EnumStringMember'));
25165
- break;
25166
- }
25167
-
25168
- case 'invalid': {
25169
- throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
25170
- }
25171
-
25172
- case 'none': {
25173
- switch(explicitType) {
25174
- case 'boolean':
25175
- this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
25176
- break;
25177
-
25178
- case 'number':
25179
- this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
25180
- break;
25181
-
25182
- default:
25183
- members.defaultedMembers.push(this.finishNode(memberNode, 'EnumDefaultedMember'));
25184
- }
25185
- }
25186
- }
25187
-
25188
- if (!this.match(8)) {
25189
- this.expect(12);
25190
- }
25191
- }
25192
-
25193
- return {
25194
- members,
25195
- hasUnknownMembers,
25196
- };
25197
- }
25198
-
25199
- flowEnumStringMembers(initializedMembers, defaultedMembers, {enumName}) {
25200
- if (initializedMembers.length === 0) {
25201
- return defaultedMembers;
25202
- } else if (defaultedMembers.length === 0) {
25203
- return initializedMembers;
25204
- } else if (defaultedMembers.length > initializedMembers.length) {
25205
- for (const member of initializedMembers) {
25206
- this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
25207
- enumName,
25208
- });
25209
- }
25210
-
25211
- return defaultedMembers;
25212
- } else {
25213
- for (const member of defaultedMembers) {
25214
- this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
25215
- enumName,
25216
- });
25217
- }
25218
-
25219
- return initializedMembers;
25220
- }
25221
-
25222
- }
25223
-
25224
- flowEnumParseExplicitType({enumName}) {
25225
- if (!this.eatContextual(102))
25226
- return null;
25227
-
25228
- if (!tokenIsIdentifier(this.state.type)) {
25229
- throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
25230
- enumName,
25231
- });
25232
- }
25233
-
25234
- const {value} = this.state;
25235
-
25236
- this.next();
25237
-
25238
- if (value !== 'boolean' && value !== 'number' && value !== 'string' && value !== 'symbol') {
25239
- this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
25240
- enumName,
25241
- invalidEnumType: value,
25242
- });
25243
- }
25244
-
25245
- return value;
25246
- }
25247
-
25248
- flowEnumBody(node, id) {
25249
- const enumName = id.name;
25250
- const nameLoc = id.loc.start;
25251
- const explicitType = this.flowEnumParseExplicitType({
25252
- enumName,
25253
- });
25254
-
25255
- this.expect(5);
25256
- const {
25257
- members,
25258
- hasUnknownMembers,
25259
- } = this.flowEnumMembers({
25260
- enumName,
25261
- explicitType,
25262
- });
25263
-
25264
- node.hasUnknownMembers = hasUnknownMembers;
25265
- switch(explicitType) {
25266
- case 'boolean':
25267
- node.explicitType = true;
25268
- node.members = members.booleanMembers;
25269
- this.expect(8);
25270
- return this.finishNode(node, 'EnumBooleanBody');
25271
-
25272
- case 'number':
25273
- node.explicitType = true;
25274
- node.members = members.numberMembers;
25275
- this.expect(8);
25276
- return this.finishNode(node, 'EnumNumberBody');
25277
-
25278
- case 'string':
25279
- node.explicitType = true;
25280
- node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
25281
- enumName,
25282
- });
25283
- this.expect(8);
25284
- return this.finishNode(node, 'EnumStringBody');
25285
-
25286
- case 'symbol':
25287
- node.members = members.defaultedMembers;
25288
- this.expect(8);
25289
- return this.finishNode(node, 'EnumSymbolBody');
25290
-
25291
- default: {
25292
- const empty = () => {
25293
- node.members = [];
25294
- this.expect(8);
25295
- return this.finishNode(node, 'EnumStringBody');
25296
- };
25297
-
25298
- node.explicitType = false;
25299
- const boolsLen = members.booleanMembers.length;
25300
- const numsLen = members.numberMembers.length;
25301
- const strsLen = members.stringMembers.length;
25302
- const defaultedLen = members.defaultedMembers.length;
25303
-
25304
- if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
25305
- return empty();
25306
- } else if (!boolsLen && !numsLen) {
25307
- node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
25308
- enumName,
25309
- });
25310
- this.expect(8);
25311
- return this.finishNode(node, 'EnumStringBody');
25312
- } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
25313
- for (const member of members.defaultedMembers) {
25314
- this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
25315
- enumName,
25316
- memberName: member.id.name,
25317
- });
25318
- }
25319
-
25320
- node.members = members.booleanMembers;
25321
- this.expect(8);
25322
-
25323
- return this.finishNode(node, 'EnumBooleanBody');
25324
- } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
25325
- for (const member of members.defaultedMembers) {
25326
- this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
25327
- enumName,
25328
- memberName: member.id.name,
25329
- });
25330
- }
25331
-
25332
- node.members = members.numberMembers;
25333
- this.expect(8);
25334
-
25335
- return this.finishNode(node, 'EnumNumberBody');
25336
- } else {
25337
- this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
25338
- enumName,
25339
- });
25340
- return empty();
25341
- }
25342
-
25343
-
25344
- }
25345
- }
25346
- }
25347
-
25348
- flowParseEnumDeclaration(node) {
25349
- const id = this.parseIdentifier();
25350
-
25351
- node.id = id;
25352
- node.body = this.flowEnumBody(this.startNode(), id);
25353
- return this.finishNode(node, 'EnumDeclaration');
25354
- }
25355
-
25356
- jsxParseOpeningElementAfterName(node) {
25357
- if (this.shouldParseTypes()) {
25358
- if (this.match(47) || this.match(51)) {
25359
- node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
25360
- }
25361
- }
25362
-
25363
- return super.jsxParseOpeningElementAfterName(node);
25364
- }
25365
-
25366
- isLookaheadToken_lt() {
25367
- const next = this.nextTokenStart();
25368
-
25369
- if (this.input.charCodeAt(next) === 60) {
25370
- const afterNext = this.input.charCodeAt(next + 1);
25371
- return afterNext !== 60 && afterNext !== 61;
25372
- }
25373
-
25374
- return false;
25375
- }
25376
-
25377
- reScan_lt_gt() {
25378
- const {type} = this.state;
25379
-
25380
- if (type === 47) {
25381
- this.state.pos -= 1;
25382
- this.readToken_lt();
25383
- } else if (type === 48) {
25384
- this.state.pos -= 1;
25385
- this.readToken_gt();
25386
- }
25387
- }
25388
-
25389
- reScan_lt() {
25390
- const {type} = this.state;
25391
-
25392
- if (type === 51) {
25393
- this.state.pos -= 2;
25394
- this.finishOp(47, 1);
25395
- return 47;
25396
- }
25397
-
25398
- return type;
25399
- }
25400
-
25401
- maybeUnwrapTypeCastExpression(node) {
25402
- return node.type === 'TypeCastExpression' ? node.expression : node;
25403
- }
25404
- };
25405
-
25406
21525
  var entities = {
25407
21526
  __proto__: null,
25408
21527
  quot: '"',
@@ -33696,7 +29815,6 @@ function validatePlugins(pluginsMap) {
33696
29815
  var mixinPlugins = {
33697
29816
  estree,
33698
29817
  jsx,
33699
- flow,
33700
29818
  typescript,
33701
29819
  v8intrinsic,
33702
29820
  placeholders,