@putout/babel 4.1.1 → 4.3.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
@@ -1483,16 +1483,14 @@ typeof window !== 'undefined'
1483
1483
  // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
1484
1484
  typeof navigator !== 'undefined'
1485
1485
  && navigator.userAgent
1486
- && (m = navigator
1487
- .userAgent
1486
+ && (m = navigator.userAgent
1488
1487
  .toLowerCase()
1489
1488
  .match(/firefox\/(\d+)/))
1490
1489
  && parseInt(m[1], 10) >= 31
1491
1490
  || // Double check webkit in userAgent just in case we are in a worker
1492
1491
  typeof navigator !== 'undefined'
1493
1492
  && navigator.userAgent
1494
- && navigator
1495
- .userAgent
1493
+ && navigator.userAgent
1496
1494
  .toLowerCase()
1497
1495
  .match(/applewebkit\/(\d+)/);
1498
1496
  }
@@ -7962,7 +7960,6 @@ function isLVal(node, opts) {
7962
7960
  case 'MemberExpression':
7963
7961
  case 'ArrayPattern':
7964
7962
  case 'ObjectPattern':
7965
- case 'OptionalMemberExpression':
7966
7963
  case 'TSAsExpression':
7967
7964
  case 'TSSatisfiesExpression':
7968
7965
  case 'TSTypeAssertion':
@@ -8262,196 +8259,15 @@ function isPrivate(node, opts) {
8262
8259
  return opts == null || shallowEqual(node, opts);
8263
8260
  }
8264
8261
 
8265
- function isFlow(node, opts) {
8266
- if (!node)
8267
- return false;
8268
-
8269
- switch(node.type) {
8270
- case 'AnyTypeAnnotation':
8271
- case 'ArrayTypeAnnotation':
8272
- case 'BooleanTypeAnnotation':
8273
- case 'BooleanLiteralTypeAnnotation':
8274
- case 'NullLiteralTypeAnnotation':
8275
- case 'ClassImplements':
8276
- case 'DeclareClass':
8277
- case 'DeclareFunction':
8278
- case 'DeclareInterface':
8279
- case 'DeclareModule':
8280
- case 'DeclareModuleExports':
8281
- case 'DeclareTypeAlias':
8282
- case 'DeclareOpaqueType':
8283
- case 'DeclareVariable':
8284
- case 'DeclareExportDeclaration':
8285
- case 'DeclareExportAllDeclaration':
8286
- case 'DeclaredPredicate':
8287
- case 'ExistsTypeAnnotation':
8288
- case 'FunctionTypeAnnotation':
8289
- case 'FunctionTypeParam':
8290
- case 'GenericTypeAnnotation':
8291
- case 'InferredPredicate':
8292
- case 'InterfaceExtends':
8293
- case 'InterfaceDeclaration':
8294
- case 'InterfaceTypeAnnotation':
8295
- case 'IntersectionTypeAnnotation':
8296
- case 'MixedTypeAnnotation':
8297
- case 'EmptyTypeAnnotation':
8298
- case 'NullableTypeAnnotation':
8299
- case 'NumberLiteralTypeAnnotation':
8300
- case 'NumberTypeAnnotation':
8301
- case 'ObjectTypeAnnotation':
8302
- case 'ObjectTypeInternalSlot':
8303
- case 'ObjectTypeCallProperty':
8304
- case 'ObjectTypeIndexer':
8305
- case 'ObjectTypeProperty':
8306
- case 'ObjectTypeSpreadProperty':
8307
- case 'OpaqueType':
8308
- case 'QualifiedTypeIdentifier':
8309
- case 'StringLiteralTypeAnnotation':
8310
- case 'StringTypeAnnotation':
8311
- case 'SymbolTypeAnnotation':
8312
- case 'ThisTypeAnnotation':
8313
- case 'TupleTypeAnnotation':
8314
- case 'TypeofTypeAnnotation':
8315
- case 'TypeAlias':
8316
- case 'TypeAnnotation':
8317
- case 'TypeCastExpression':
8318
- case 'TypeParameter':
8319
- case 'TypeParameterDeclaration':
8320
- case 'TypeParameterInstantiation':
8321
- case 'UnionTypeAnnotation':
8322
- case 'Variance':
8323
- case 'VoidTypeAnnotation':
8324
- case 'EnumDeclaration':
8325
- case 'EnumBooleanBody':
8326
- case 'EnumNumberBody':
8327
- case 'EnumStringBody':
8328
- case 'EnumSymbolBody':
8329
- case 'EnumBooleanMember':
8330
- case 'EnumNumberMember':
8331
- case 'EnumStringMember':
8332
- case 'EnumDefaultedMember':
8333
- case 'IndexedAccessType':
8334
- case 'OptionalIndexedAccessType':
8335
- break;
8336
-
8337
- default:
8338
- return false;
8339
- }
8340
-
8341
-
8342
- return opts == null || shallowEqual(node, opts);
8343
- }
8262
+ function isFlow() {}
8344
8263
 
8345
- function isFlowType(node, opts) {
8346
- if (!node)
8347
- return false;
8348
-
8349
- switch(node.type) {
8350
- case 'AnyTypeAnnotation':
8351
- case 'ArrayTypeAnnotation':
8352
- case 'BooleanTypeAnnotation':
8353
- case 'BooleanLiteralTypeAnnotation':
8354
- case 'NullLiteralTypeAnnotation':
8355
- case 'ExistsTypeAnnotation':
8356
- case 'FunctionTypeAnnotation':
8357
- case 'GenericTypeAnnotation':
8358
- case 'InterfaceTypeAnnotation':
8359
- case 'IntersectionTypeAnnotation':
8360
- case 'MixedTypeAnnotation':
8361
- case 'EmptyTypeAnnotation':
8362
- case 'NullableTypeAnnotation':
8363
- case 'NumberLiteralTypeAnnotation':
8364
- case 'NumberTypeAnnotation':
8365
- case 'ObjectTypeAnnotation':
8366
- case 'StringLiteralTypeAnnotation':
8367
- case 'StringTypeAnnotation':
8368
- case 'SymbolTypeAnnotation':
8369
- case 'ThisTypeAnnotation':
8370
- case 'TupleTypeAnnotation':
8371
- case 'TypeofTypeAnnotation':
8372
- case 'UnionTypeAnnotation':
8373
- case 'VoidTypeAnnotation':
8374
- case 'IndexedAccessType':
8375
- case 'OptionalIndexedAccessType':
8376
- break;
8377
-
8378
- default:
8379
- return false;
8380
- }
8381
-
8382
-
8383
- return opts == null || shallowEqual(node, opts);
8384
- }
8264
+ function isFlowType() {}
8385
8265
 
8386
- function isFlowBaseAnnotation(node, opts) {
8387
- if (!node)
8388
- return false;
8389
-
8390
- switch(node.type) {
8391
- case 'AnyTypeAnnotation':
8392
- case 'BooleanTypeAnnotation':
8393
- case 'NullLiteralTypeAnnotation':
8394
- case 'MixedTypeAnnotation':
8395
- case 'EmptyTypeAnnotation':
8396
- case 'NumberTypeAnnotation':
8397
- case 'StringTypeAnnotation':
8398
- case 'SymbolTypeAnnotation':
8399
- case 'ThisTypeAnnotation':
8400
- case 'VoidTypeAnnotation':
8401
- break;
8402
-
8403
- default:
8404
- return false;
8405
- }
8406
-
8407
-
8408
- return opts == null || shallowEqual(node, opts);
8409
- }
8266
+ function isFlowBaseAnnotation() {}
8410
8267
 
8411
- function isFlowDeclaration(node, opts) {
8412
- if (!node)
8413
- return false;
8414
-
8415
- switch(node.type) {
8416
- case 'DeclareClass':
8417
- case 'DeclareFunction':
8418
- case 'DeclareInterface':
8419
- case 'DeclareModule':
8420
- case 'DeclareModuleExports':
8421
- case 'DeclareTypeAlias':
8422
- case 'DeclareOpaqueType':
8423
- case 'DeclareVariable':
8424
- case 'DeclareExportDeclaration':
8425
- case 'DeclareExportAllDeclaration':
8426
- case 'InterfaceDeclaration':
8427
- case 'OpaqueType':
8428
- case 'TypeAlias':
8429
- break;
8430
-
8431
- default:
8432
- return false;
8433
- }
8434
-
8435
-
8436
- return opts == null || shallowEqual(node, opts);
8437
- }
8268
+ function isFlowDeclaration() {}
8438
8269
 
8439
- function isFlowPredicate(node, opts) {
8440
- if (!node)
8441
- return false;
8442
-
8443
- switch(node.type) {
8444
- case 'DeclaredPredicate':
8445
- case 'InferredPredicate':
8446
- break;
8447
-
8448
- default:
8449
- return false;
8450
- }
8451
-
8452
-
8453
- return opts == null || shallowEqual(node, opts);
8454
- }
8270
+ function isFlowPredicate() {}
8455
8271
 
8456
8272
  function isEnumBody(node, opts) {
8457
8273
  if (!node)
@@ -9409,7 +9225,7 @@ defineType$4('ArrayExpression', {
9409
9225
  defineType$4('AssignmentExpression', {
9410
9226
  fields: {
9411
9227
  operator: {
9412
- validate: Object.assign(function() {
9228
+ validate: Object.assign((function() {
9413
9229
  const identifier4 = assertOneOf(...ASSIGNMENT_OPERATORS);
9414
9230
  const pattern = assertOneOf('=');
9415
9231
 
@@ -9417,7 +9233,7 @@ defineType$4('AssignmentExpression', {
9417
9233
  const validator = is('Pattern', node.left) ? pattern : identifier4;
9418
9234
  validator(node, key, val);
9419
9235
  };
9420
- }(), {
9236
+ })(), {
9421
9237
  oneOf: ASSIGNMENT_OPERATORS,
9422
9238
  }),
9423
9239
  },
@@ -9447,7 +9263,7 @@ defineType$4('BinaryExpression', {
9447
9263
  validate: assertOneOf(...BINARY_OPERATORS),
9448
9264
  },
9449
9265
  left: {
9450
- validate: function() {
9266
+ validate: (function() {
9451
9267
  const expression2 = assertNodeType('Expression');
9452
9268
  const inOp = assertNodeType('Expression', 'PrivateName');
9453
9269
  const validator = Object.assign(function(node, key, val) {
@@ -9458,7 +9274,7 @@ defineType$4('BinaryExpression', {
9458
9274
  });
9459
9275
 
9460
9276
  return validator;
9461
- }(),
9277
+ })(),
9462
9278
  },
9463
9279
  right: {
9464
9280
  validate: assertNodeType('Expression'),
@@ -9768,7 +9584,7 @@ defineType$4('FunctionDeclaration', {
9768
9584
  'Pureish',
9769
9585
  'Declaration',
9770
9586
  ],
9771
- validate: function() {
9587
+ validate: (function() {
9772
9588
  const identifier4 = assertNodeType('Identifier');
9773
9589
 
9774
9590
  return function(parent, key, node) {
@@ -9776,7 +9592,7 @@ defineType$4('FunctionDeclaration', {
9776
9592
  identifier4(node, 'id', node.id);
9777
9593
  }
9778
9594
  };
9779
- }(),
9595
+ })(),
9780
9596
  });
9781
9597
  defineType$4('FunctionExpression', {
9782
9598
  inherits: 'FunctionDeclaration',
@@ -9991,7 +9807,7 @@ defineType$4('RegExpLiteral', {
9991
9807
  },
9992
9808
  flags: {
9993
9809
  validate: chain(assertValueType('string'), Object.assign(function(node, key, val) {
9994
- const invalid = /[^gimsuy]/.exec(val);
9810
+ const invalid = /[^dgimsuvy]/.exec(val);
9995
9811
 
9996
9812
  if (invalid) {
9997
9813
  throw new TypeError(`"${invalid[0]}" is not a valid RegExp flag`);
@@ -10041,7 +9857,7 @@ defineType$4('MemberExpression', {
10041
9857
  validate: assertNodeType('Expression', 'Super'),
10042
9858
  },
10043
9859
  property: {
10044
- validate: function() {
9860
+ validate: (function() {
10045
9861
  const normal = assertNodeType('Identifier', 'PrivateName');
10046
9862
  const computed = assertNodeType('Expression');
10047
9863
  const validator = function(node, key, val) {
@@ -10055,7 +9871,7 @@ defineType$4('MemberExpression', {
10055
9871
  'PrivateName',
10056
9872
  ];
10057
9873
  return validator;
10058
- }(),
9874
+ })(),
10059
9875
  },
10060
9876
  computed: {
10061
9877
  default: false,
@@ -10128,7 +9944,7 @@ defineType$4('ObjectMethod', {
10128
9944
  default: false,
10129
9945
  },
10130
9946
  key: {
10131
- validate: function() {
9947
+ validate: (function() {
10132
9948
  const normal = assertNodeType('Identifier', 'StringLiteral', 'NumericLiteral', 'BigIntLiteral');
10133
9949
  const computed = assertNodeType('Expression');
10134
9950
  const validator = function(node, key, val) {
@@ -10144,7 +9960,7 @@ defineType$4('ObjectMethod', {
10144
9960
  'BigIntLiteral',
10145
9961
  ];
10146
9962
  return validator;
10147
- }(),
9963
+ })(),
10148
9964
  },
10149
9965
  decorators: {
10150
9966
  validate: arrayOfType('Decorator'),
@@ -10177,7 +9993,7 @@ defineType$4('ObjectProperty', {
10177
9993
  default: false,
10178
9994
  },
10179
9995
  key: {
10180
- validate: function() {
9996
+ validate: (function() {
10181
9997
  const normal = assertNodeType('Identifier', 'StringLiteral', 'NumericLiteral', 'BigIntLiteral', 'PrivateName');
10182
9998
  const computed = assertNodeType('Expression');
10183
9999
  const validator = Object.assign(function(node, key, val) {
@@ -10195,7 +10011,7 @@ defineType$4('ObjectProperty', {
10195
10011
  });
10196
10012
 
10197
10013
  return validator;
10198
- }(),
10014
+ })(),
10199
10015
  },
10200
10016
  value: {
10201
10017
  validate: assertNodeType('Expression', 'PatternLike'),
@@ -10232,7 +10048,7 @@ defineType$4('ObjectProperty', {
10232
10048
  'Property',
10233
10049
  'ObjectMember',
10234
10050
  ],
10235
- validate: function() {
10051
+ validate: (function() {
10236
10052
  const pattern = assertNodeType('Identifier', 'Pattern', 'TSAsExpression', 'TSSatisfiesExpression', 'TSNonNullExpression', 'TSTypeAssertion');
10237
10053
  const expression2 = assertNodeType('Expression');
10238
10054
 
@@ -10240,7 +10056,7 @@ defineType$4('ObjectProperty', {
10240
10056
  const validator = is('ObjectPattern', parent) ? pattern : expression2;
10241
10057
  validator(node, 'value', node.value);
10242
10058
  };
10243
- }(),
10059
+ })(),
10244
10060
  });
10245
10061
  defineType$4('RestElement', {
10246
10062
  visitor: ['argument', 'typeAnnotation'],
@@ -10679,7 +10495,7 @@ defineType$4('ClassDeclaration', {
10679
10495
  optional: true,
10680
10496
  },
10681
10497
  },
10682
- validate: function() {
10498
+ validate: (function() {
10683
10499
  const identifier4 = assertNodeType('Identifier');
10684
10500
 
10685
10501
  return function(parent, key, node) {
@@ -10687,7 +10503,7 @@ defineType$4('ClassDeclaration', {
10687
10503
  identifier4(node, 'id', node.id);
10688
10504
  }
10689
10505
  };
10690
- }(),
10506
+ })(),
10691
10507
  });
10692
10508
  var importAttributes = {
10693
10509
  attributes: {
@@ -10770,7 +10586,7 @@ defineType$4('ExportNamedDeclaration', {
10770
10586
  }, importAttributes, {
10771
10587
  specifiers: {
10772
10588
  default: [],
10773
- validate: arrayOf(function() {
10589
+ validate: arrayOf((function() {
10774
10590
  const sourced = assertNodeType('ExportSpecifier', 'ExportDefaultSpecifier', 'ExportNamespaceSpecifier');
10775
10591
  const sourceless = assertNodeType('ExportSpecifier');
10776
10592
 
@@ -10784,7 +10600,7 @@ defineType$4('ExportNamedDeclaration', {
10784
10600
  'ExportNamespaceSpecifier',
10785
10601
  ],
10786
10602
  });
10787
- }()),
10603
+ })()),
10788
10604
  },
10789
10605
  source: {
10790
10606
  validate: assertNodeType('StringLiteral'),
@@ -10831,7 +10647,7 @@ defineType$4('ForOfStatement', {
10831
10647
  ],
10832
10648
  fields: {
10833
10649
  left: {
10834
- validate: function() {
10650
+ validate: (function() {
10835
10651
  const declaration = assertNodeType('VariableDeclaration');
10836
10652
  const lval = assertNodeType('Identifier', 'MemberExpression', 'ArrayPattern', 'ObjectPattern', 'TSAsExpression', 'TSSatisfiesExpression', 'TSTypeAssertion', 'TSNonNullExpression');
10837
10653
 
@@ -10854,7 +10670,7 @@ defineType$4('ForOfStatement', {
10854
10670
  'TSNonNullExpression',
10855
10671
  ],
10856
10672
  });
10857
- }(),
10673
+ })(),
10858
10674
  },
10859
10675
  right: {
10860
10676
  validate: assertNodeType('Expression'),
@@ -11007,7 +10823,7 @@ var classMethodOrPropertyCommon = () => ({
11007
10823
  optional: true,
11008
10824
  },
11009
10825
  key: {
11010
- validate: chain(function() {
10826
+ validate: chain((function() {
11011
10827
  const normal = assertNodeType('Identifier', 'StringLiteral', 'NumericLiteral', 'BigIntLiteral');
11012
10828
  const computed = assertNodeType('Expression');
11013
10829
 
@@ -11015,7 +10831,7 @@ var classMethodOrPropertyCommon = () => ({
11015
10831
  const validator = node.computed ? computed : normal;
11016
10832
  validator(node, key, val);
11017
10833
  };
11018
- }(), assertNodeType('Identifier', 'StringLiteral', 'NumericLiteral', 'BigIntLiteral', 'Expression')),
10834
+ })(), assertNodeType('Identifier', 'StringLiteral', 'NumericLiteral', 'BigIntLiteral', 'Expression')),
11019
10835
  },
11020
10836
  });
11021
10837
 
@@ -11241,13 +11057,13 @@ defineType$4('OptionalMemberExpression', {
11241
11057
  'optional',
11242
11058
  ],
11243
11059
  visitor: ['object', 'property'],
11244
- aliases: ['Expression', 'LVal'],
11060
+ aliases: ['Expression'],
11245
11061
  fields: {
11246
11062
  object: {
11247
11063
  validate: assertNodeType('Expression'),
11248
11064
  },
11249
11065
  property: {
11250
- validate: function() {
11066
+ validate: (function() {
11251
11067
  const normal = assertNodeType('Identifier');
11252
11068
  const computed = assertNodeType('Expression');
11253
11069
  const validator = Object.assign(function(node, key, val) {
@@ -11258,7 +11074,7 @@ defineType$4('OptionalMemberExpression', {
11258
11074
  });
11259
11075
 
11260
11076
  return validator;
11261
- }(),
11077
+ })(),
11262
11078
  },
11263
11079
  computed: {
11264
11080
  default: false,
@@ -11360,7 +11176,7 @@ defineType$4('ClassAccessorProperty', {
11360
11176
  aliases: ['Property', 'Accessor'],
11361
11177
  fields: Object.assign({}, classMethodOrPropertyCommon(), {
11362
11178
  key: {
11363
- validate: chain(function() {
11179
+ validate: chain((function() {
11364
11180
  const normal = assertNodeType('Identifier', 'StringLiteral', 'NumericLiteral', 'BigIntLiteral', 'PrivateName');
11365
11181
  const computed = assertNodeType('Expression');
11366
11182
 
@@ -11368,7 +11184,7 @@ defineType$4('ClassAccessorProperty', {
11368
11184
  const validator = node.computed ? computed : normal;
11369
11185
  validator(node, key, val);
11370
11186
  };
11371
- }(), assertNodeType('Identifier', 'StringLiteral', 'NumericLiteral', 'BigIntLiteral', 'Expression', 'PrivateName')),
11187
+ })(), assertNodeType('Identifier', 'StringLiteral', 'NumericLiteral', 'BigIntLiteral', 'Expression', 'PrivateName')),
11372
11188
  },
11373
11189
  value: {
11374
11190
  validate: assertNodeType('Expression'),
@@ -12774,6 +12590,7 @@ defineType('TSTypeOperator', {
12774
12590
  fields: {
12775
12591
  operator: {
12776
12592
  validate: assertOneOf('keyof', 'readonly', 'unique'),
12593
+ default: void 0,
12777
12594
  },
12778
12595
  typeAnnotation: validateType('TSType'),
12779
12596
  },
@@ -12830,7 +12647,7 @@ defineType('TSLiteralType', {
12830
12647
  visitor: ['literal'],
12831
12648
  fields: {
12832
12649
  literal: {
12833
- validate: function() {
12650
+ validate: (function() {
12834
12651
  const unaryExpression3 = assertNodeType('NumericLiteral', 'BigIntLiteral');
12835
12652
  const unaryOperator = assertOneOf('-');
12836
12653
  const literal = assertNodeType('NumericLiteral', 'StringLiteral', 'BooleanLiteral', 'BigIntLiteral', 'TemplateLiteral');
@@ -12853,7 +12670,7 @@ defineType('TSLiteralType', {
12853
12670
  'UnaryExpression',
12854
12671
  ];
12855
12672
  return validator;
12856
- }(),
12673
+ })(),
12857
12674
  },
12858
12675
  },
12859
12676
  });
@@ -19137,8 +18954,7 @@ function getNameFromLiteralId(id) {
19137
18954
  }
19138
18955
 
19139
18956
  if (isTemplateLiteral(id)) {
19140
- return id
19141
- .quasis
18957
+ return id.quasis
19142
18958
  .map((quasi) => quasi.value.raw)
19143
18959
  .join('');
19144
18960
  }
@@ -20337,7 +20153,6 @@ var estree = (superClass) => class ESTreeParserMixin extends superClass {
20337
20153
  this.castNodeTo(node, 'ImportExpression');
20338
20154
  node.source = node.arguments[0];
20339
20155
  node.options = node.arguments[1] ?? null;
20340
- node.attributes = node.arguments[1] ?? null;
20341
20156
  delete node.arguments;
20342
20157
  delete node.callee;
20343
20158
  } else if (node.type === 'OptionalCallExpression') {
@@ -22150,3262 +21965,323 @@ var reservedWordLikeSet = /* @__PURE__ */new Set([
22150
21965
  'import',
22151
21966
  'null',
22152
21967
  'true',
22153
- 'false',
22154
- 'in',
22155
- 'instanceof',
22156
- 'typeof',
22157
- 'void',
22158
- 'delete',
22159
- 'implements',
22160
- 'interface',
22161
- 'let',
22162
- 'package',
22163
- 'private',
22164
- 'protected',
22165
- 'public',
22166
- 'static',
22167
- 'yield',
22168
- 'eval',
22169
- 'arguments',
22170
- 'enum',
22171
- 'await',
22172
- ]);
22173
-
22174
- function canBeReservedWord(word) {
22175
- return reservedWordLikeSet.has(word);
22176
- }
22177
-
22178
- var Scope = class {
22179
- constructor(flags) {
22180
- __publicField(this, 'flags', 0);
22181
- __publicField(this, 'names', /* @__PURE__ */new Map());
22182
- __publicField(this, 'firstLexicalName', '');
22183
- this.flags = flags;
22184
- }
22185
- };
22186
-
22187
- var ScopeHandler = class {
22188
- constructor(parser, inModule) {
22189
- __publicField(this, 'parser');
22190
- __publicField(this, 'scopeStack', []);
22191
- __publicField(this, 'inModule');
22192
- __publicField(this, 'undefinedExports', /* @__PURE__ */new Map());
22193
- this.parser = parser;
22194
- this.inModule = inModule;
22195
- }
22196
-
22197
- get inTopLevel() {
22198
- return (this.currentScope().flags & 1) > 0;
22199
- }
22200
-
22201
- get inFunction() {
22202
- return (this.currentVarScopeFlags() & 2) > 0;
22203
- }
22204
-
22205
- get allowSuper() {
22206
- return (this.currentThisScopeFlags() & 16) > 0;
22207
- }
22208
-
22209
- get allowDirectSuper() {
22210
- return (this.currentThisScopeFlags() & 32) > 0;
22211
- }
22212
-
22213
- get allowNewTarget() {
22214
- return (this.currentThisScopeFlags() & 512) > 0;
22215
- }
22216
-
22217
- get inClass() {
22218
- return (this.currentThisScopeFlags() & 64) > 0;
22219
- }
22220
-
22221
- get inClassAndNotInNonArrowFunction() {
22222
- const flags = this.currentThisScopeFlags();
22223
- return (flags & 64) > 0 && (flags & 2) === 0;
22224
- }
22225
-
22226
- get inStaticBlock() {
22227
- for (let i = this.scopeStack.length - 1;; i--) {
22228
- const {flags} = this.scopeStack[i];
22229
-
22230
- if (flags & 128) {
22231
- return true;
22232
- }
22233
-
22234
- if (flags & (1667 | 64)) {
22235
- return false;
22236
- }
22237
- }
22238
- }
22239
-
22240
- get inNonArrowFunction() {
22241
- return (this.currentThisScopeFlags() & 2) > 0;
22242
- }
22243
-
22244
- get inBareCaseStatement() {
22245
- return (this.currentScope().flags & 256) > 0;
22246
- }
22247
-
22248
- get treatFunctionsAsVar() {
22249
- return this.treatFunctionsAsVarInScope(this.currentScope());
22250
- }
22251
-
22252
- createScope(flags) {
22253
- return new Scope(flags);
22254
- }
22255
-
22256
- enter(flags) {
22257
- this.scopeStack.push(this.createScope(flags));
22258
- }
22259
-
22260
- exit() {
22261
- const scope2 = this.scopeStack.pop();
22262
- return scope2.flags;
22263
- }
22264
-
22265
- treatFunctionsAsVarInScope(scope2) {
22266
- return !!(scope2.flags & (2 | 128) || !this.parser.inModule && scope2.flags & 1);
22267
- }
22268
-
22269
- declareName(name, bindingType, loc) {
22270
- let scope2 = this.currentScope();
22271
-
22272
- if (bindingType & 8 || bindingType & 16) {
22273
- this.checkRedeclarationInScope(scope2, name, bindingType, loc);
22274
- let type = scope2.names.get(name) || 0;
22275
-
22276
- if (bindingType & 16) {
22277
- type = type | 4;
22278
- } else {
22279
- if (!scope2.firstLexicalName) {
22280
- scope2.firstLexicalName = name;
22281
- }
22282
-
22283
- type = type | 2;
22284
- }
22285
-
22286
- scope2.names.set(name, type);
22287
-
22288
- if (bindingType & 8) {
22289
- this.maybeExportDefined(scope2, name);
22290
- }
22291
- } else if (bindingType & 4) {
22292
- for (let i = this.scopeStack.length - 1; i >= 0; --i) {
22293
- scope2 = this.scopeStack[i];
22294
- this.checkRedeclarationInScope(scope2, name, bindingType, loc);
22295
- scope2.names.set(name, (scope2.names.get(name) || 0) | 1);
22296
- this.maybeExportDefined(scope2, name);
22297
-
22298
- if (scope2.flags & 1667)
22299
- break;
22300
- }
22301
- }
22302
-
22303
- if (this.parser.inModule && scope2.flags & 1) {
22304
- this.undefinedExports.delete(name);
22305
- }
22306
- }
22307
-
22308
- maybeExportDefined(scope2, name) {
22309
- if (this.parser.inModule && scope2.flags & 1) {
22310
- this.undefinedExports.delete(name);
22311
- }
22312
- }
22313
-
22314
- checkRedeclarationInScope(scope2, name, bindingType, loc) {
22315
- if (this.isRedeclaredInScope(scope2, name, bindingType)) {
22316
- this.parser.raise(Errors.VarRedeclaration, loc, {
22317
- identifierName: name,
22318
- });
22319
- }
22320
- }
22321
-
22322
- isRedeclaredInScope(scope2, name, bindingType) {
22323
- if (!(bindingType & 1))
22324
- return false;
22325
-
22326
- if (bindingType & 8) {
22327
- return scope2.names.has(name);
22328
- }
22329
-
22330
- const type = scope2.names.get(name);
22331
-
22332
- if (bindingType & 16) {
22333
- return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope2) && (type & 1) > 0;
22334
- }
22335
-
22336
- return (type & 2) > 0 && !(scope2.flags & 8 && scope2.firstLexicalName === name)
22337
- || !this.treatFunctionsAsVarInScope(scope2) && (type & 4) > 0;
22338
- }
22339
-
22340
- checkLocalExport(id) {
22341
- const {name} = id;
22342
-
22343
- const topLevelScope = this.scopeStack[0];
22344
-
22345
- if (!topLevelScope.names.has(name)) {
22346
- this.undefinedExports.set(name, id.loc.start);
22347
- }
22348
- }
22349
-
22350
- currentScope() {
22351
- return this.scopeStack[this.scopeStack.length - 1];
22352
- }
22353
-
22354
- currentVarScopeFlags() {
22355
- for (let i = this.scopeStack.length - 1;; i--) {
22356
- const {flags} = this.scopeStack[i];
22357
-
22358
- if (flags & 1667) {
22359
- return flags;
22360
- }
22361
- }
22362
- }
22363
-
22364
- currentThisScopeFlags() {
22365
- for (let i = this.scopeStack.length - 1;; i--) {
22366
- const {flags} = this.scopeStack[i];
22367
-
22368
- if (flags & (1667 | 64) && !(flags & 4)) {
22369
- return flags;
22370
- }
22371
- }
22372
- }
22373
- };
22374
-
22375
- var FlowScope = class extends Scope {
22376
- constructor() {
22377
- super(...arguments);
22378
- __publicField(this, 'declareFunctions', /* @__PURE__ */new Set());
22379
- }
22380
- };
22381
-
22382
- var FlowScopeHandler = class extends ScopeHandler {
22383
- createScope(flags) {
22384
- return new FlowScope(flags);
22385
- }
22386
-
22387
- declareName(name, bindingType, loc) {
22388
- const scope2 = this.currentScope();
22389
-
22390
- if (bindingType & 2048) {
22391
- this.checkRedeclarationInScope(scope2, name, bindingType, loc);
22392
- this.maybeExportDefined(scope2, name);
22393
- scope2.declareFunctions.add(name);
22394
- return;
22395
- }
22396
-
22397
- super.declareName(name, bindingType, loc);
22398
- }
22399
-
22400
- isRedeclaredInScope(scope2, name, bindingType) {
22401
- if (super.isRedeclaredInScope(scope2, name, bindingType))
22402
- return true;
22403
-
22404
- if (bindingType & 2048 && !scope2.declareFunctions.has(name)) {
22405
- const type = scope2.names.get(name);
22406
- return (type & 4) > 0 || (type & 2) > 0;
22407
- }
22408
-
22409
- return false;
22410
- }
22411
-
22412
- checkLocalExport(id) {
22413
- if (!this.scopeStack[0].declareFunctions.has(id.name)) {
22414
- super.checkLocalExport(id);
22415
- }
22416
- }
22417
- };
22418
-
22419
- var reservedTypes = /* @__PURE__ */new Set([
22420
- '_',
22421
- 'any',
22422
- 'bool',
22423
- 'boolean',
22424
- 'empty',
22425
- 'extends',
22426
- 'false',
22427
- 'interface',
22428
- 'mixed',
22429
- 'null',
22430
- 'number',
22431
- 'static',
22432
- 'string',
22433
- 'true',
22434
- 'typeof',
22435
- 'void',
22436
- ]);
22437
-
22438
- var FlowErrors = ParseErrorEnum`flow`({
22439
- AmbiguousConditionalArrow: 'Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.',
22440
- 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.',
22441
- AssignReservedType: ({reservedType}) => `Cannot overwrite reserved type ${reservedType}.`,
22442
- DeclareClassElement: 'The `declare` modifier can only appear on class fields.',
22443
- DeclareClassFieldInitializer: 'Initializers are not allowed in fields with the `declare` modifier.',
22444
- DuplicateDeclareModuleExports: 'Duplicate `declare module.exports` statement.',
22445
- EnumBooleanMemberNotInitialized: ({memberName, enumName}) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
22446
- EnumDuplicateMemberName: ({memberName, enumName}) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
22447
- 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.`,
22448
- EnumInvalidExplicitType: ({invalidEnumType, enumName}) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
22449
- EnumInvalidExplicitTypeUnknownSupplied: ({enumName}) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
22450
- EnumInvalidMemberInitializerPrimaryType: ({enumName, memberName, explicitType}) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
22451
- EnumInvalidMemberInitializerSymbolType: ({enumName, memberName}) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
22452
- EnumInvalidMemberInitializerUnknownType: ({enumName, memberName}) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
22453
- EnumInvalidMemberName: ({enumName, memberName, suggestion}) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
22454
- EnumNumberMemberNotInitialized: ({enumName, memberName}) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
22455
- EnumStringMemberInconsistentlyInitialized: ({enumName}) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
22456
- GetterMayNotHaveThisParam: 'A getter cannot have a `this` parameter.',
22457
- ImportReflectionHasImportType: 'An `import module` declaration can not use `type` or `typeof` keyword.',
22458
- 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.',
22459
- InexactInsideExact: 'Explicit inexact syntax cannot appear inside an explicit exact object type.',
22460
- InexactInsideNonObject: 'Explicit inexact syntax cannot appear in class or interface definitions.',
22461
- InexactVariance: 'Explicit inexact syntax cannot have variance.',
22462
- InvalidNonTypeImportInDeclareModule: 'Imports within a `declare module` body must always be `import type` or `import typeof`.',
22463
- MissingTypeParamDefault: 'Type parameter declaration needs a default, since a preceding type parameter declaration has a default.',
22464
- NestedDeclareModule: '`declare module` cannot be used inside another `declare module`.',
22465
- NestedFlowComment: 'Cannot have a flow comment inside another flow comment.',
22466
- PatternIsOptional: Object.assign({
22467
- message: 'A binding pattern parameter cannot be optional in an implementation signature.',
22468
- }, {}),
22469
- SetterMayNotHaveThisParam: 'A setter cannot have a `this` parameter.',
22470
- SpreadVariance: 'Spread properties cannot have variance.',
22471
- ThisParamAnnotationRequired: 'A type annotation is required for the `this` parameter.',
22472
- ThisParamBannedInConstructor: 'Constructors cannot have a `this` parameter; constructors don\'t bind `this` like other functions.',
22473
- ThisParamMayNotBeOptional: 'The `this` parameter cannot be optional.',
22474
- ThisParamMustBeFirst: 'The `this` parameter must be the first function parameter.',
22475
- ThisParamNoDefault: 'The `this` parameter may not have a default value.',
22476
- TypeBeforeInitializer: 'Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.',
22477
- TypeCastInPattern: 'The type cast expression is expected to be wrapped with parenthesis.',
22478
- UnexpectedExplicitInexactInObject: 'Explicit inexact syntax must appear at the end of an inexact object.',
22479
- UnexpectedReservedType: ({reservedType}) => `Unexpected reserved type ${reservedType}.`,
22480
- UnexpectedReservedUnderscore: '`_` is only allowed as a type argument to call or new.',
22481
- UnexpectedSpaceBetweenModuloChecks: 'Spaces between `%` and `checks` are not allowed here.',
22482
- UnexpectedSpreadType: 'Spread operator cannot appear in class or interface definitions.',
22483
- UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
22484
- UnexpectedTokenAfterTypeParameter: 'Expected an arrow function after this type parameter declaration.',
22485
- UnexpectedTypeParameterBeforeAsyncArrowFunction: 'Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.',
22486
- UnsupportedDeclareExportKind: ({unsupportedExportKind, suggestion}) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
22487
- UnsupportedStatementInDeclareModule: 'Only declares and type imports are allowed inside declare module.',
22488
- UnterminatedFlowComment: 'Unterminated flow-comment.',
22489
- });
22490
-
22491
- function isEsModuleType(bodyElement) {
22492
- return bodyElement.type === 'DeclareExportAllDeclaration'
22493
- || bodyElement.type === 'DeclareExportDeclaration'
22494
- && (!bodyElement.declaration
22495
- || bodyElement.declaration.type !== 'TypeAlias'
22496
- && bodyElement.declaration.type !== 'InterfaceDeclaration');
22497
- }
22498
-
22499
- function hasTypeImportKind(node) {
22500
- return node.importKind === 'type' || node.importKind === 'typeof';
22501
- }
22502
-
22503
- var exportSuggestions = {
22504
- const: 'declare export var',
22505
- let: 'declare export var',
22506
- type: 'export type',
22507
- interface: 'export interface',
22508
- };
22509
-
22510
- function partition(list, test) {
22511
- const list1 = [];
22512
- const list2 = [];
22513
-
22514
- for (let i = 0; i < list.length; i++) {
22515
- (test(list[i], i, list) ? list1 : list2).push(list[i]);
22516
- }
22517
-
22518
- return [list1, list2];
22519
- }
22520
-
22521
- var FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
22522
-
22523
- var flow = (superClass) => class FlowParserMixin extends superClass {
22524
- constructor() {
22525
- super(...arguments);
22526
- __publicField(this, 'flowPragma');
22527
- }
22528
-
22529
- getScopeHandler() {
22530
- return FlowScopeHandler;
22531
- }
22532
-
22533
- shouldParseTypes() {
22534
- return this.getPluginOption('flow', 'all') || this.flowPragma === 'flow';
22535
- }
22536
-
22537
- finishToken(type, val) {
22538
- if (type !== 134 && type !== 13 && type !== 28) {
22539
- if (this.flowPragma === void 0) {
22540
- this.flowPragma = null;
22541
- }
22542
- }
22543
-
22544
- super.finishToken(type, val);
22545
- }
22546
-
22547
- addComment(comment) {
22548
- if (this.flowPragma === void 0) {
22549
- const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
22550
-
22551
- if (!matches); else if (matches[1] === 'flow') {
22552
- this.flowPragma = 'flow';
22553
- } else if (matches[1] === 'noflow') {
22554
- this.flowPragma = 'noflow';
22555
- } else {
22556
- throw new Error('Unexpected flow pragma');
22557
- }
22558
-
22559
- }
22560
-
22561
- super.addComment(comment);
22562
- }
22563
-
22564
- flowParseTypeInitialiser(tok) {
22565
- const oldInType = this.state.inType;
22566
-
22567
- this.state.inType = true;
22568
- this.expect(tok || 14);
22569
- const type = this.flowParseType();
22570
-
22571
- this.state.inType = oldInType;
22572
- return type;
22573
- }
22574
-
22575
- flowParsePredicate() {
22576
- const node = this.startNode();
22577
- const moduloLoc = this.state.startLoc;
22578
- this.next();
22579
- this.expectContextual(110);
22580
-
22581
- if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
22582
- this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
22583
- }
22584
-
22585
- if (this.eat(10)) {
22586
- node.value = super.parseExpression();
22587
- this.expect(11);
22588
- return this.finishNode(node, 'DeclaredPredicate');
22589
- } else {
22590
- return this.finishNode(node, 'InferredPredicate');
22591
- }
22592
- }
22593
-
22594
- flowParseTypeAndPredicateInitialiser() {
22595
- const oldInType = this.state.inType;
22596
-
22597
- this.state.inType = true;
22598
- this.expect(14);
22599
- let type = null;
22600
- let predicate = null;
22601
-
22602
- if (this.match(54)) {
22603
- this.state.inType = oldInType;
22604
- predicate = this.flowParsePredicate();
22605
- } else {
22606
- type = this.flowParseType();
22607
- this.state.inType = oldInType;
22608
-
22609
- if (this.match(54)) {
22610
- predicate = this.flowParsePredicate();
22611
- }
22612
- }
22613
-
22614
- return [type, predicate];
22615
- }
22616
-
22617
- flowParseDeclareClass(node) {
22618
- this.next();
22619
- this.flowParseInterfaceish(node, true);
22620
- return this.finishNode(node, 'DeclareClass');
22621
- }
22622
-
22623
- flowParseDeclareFunction(node) {
22624
- this.next();
22625
- const id = node.id = this.parseIdentifier();
22626
- const typeNode = this.startNode();
22627
- const typeContainer = this.startNode();
22628
-
22629
- if (this.match(47)) {
22630
- typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
22631
- } else {
22632
- typeNode.typeParameters = null;
22633
- }
22634
-
22635
- this.expect(10);
22636
- const tmp = this.flowParseFunctionTypeParams();
22637
-
22638
- typeNode.params = tmp.params;
22639
- typeNode.rest = tmp.rest;
22640
- typeNode.this = tmp._this;
22641
- this.expect(11);
22642
- [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
22643
- typeContainer.typeAnnotation = this.finishNode(typeNode, 'FunctionTypeAnnotation');
22644
- id.typeAnnotation = this.finishNode(typeContainer, 'TypeAnnotation');
22645
- this.resetEndLocation(id);
22646
- this.semicolon();
22647
- this.scope.declareName(node.id.name, 2048, node.id.loc.start);
22648
- return this.finishNode(node, 'DeclareFunction');
22649
- }
22650
-
22651
- flowParseDeclare(node, insideModule) {
22652
- if (this.match(80)) {
22653
- return this.flowParseDeclareClass(node);
22654
- } else if (this.match(68)) {
22655
- return this.flowParseDeclareFunction(node);
22656
- } else if (this.match(74)) {
22657
- return this.flowParseDeclareVariable(node);
22658
- } else if (this.eatContextual(127)) {
22659
- if (this.match(16)) {
22660
- return this.flowParseDeclareModuleExports(node);
22661
- } else {
22662
- if (insideModule) {
22663
- this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
22664
- }
22665
-
22666
- return this.flowParseDeclareModule(node);
22667
- }
22668
- } else if (this.isContextual(130)) {
22669
- return this.flowParseDeclareTypeAlias(node);
22670
- } else if (this.isContextual(131)) {
22671
- return this.flowParseDeclareOpaqueType(node);
22672
- } else if (this.isContextual(129)) {
22673
- return this.flowParseDeclareInterface(node);
22674
- } else if (this.match(82)) {
22675
- return this.flowParseDeclareExportDeclaration(node, insideModule);
22676
- } else {
22677
- this.unexpected();
22678
- }
22679
-
22680
-
22681
-
22682
-
22683
-
22684
-
22685
- }
22686
-
22687
- flowParseDeclareVariable(node) {
22688
- this.next();
22689
- node.id = this.flowParseTypeAnnotatableIdentifier(true);
22690
- this.scope.declareName(node.id.name, 5, node.id.loc.start);
22691
- this.semicolon();
22692
- return this.finishNode(node, 'DeclareVariable');
22693
- }
22694
-
22695
- flowParseDeclareModule(node) {
22696
- this.scope.enter(0);
22697
-
22698
- if (this.match(134)) {
22699
- node.id = super.parseExprAtom();
22700
- } else {
22701
- node.id = this.parseIdentifier();
22702
- }
22703
-
22704
- const bodyNode = node.body = this.startNode();
22705
- const body = bodyNode.body = [];
22706
-
22707
- this.expect(5);
22708
- while (!this.match(8)) {
22709
- let bodyNode2 = this.startNode();
22710
-
22711
- if (this.match(83)) {
22712
- this.next();
22713
-
22714
- if (!this.isContextual(130) && !this.match(87)) {
22715
- this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
22716
- }
22717
-
22718
- super.parseImport(bodyNode2);
22719
- } else {
22720
- this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
22721
- bodyNode2 = this.flowParseDeclare(bodyNode2, true);
22722
- }
22723
-
22724
- body.push(bodyNode2);
22725
- }
22726
-
22727
- this.scope.exit();
22728
- this.expect(8);
22729
- this.finishNode(bodyNode, 'BlockStatement');
22730
- let kind = null;
22731
- let hasModuleExport = false;
22732
-
22733
- body.forEach((bodyElement) => {
22734
- if (isEsModuleType(bodyElement)) {
22735
- if (kind === 'CommonJS') {
22736
- this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
22737
- }
22738
-
22739
- kind = 'ES';
22740
- } else if (bodyElement.type === 'DeclareModuleExports') {
22741
- if (hasModuleExport) {
22742
- this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
22743
- }
22744
-
22745
- if (kind === 'ES') {
22746
- this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
22747
- }
22748
-
22749
- kind = 'CommonJS';
22750
- hasModuleExport = true;
22751
- }
22752
- });
22753
- node.kind = kind || 'CommonJS';
22754
- return this.finishNode(node, 'DeclareModule');
22755
- }
22756
-
22757
- flowParseDeclareExportDeclaration(node, insideModule) {
22758
- this.expect(82);
22759
-
22760
- if (this.eat(65)) {
22761
- if (this.match(68) || this.match(80)) {
22762
- node.declaration = this.flowParseDeclare(this.startNode());
22763
- } else {
22764
- node.declaration = this.flowParseType();
22765
- this.semicolon();
22766
- }
22767
-
22768
- node.default = true;
22769
- return this.finishNode(node, 'DeclareExportDeclaration');
22770
- } else {
22771
- if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
22772
- const label = this.state.value;
22773
-
22774
- throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
22775
- unsupportedExportKind: label,
22776
- suggestion: exportSuggestions[label],
22777
- });
22778
- }
22779
-
22780
- if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
22781
- node.declaration = this.flowParseDeclare(this.startNode());
22782
- node.default = false;
22783
- return this.finishNode(node, 'DeclareExportDeclaration');
22784
- } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
22785
- node = this.parseExport(node, null);
22786
-
22787
- if (node.type === 'ExportNamedDeclaration') {
22788
- node.default = false;
22789
- delete node.exportKind;
22790
- return this.castNodeTo(node, 'DeclareExportDeclaration');
22791
- } else {
22792
- return this.castNodeTo(node, 'DeclareExportAllDeclaration');
22793
- }
22794
- }
22795
- }
22796
-
22797
- this.unexpected();
22798
- }
22799
-
22800
- flowParseDeclareModuleExports(node) {
22801
- this.next();
22802
- this.expectContextual(111);
22803
- node.typeAnnotation = this.flowParseTypeAnnotation();
22804
- this.semicolon();
22805
- return this.finishNode(node, 'DeclareModuleExports');
22806
- }
22807
-
22808
- flowParseDeclareTypeAlias(node) {
22809
- this.next();
22810
- const finished = this.flowParseTypeAlias(node);
22811
- this.castNodeTo(finished, 'DeclareTypeAlias');
22812
- return finished;
22813
- }
22814
-
22815
- flowParseDeclareOpaqueType(node) {
22816
- this.next();
22817
- const finished = this.flowParseOpaqueType(node, true);
22818
- this.castNodeTo(finished, 'DeclareOpaqueType');
22819
- return finished;
22820
- }
22821
-
22822
- flowParseDeclareInterface(node) {
22823
- this.next();
22824
- this.flowParseInterfaceish(node, false);
22825
- return this.finishNode(node, 'DeclareInterface');
22826
- }
22827
-
22828
- flowParseInterfaceish(node, isClass3) {
22829
- node.id = this.flowParseRestrictedIdentifier(!isClass3, true);
22830
- this.scope.declareName(node.id.name, isClass3 ? 17 : 8201, node.id.loc.start);
22831
-
22832
- if (this.match(47)) {
22833
- node.typeParameters = this.flowParseTypeParameterDeclaration();
22834
- } else {
22835
- node.typeParameters = null;
22836
- }
22837
-
22838
- node.extends = [];
22839
-
22840
- if (this.eat(81)) {
22841
- do {
22842
- node.extends.push(this.flowParseInterfaceExtends());
22843
- } while (!isClass3 && this.eat(12))
22844
- }
22845
-
22846
- if (isClass3) {
22847
- node.implements = [];
22848
- node.mixins = [];
22849
-
22850
- if (this.eatContextual(117)) {
22851
- do {
22852
- node.mixins.push(this.flowParseInterfaceExtends());
22853
- } while (this.eat(12))
22854
- }
22855
-
22856
- if (this.eatContextual(113)) {
22857
- do {
22858
- node.implements.push(this.flowParseInterfaceExtends());
22859
- } while (this.eat(12))
22860
- }
22861
- }
22862
-
22863
- node.body = this.flowParseObjectType({
22864
- allowStatic: isClass3,
22865
- allowExact: false,
22866
- allowSpread: false,
22867
- allowProto: isClass3,
22868
- allowInexact: false,
22869
- });
22870
- }
22871
-
22872
- flowParseInterfaceExtends() {
22873
- const node = this.startNode();
22874
-
22875
- node.id = this.flowParseQualifiedTypeIdentifier();
22876
-
22877
- if (this.match(47)) {
22878
- node.typeParameters = this.flowParseTypeParameterInstantiation();
22879
- } else {
22880
- node.typeParameters = null;
22881
- }
22882
-
22883
- return this.finishNode(node, 'InterfaceExtends');
22884
- }
22885
-
22886
- flowParseInterface(node) {
22887
- this.flowParseInterfaceish(node, false);
22888
- return this.finishNode(node, 'InterfaceDeclaration');
22889
- }
22890
-
22891
- checkNotUnderscore(word) {
22892
- if (word === '_') {
22893
- this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
22894
- }
22895
- }
22896
-
22897
- checkReservedType(word, startLoc, declaration) {
22898
- if (!reservedTypes.has(word))
22899
- return;
22900
-
22901
- this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
22902
- reservedType: word,
22903
- });
22904
- }
22905
-
22906
- flowParseRestrictedIdentifier(liberal, declaration) {
22907
- this.checkReservedType(this.state.value, this.state.startLoc, declaration);
22908
- return this.parseIdentifier(liberal);
22909
- }
22910
-
22911
- flowParseTypeAlias(node) {
22912
- node.id = this.flowParseRestrictedIdentifier(false, true);
22913
- this.scope.declareName(node.id.name, 8201, node.id.loc.start);
22914
-
22915
- if (this.match(47)) {
22916
- node.typeParameters = this.flowParseTypeParameterDeclaration();
22917
- } else {
22918
- node.typeParameters = null;
22919
- }
22920
-
22921
- node.right = this.flowParseTypeInitialiser(29);
22922
- this.semicolon();
22923
- return this.finishNode(node, 'TypeAlias');
22924
- }
22925
-
22926
- flowParseOpaqueType(node, declare) {
22927
- this.expectContextual(130);
22928
- node.id = this.flowParseRestrictedIdentifier(true, true);
22929
- this.scope.declareName(node.id.name, 8201, node.id.loc.start);
22930
-
22931
- if (this.match(47)) {
22932
- node.typeParameters = this.flowParseTypeParameterDeclaration();
22933
- } else {
22934
- node.typeParameters = null;
22935
- }
22936
-
22937
- node.supertype = null;
22938
-
22939
- if (this.match(14)) {
22940
- node.supertype = this.flowParseTypeInitialiser(14);
22941
- }
22942
-
22943
- node.impltype = null;
22944
-
22945
- if (!declare) {
22946
- node.impltype = this.flowParseTypeInitialiser(29);
22947
- }
22948
-
22949
- this.semicolon();
22950
- return this.finishNode(node, 'OpaqueType');
22951
- }
22952
-
22953
- flowParseTypeParameter(requireDefault = false) {
22954
- const nodeStartLoc = this.state.startLoc;
22955
- const node = this.startNode();
22956
- const variance2 = this.flowParseVariance();
22957
- const ident = this.flowParseTypeAnnotatableIdentifier();
22958
-
22959
- node.name = ident.name;
22960
- node.variance = variance2;
22961
- node.bound = ident.typeAnnotation;
22962
-
22963
- if (this.match(29)) {
22964
- this.eat(29);
22965
- node.default = this.flowParseType();
22966
- } else {
22967
- if (requireDefault) {
22968
- this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
22969
- }
22970
- }
22971
-
22972
- return this.finishNode(node, 'TypeParameter');
22973
- }
22974
-
22975
- flowParseTypeParameterDeclaration() {
22976
- const oldInType = this.state.inType;
22977
- const node = this.startNode();
22978
-
22979
- node.params = [];
22980
- this.state.inType = true;
22981
-
22982
- if (this.match(47) || this.match(143)) {
22983
- this.next();
22984
- } else {
22985
- this.unexpected();
22986
- }
22987
-
22988
- let defaultRequired = false;
22989
-
22990
- do {
22991
- const typeParameter2 = this.flowParseTypeParameter(defaultRequired);
22992
- node.params.push(typeParameter2);
22993
-
22994
- if (typeParameter2.default) {
22995
- defaultRequired = true;
22996
- }
22997
-
22998
- if (!this.match(48)) {
22999
- this.expect(12);
23000
- }
23001
- } while (!this.match(48))
23002
- this.expect(48);
23003
- this.state.inType = oldInType;
23004
- return this.finishNode(node, 'TypeParameterDeclaration');
23005
- }
23006
-
23007
- flowInTopLevelContext(cb) {
23008
- if (this.curContext() !== types.brace) {
23009
- const oldContext = this.state.context;
23010
-
23011
- this.state.context = [oldContext[0]];
23012
- try {
23013
- return cb();
23014
- } finally {
23015
- this.state.context = oldContext;
23016
- }
23017
- } else {
23018
- return cb();
23019
- }
23020
- }
23021
-
23022
- flowParseTypeParameterInstantiationInExpression() {
23023
- if (this.reScan_lt() !== 47)
23024
- return;
23025
-
23026
- return this.flowParseTypeParameterInstantiation();
23027
- }
23028
-
23029
- flowParseTypeParameterInstantiation() {
23030
- const node = this.startNode();
23031
- const oldInType = this.state.inType;
23032
-
23033
- this.state.inType = true;
23034
- node.params = [];
23035
- this.flowInTopLevelContext(() => {
23036
- this.expect(47);
23037
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
23038
-
23039
- this.state.noAnonFunctionType = false;
23040
- while (!this.match(48)) {
23041
- node.params.push(this.flowParseType());
23042
-
23043
- if (!this.match(48)) {
23044
- this.expect(12);
23045
- }
23046
- }
23047
-
23048
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
23049
- });
23050
- this.state.inType = oldInType;
23051
-
23052
- if (!this.state.inType && this.curContext() === types.brace) {
23053
- this.reScan_lt_gt();
23054
- }
23055
-
23056
- this.expect(48);
23057
- return this.finishNode(node, 'TypeParameterInstantiation');
23058
- }
23059
-
23060
- flowParseTypeParameterInstantiationCallOrNew() {
23061
- if (this.reScan_lt() !== 47)
23062
- return;
23063
-
23064
- const node = this.startNode();
23065
- const oldInType = this.state.inType;
23066
-
23067
- node.params = [];
23068
- this.state.inType = true;
23069
- this.expect(47);
23070
- while (!this.match(48)) {
23071
- node.params.push(this.flowParseTypeOrImplicitInstantiation());
23072
-
23073
- if (!this.match(48)) {
23074
- this.expect(12);
23075
- }
23076
- }
23077
-
23078
- this.expect(48);
23079
- this.state.inType = oldInType;
23080
- return this.finishNode(node, 'TypeParameterInstantiation');
23081
- }
23082
-
23083
- flowParseInterfaceType() {
23084
- const node = this.startNode();
23085
- this.expectContextual(129);
23086
- node.extends = [];
23087
-
23088
- if (this.eat(81)) {
23089
- do {
23090
- node.extends.push(this.flowParseInterfaceExtends());
23091
- } while (this.eat(12))
23092
- }
23093
-
23094
- node.body = this.flowParseObjectType({
23095
- allowStatic: false,
23096
- allowExact: false,
23097
- allowSpread: false,
23098
- allowProto: false,
23099
- allowInexact: false,
23100
- });
23101
- return this.finishNode(node, 'InterfaceTypeAnnotation');
23102
- }
23103
-
23104
- flowParseObjectPropertyKey() {
23105
- return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
23106
- }
23107
-
23108
- flowParseObjectTypeIndexer(node, isStatic2, variance2) {
23109
- node.static = isStatic2;
23110
-
23111
- if (this.lookahead().type === 14) {
23112
- node.id = this.flowParseObjectPropertyKey();
23113
- node.key = this.flowParseTypeInitialiser();
23114
- } else {
23115
- node.id = null;
23116
- node.key = this.flowParseType();
23117
- }
23118
-
23119
- this.expect(3);
23120
- node.value = this.flowParseTypeInitialiser();
23121
- node.variance = variance2;
23122
- return this.finishNode(node, 'ObjectTypeIndexer');
23123
- }
23124
-
23125
- flowParseObjectTypeInternalSlot(node, isStatic2) {
23126
- node.static = isStatic2;
23127
- node.id = this.flowParseObjectPropertyKey();
23128
- this.expect(3);
23129
- this.expect(3);
23130
-
23131
- if (this.match(47) || this.match(10)) {
23132
- node.method = true;
23133
- node.optional = false;
23134
- node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
23135
- } else {
23136
- node.method = false;
23137
-
23138
- if (this.eat(17)) {
23139
- node.optional = true;
23140
- }
23141
-
23142
- node.value = this.flowParseTypeInitialiser();
23143
- }
23144
-
23145
- return this.finishNode(node, 'ObjectTypeInternalSlot');
23146
- }
23147
-
23148
- flowParseObjectTypeMethodish(node) {
23149
- node.params = [];
23150
- node.rest = null;
23151
- node.typeParameters = null;
23152
- node.this = null;
23153
-
23154
- if (this.match(47)) {
23155
- node.typeParameters = this.flowParseTypeParameterDeclaration();
23156
- }
23157
-
23158
- this.expect(10);
23159
-
23160
- if (this.match(78)) {
23161
- node.this = this.flowParseFunctionTypeParam(true);
23162
- node.this.name = null;
23163
-
23164
- if (!this.match(11)) {
23165
- this.expect(12);
23166
- }
23167
- }
23168
-
23169
- while (!this.match(11) && !this.match(21)) {
23170
- node.params.push(this.flowParseFunctionTypeParam(false));
23171
-
23172
- if (!this.match(11)) {
23173
- this.expect(12);
23174
- }
23175
- }
23176
-
23177
- if (this.eat(21)) {
23178
- node.rest = this.flowParseFunctionTypeParam(false);
23179
- }
23180
-
23181
- this.expect(11);
23182
- node.returnType = this.flowParseTypeInitialiser();
23183
- return this.finishNode(node, 'FunctionTypeAnnotation');
23184
- }
23185
-
23186
- flowParseObjectTypeCallProperty(node, isStatic2) {
23187
- const valueNode = this.startNode();
23188
-
23189
- node.static = isStatic2;
23190
- node.value = this.flowParseObjectTypeMethodish(valueNode);
23191
- return this.finishNode(node, 'ObjectTypeCallProperty');
23192
- }
23193
-
23194
- flowParseObjectType({allowStatic, allowExact, allowSpread, allowProto, allowInexact}) {
23195
- const oldInType = this.state.inType;
23196
-
23197
- this.state.inType = true;
23198
- const nodeStart = this.startNode();
23199
-
23200
- nodeStart.callProperties = [];
23201
- nodeStart.properties = [];
23202
- nodeStart.indexers = [];
23203
- nodeStart.internalSlots = [];
23204
- let endDelim;
23205
- let exact;
23206
- let inexact = false;
23207
-
23208
- if (allowExact && this.match(6)) {
23209
- this.expect(6);
23210
- endDelim = 9;
23211
- exact = true;
23212
- } else {
23213
- this.expect(5);
23214
- endDelim = 8;
23215
- exact = false;
23216
- }
23217
-
23218
- nodeStart.exact = exact;
23219
- while (!this.match(endDelim)) {
23220
- let isStatic2 = false;
23221
- let protoStartLoc = null;
23222
- let inexactStartLoc = null;
23223
- const node = this.startNode();
23224
-
23225
- if (allowProto && this.isContextual(118)) {
23226
- const lookahead = this.lookahead();
23227
-
23228
- if (lookahead.type !== 14 && lookahead.type !== 17) {
23229
- this.next();
23230
- protoStartLoc = this.state.startLoc;
23231
- allowStatic = false;
23232
- }
23233
- }
23234
-
23235
- if (allowStatic && this.isContextual(106)) {
23236
- const lookahead = this.lookahead();
23237
-
23238
- if (lookahead.type !== 14 && lookahead.type !== 17) {
23239
- this.next();
23240
- isStatic2 = true;
23241
- }
23242
- }
23243
-
23244
- const variance2 = this.flowParseVariance();
23245
-
23246
- if (this.eat(0)) {
23247
- if (protoStartLoc != null) {
23248
- this.unexpected(protoStartLoc);
23249
- }
23250
-
23251
- if (this.eat(0)) {
23252
- if (variance2) {
23253
- this.unexpected(variance2.loc.start);
23254
- }
23255
-
23256
- nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic2));
23257
- } else {
23258
- nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic2, variance2));
23259
- }
23260
- } else if (this.match(10) || this.match(47)) {
23261
- if (protoStartLoc != null) {
23262
- this.unexpected(protoStartLoc);
23263
- }
23264
-
23265
- if (variance2) {
23266
- this.unexpected(variance2.loc.start);
23267
- }
23268
-
23269
- nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic2));
23270
- } else {
23271
- let kind = 'init';
23272
-
23273
- if (this.isContextual(99) || this.isContextual(104)) {
23274
- const lookahead = this.lookahead();
23275
-
23276
- if (tokenIsLiteralPropertyName(lookahead.type)) {
23277
- kind = this.state.value;
23278
- this.next();
23279
- }
23280
- }
23281
-
23282
- const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic2, protoStartLoc, variance2, kind, allowSpread, allowInexact ?? !exact);
23283
-
23284
- if (propOrInexact === null) {
23285
- inexact = true;
23286
- inexactStartLoc = this.state.lastTokStartLoc;
23287
- } else {
23288
- nodeStart.properties.push(propOrInexact);
23289
- }
23290
- }
23291
-
23292
- this.flowObjectTypeSemicolon();
23293
-
23294
- if (inexactStartLoc && !this.match(8) && !this.match(9)) {
23295
- this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
23296
- }
23297
- }
23298
-
23299
- this.expect(endDelim);
23300
-
23301
- if (allowSpread) {
23302
- nodeStart.inexact = inexact;
23303
- }
23304
-
23305
- const out = this.finishNode(nodeStart, 'ObjectTypeAnnotation');
23306
-
23307
- this.state.inType = oldInType;
23308
- return out;
23309
- }
23310
-
23311
- flowParseObjectTypeProperty(node, isStatic2, protoStartLoc, variance2, kind, allowSpread, allowInexact) {
23312
- if (this.eat(21)) {
23313
- const isInexactToken = this.match(12)
23314
- || this.match(13)
23315
- || this.match(8)
23316
- || this.match(9);
23317
-
23318
- if (isInexactToken) {
23319
- if (!allowSpread) {
23320
- this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
23321
- } else if (!allowInexact) {
23322
- this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
23323
- }
23324
-
23325
- if (variance2) {
23326
- this.raise(FlowErrors.InexactVariance, variance2);
23327
- }
23328
-
23329
- return null;
23330
- }
23331
-
23332
- if (!allowSpread) {
23333
- this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
23334
- }
23335
-
23336
- if (protoStartLoc != null) {
23337
- this.unexpected(protoStartLoc);
23338
- }
23339
-
23340
- if (variance2) {
23341
- this.raise(FlowErrors.SpreadVariance, variance2);
23342
- }
23343
-
23344
- node.argument = this.flowParseType();
23345
- return this.finishNode(node, 'ObjectTypeSpreadProperty');
23346
- } else {
23347
- node.key = this.flowParseObjectPropertyKey();
23348
- node.static = isStatic2;
23349
- node.proto = protoStartLoc != null;
23350
- node.kind = kind;
23351
- let optional = false;
23352
-
23353
- if (this.match(47) || this.match(10)) {
23354
- node.method = true;
23355
-
23356
- if (protoStartLoc != null) {
23357
- this.unexpected(protoStartLoc);
23358
- }
23359
-
23360
- if (variance2) {
23361
- this.unexpected(variance2.loc.start);
23362
- }
23363
-
23364
- node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
23365
-
23366
- if (kind === 'get' || kind === 'set') {
23367
- this.flowCheckGetterSetterParams(node);
23368
- }
23369
-
23370
- if (!allowSpread && node.key.name === 'constructor' && node.value.this) {
23371
- this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
23372
- }
23373
- } else {
23374
- if (kind !== 'init')
23375
- this.unexpected();
23376
-
23377
- node.method = false;
23378
-
23379
- if (this.eat(17)) {
23380
- optional = true;
23381
- }
23382
-
23383
- node.value = this.flowParseTypeInitialiser();
23384
- node.variance = variance2;
23385
- }
23386
-
23387
- node.optional = optional;
23388
- return this.finishNode(node, 'ObjectTypeProperty');
23389
- }
23390
- }
23391
-
23392
- flowCheckGetterSetterParams(property) {
23393
- const paramCount = property.kind === 'get' ? 0 : 1;
23394
- const length = property.value.params.length + (property.value.rest ? 1 : 0);
23395
-
23396
- if (property.value.this) {
23397
- this.raise(property.kind === 'get' ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
23398
- }
23399
-
23400
- if (length !== paramCount) {
23401
- this.raise(property.kind === 'get' ? Errors.BadGetterArity : Errors.BadSetterArity, property);
23402
- }
23403
-
23404
- if (property.kind === 'set' && property.value.rest) {
23405
- this.raise(Errors.BadSetterRestParameter, property);
23406
- }
23407
- }
23408
-
23409
- flowObjectTypeSemicolon() {
23410
- if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
23411
- this.unexpected();
23412
- }
23413
- }
23414
-
23415
- flowParseQualifiedTypeIdentifier(startLoc, id) {
23416
- startLoc ?? (startLoc = this.state.startLoc);
23417
- let node = id || this.flowParseRestrictedIdentifier(true);
23418
-
23419
- while (this.eat(16)) {
23420
- const node2 = this.startNodeAt(startLoc);
23421
-
23422
- node2.qualification = node;
23423
- node2.id = this.flowParseRestrictedIdentifier(true);
23424
- node = this.finishNode(node2, 'QualifiedTypeIdentifier');
23425
- }
23426
-
23427
- return node;
23428
- }
23429
-
23430
- flowParseGenericType(startLoc, id) {
23431
- const node = this.startNodeAt(startLoc);
23432
-
23433
- node.typeParameters = null;
23434
- node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
23435
-
23436
- if (this.match(47)) {
23437
- node.typeParameters = this.flowParseTypeParameterInstantiation();
23438
- }
23439
-
23440
- return this.finishNode(node, 'GenericTypeAnnotation');
23441
- }
23442
-
23443
- flowParseTypeofType() {
23444
- const node = this.startNode();
23445
- this.expect(87);
23446
- node.argument = this.flowParsePrimaryType();
23447
- return this.finishNode(node, 'TypeofTypeAnnotation');
23448
- }
23449
-
23450
- flowParseTupleType() {
23451
- const node = this.startNode();
23452
-
23453
- node.types = [];
23454
- this.expect(0);
23455
- while (this.state.pos < this.length && !this.match(3)) {
23456
- node.types.push(this.flowParseType());
23457
-
23458
- if (this.match(3))
23459
- break;
23460
-
23461
- this.expect(12);
23462
- }
23463
-
23464
- this.expect(3);
23465
- return this.finishNode(node, 'TupleTypeAnnotation');
23466
- }
23467
-
23468
- flowParseFunctionTypeParam(first) {
23469
- let name = null;
23470
- let optional = false;
23471
- let typeAnnotation2 = null;
23472
- const node = this.startNode();
23473
- const lh = this.lookahead();
23474
- const isThis = this.state.type === 78;
23475
-
23476
- if (lh.type === 14 || lh.type === 17) {
23477
- if (isThis && !first) {
23478
- this.raise(FlowErrors.ThisParamMustBeFirst, node);
23479
- }
23480
-
23481
- name = this.parseIdentifier(isThis);
23482
-
23483
- if (this.eat(17)) {
23484
- optional = true;
23485
-
23486
- if (isThis) {
23487
- this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
23488
- }
23489
- }
23490
-
23491
- typeAnnotation2 = this.flowParseTypeInitialiser();
23492
- } else {
23493
- typeAnnotation2 = this.flowParseType();
23494
- }
23495
-
23496
- node.name = name;
23497
- node.optional = optional;
23498
- node.typeAnnotation = typeAnnotation2;
23499
- return this.finishNode(node, 'FunctionTypeParam');
23500
- }
23501
-
23502
- reinterpretTypeAsFunctionTypeParam(type) {
23503
- const node = this.startNodeAt(type.loc.start);
23504
-
23505
- node.name = null;
23506
- node.optional = false;
23507
- node.typeAnnotation = type;
23508
- return this.finishNode(node, 'FunctionTypeParam');
23509
- }
23510
-
23511
- flowParseFunctionTypeParams(params = []) {
23512
- let rest = null;
23513
- let _this = null;
23514
-
23515
- if (this.match(78)) {
23516
- _this = this.flowParseFunctionTypeParam(true);
23517
- _this.name = null;
23518
-
23519
- if (!this.match(11)) {
23520
- this.expect(12);
23521
- }
23522
- }
23523
-
23524
- while (!this.match(11) && !this.match(21)) {
23525
- params.push(this.flowParseFunctionTypeParam(false));
23526
-
23527
- if (!this.match(11)) {
23528
- this.expect(12);
23529
- }
23530
- }
23531
-
23532
- if (this.eat(21)) {
23533
- rest = this.flowParseFunctionTypeParam(false);
23534
- }
23535
-
23536
- return {
23537
- params,
23538
- rest,
23539
- _this,
23540
- };
23541
- }
23542
-
23543
- flowIdentToTypeAnnotation(startLoc, node, id) {
23544
- switch(id.name) {
23545
- case 'any':
23546
- return this.finishNode(node, 'AnyTypeAnnotation');
23547
-
23548
- case 'bool':
23549
- case 'boolean':
23550
- return this.finishNode(node, 'BooleanTypeAnnotation');
23551
-
23552
- case 'mixed':
23553
- return this.finishNode(node, 'MixedTypeAnnotation');
23554
-
23555
- case 'empty':
23556
- return this.finishNode(node, 'EmptyTypeAnnotation');
23557
-
23558
- case 'number':
23559
- return this.finishNode(node, 'NumberTypeAnnotation');
23560
-
23561
- case 'string':
23562
- return this.finishNode(node, 'StringTypeAnnotation');
23563
-
23564
- case 'symbol':
23565
- return this.finishNode(node, 'SymbolTypeAnnotation');
23566
-
23567
- default:
23568
- this.checkNotUnderscore(id.name);
23569
- return this.flowParseGenericType(startLoc, id);
23570
- }
23571
- }
23572
-
23573
- flowParsePrimaryType() {
23574
- const startLoc = this.state.startLoc;
23575
- const node = this.startNode();
23576
- let tmp;
23577
- let type;
23578
- let isGroupedType = false;
23579
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
23580
-
23581
- switch(this.state.type) {
23582
- case 5:
23583
- return this.flowParseObjectType({
23584
- allowStatic: false,
23585
- allowExact: false,
23586
- allowSpread: true,
23587
- allowProto: false,
23588
- allowInexact: true,
23589
- });
23590
-
23591
- case 6:
23592
- return this.flowParseObjectType({
23593
- allowStatic: false,
23594
- allowExact: true,
23595
- allowSpread: true,
23596
- allowProto: false,
23597
- allowInexact: false,
23598
- });
23599
-
23600
- case 0:
23601
- this.state.noAnonFunctionType = false;
23602
- type = this.flowParseTupleType();
23603
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
23604
- return type;
23605
-
23606
- case 47: {
23607
- const node2 = this.startNode();
23608
-
23609
- node2.typeParameters = this.flowParseTypeParameterDeclaration();
23610
- this.expect(10);
23611
- tmp = this.flowParseFunctionTypeParams();
23612
- node2.params = tmp.params;
23613
- node2.rest = tmp.rest;
23614
- node2.this = tmp._this;
23615
- this.expect(11);
23616
- this.expect(19);
23617
- node2.returnType = this.flowParseType();
23618
- return this.finishNode(node2, 'FunctionTypeAnnotation');
23619
- }
23620
-
23621
- case 10: {
23622
- const node2 = this.startNode();
23623
- this.next();
23624
-
23625
- if (!this.match(11) && !this.match(21)) {
23626
- if (tokenIsIdentifier(this.state.type) || this.match(78)) {
23627
- const token = this.lookahead().type;
23628
- isGroupedType = token !== 17 && token !== 14;
23629
- } else {
23630
- isGroupedType = true;
23631
- }
23632
- }
23633
-
23634
- if (isGroupedType) {
23635
- this.state.noAnonFunctionType = false;
23636
- type = this.flowParseType();
23637
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
23638
-
23639
- if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
23640
- this.expect(11);
23641
- return type;
23642
- } else {
23643
- this.eat(12);
23644
- }
23645
- }
23646
-
23647
- if (type) {
23648
- tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
23649
- } else {
23650
- tmp = this.flowParseFunctionTypeParams();
23651
- }
23652
-
23653
- node2.params = tmp.params;
23654
- node2.rest = tmp.rest;
23655
- node2.this = tmp._this;
23656
- this.expect(11);
23657
- this.expect(19);
23658
- node2.returnType = this.flowParseType();
23659
- node2.typeParameters = null;
23660
- return this.finishNode(node2, 'FunctionTypeAnnotation');
23661
- }
23662
-
23663
- case 134:
23664
- return this.parseLiteral(this.state.value, 'StringLiteralTypeAnnotation');
23665
-
23666
- case 85:
23667
- case 86:
23668
- node.value = this.match(85);
23669
- this.next();
23670
- return this.finishNode(node, 'BooleanLiteralTypeAnnotation');
23671
-
23672
- case 53:
23673
- if (this.state.value === '-') {
23674
- this.next();
23675
-
23676
- if (this.match(135)) {
23677
- return this.parseLiteralAtNode(-this.state.value, 'NumberLiteralTypeAnnotation', node);
23678
- }
23679
-
23680
- if (this.match(136)) {
23681
- return this.parseLiteralAtNode(-this.state.value, 'BigIntLiteralTypeAnnotation', node);
23682
- }
23683
-
23684
- throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
23685
- }
23686
-
23687
- this.unexpected();
23688
- return;
23689
-
23690
- case 135:
23691
- return this.parseLiteral(this.state.value, 'NumberLiteralTypeAnnotation');
23692
-
23693
- case 136:
23694
- return this.parseLiteral(this.state.value, 'BigIntLiteralTypeAnnotation');
23695
-
23696
- case 88:
23697
- this.next();
23698
- return this.finishNode(node, 'VoidTypeAnnotation');
23699
-
23700
- case 84:
23701
- this.next();
23702
- return this.finishNode(node, 'NullLiteralTypeAnnotation');
23703
-
23704
- case 78:
23705
- this.next();
23706
- return this.finishNode(node, 'ThisTypeAnnotation');
23707
-
23708
- case 55:
23709
- this.next();
23710
- return this.finishNode(node, 'ExistsTypeAnnotation');
23711
-
23712
- case 87:
23713
- return this.flowParseTypeofType();
23714
-
23715
- default:
23716
- if (tokenIsKeyword(this.state.type)) {
23717
- const label = tokenLabelName(this.state.type);
23718
- this.next();
23719
- return super.createIdentifier(node, label);
23720
- } else if (tokenIsIdentifier(this.state.type)) {
23721
- if (this.isContextual(129)) {
23722
- return this.flowParseInterfaceType();
23723
- }
23724
-
23725
- return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
23726
- }
23727
- }
23728
-
23729
- this.unexpected();
23730
- }
23731
-
23732
- flowParsePostfixType() {
23733
- const startLoc = this.state.startLoc;
23734
- let type = this.flowParsePrimaryType();
23735
- let seenOptionalIndexedAccess = false;
23736
-
23737
- while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
23738
- const node = this.startNodeAt(startLoc);
23739
- const optional = this.eat(18);
23740
-
23741
- seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
23742
- this.expect(0);
23743
-
23744
- if (!optional && this.match(3)) {
23745
- node.elementType = type;
23746
- this.next();
23747
- type = this.finishNode(node, 'ArrayTypeAnnotation');
23748
- } else {
23749
- node.objectType = type;
23750
- node.indexType = this.flowParseType();
23751
- this.expect(3);
23752
-
23753
- if (seenOptionalIndexedAccess) {
23754
- node.optional = optional;
23755
- type = this.finishNode(node, 'OptionalIndexedAccessType');
23756
- } else {
23757
- type = this.finishNode(node, 'IndexedAccessType');
23758
- }
23759
- }
23760
- }
23761
-
23762
- return type;
23763
- }
23764
-
23765
- flowParsePrefixType() {
23766
- const node = this.startNode();
23767
-
23768
- if (this.eat(17)) {
23769
- node.typeAnnotation = this.flowParsePrefixType();
23770
- return this.finishNode(node, 'NullableTypeAnnotation');
23771
- } else {
23772
- return this.flowParsePostfixType();
23773
- }
23774
- }
23775
-
23776
- flowParseAnonFunctionWithoutParens() {
23777
- const param = this.flowParsePrefixType();
23778
-
23779
- if (!this.state.noAnonFunctionType && this.eat(19)) {
23780
- const node = this.startNodeAt(param.loc.start);
23781
-
23782
- node.params = [
23783
- this.reinterpretTypeAsFunctionTypeParam(param),
23784
- ];
23785
- node.rest = null;
23786
- node.this = null;
23787
- node.returnType = this.flowParseType();
23788
- node.typeParameters = null;
23789
- return this.finishNode(node, 'FunctionTypeAnnotation');
23790
- }
23791
-
23792
- return param;
23793
- }
23794
-
23795
- flowParseIntersectionType() {
23796
- const node = this.startNode();
23797
- this.eat(45);
23798
- const type = this.flowParseAnonFunctionWithoutParens();
23799
-
23800
- node.types = [type];
23801
- while (this.eat(45)) {
23802
- node.types.push(this.flowParseAnonFunctionWithoutParens());
23803
- }
23804
-
23805
- return node.types.length === 1 ? type : this.finishNode(node, 'IntersectionTypeAnnotation');
23806
- }
23807
-
23808
- flowParseUnionType() {
23809
- const node = this.startNode();
23810
- this.eat(43);
23811
- const type = this.flowParseIntersectionType();
23812
-
23813
- node.types = [type];
23814
- while (this.eat(43)) {
23815
- node.types.push(this.flowParseIntersectionType());
23816
- }
23817
-
23818
- return node.types.length === 1 ? type : this.finishNode(node, 'UnionTypeAnnotation');
23819
- }
23820
-
23821
- flowParseType() {
23822
- const oldInType = this.state.inType;
23823
-
23824
- this.state.inType = true;
23825
- const type = this.flowParseUnionType();
23826
-
23827
- this.state.inType = oldInType;
23828
- return type;
23829
- }
23830
-
23831
- flowParseTypeOrImplicitInstantiation() {
23832
- if (this.state.type === 132 && this.state.value === '_') {
23833
- const startLoc = this.state.startLoc;
23834
- const node = this.parseIdentifier();
23835
-
23836
- return this.flowParseGenericType(startLoc, node);
23837
- } else {
23838
- return this.flowParseType();
23839
- }
23840
- }
23841
-
23842
- flowParseTypeAnnotation() {
23843
- const node = this.startNode();
23844
-
23845
- node.typeAnnotation = this.flowParseTypeInitialiser();
23846
- return this.finishNode(node, 'TypeAnnotation');
23847
- }
23848
-
23849
- flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
23850
- const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
23851
-
23852
- if (this.match(14)) {
23853
- ident.typeAnnotation = this.flowParseTypeAnnotation();
23854
- this.resetEndLocation(ident);
23855
- }
23856
-
23857
- return ident;
23858
- }
23859
-
23860
- typeCastToParameter(node) {
23861
- node.expression.typeAnnotation = node.typeAnnotation;
23862
- this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
23863
- return node.expression;
23864
- }
23865
-
23866
- flowParseVariance() {
23867
- let variance2 = null;
23868
-
23869
- if (this.match(53)) {
23870
- variance2 = this.startNode();
23871
-
23872
- if (this.state.value === '+') {
23873
- variance2.kind = 'plus';
23874
- } else {
23875
- variance2.kind = 'minus';
23876
- }
23877
-
23878
- this.next();
23879
- return this.finishNode(variance2, 'Variance');
23880
- }
23881
-
23882
- return variance2;
23883
- }
23884
-
23885
- parseFunctionBody(node, allowExpressionBody, isMethod3 = false) {
23886
- if (allowExpressionBody) {
23887
- this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod3));
23888
- return;
23889
- }
23890
-
23891
- super.parseFunctionBody(node, false, isMethod3);
23892
- }
23893
-
23894
- parseFunctionBodyAndFinish(node, type, isMethod3 = false) {
23895
- if (this.match(14)) {
23896
- const typeNode = this.startNode();
23897
-
23898
- [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
23899
- node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, 'TypeAnnotation') : null;
23900
- }
23901
-
23902
- return super.parseFunctionBodyAndFinish(node, type, isMethod3);
23903
- }
23904
-
23905
- parseStatementLike(flags) {
23906
- if (this.state.strict && this.isContextual(129)) {
23907
- const lookahead = this.lookahead();
23908
-
23909
- if (tokenIsKeywordOrIdentifier(lookahead.type)) {
23910
- const node = this.startNode();
23911
- this.next();
23912
- return this.flowParseInterface(node);
23913
- }
23914
- } else if (this.isContextual(126)) {
23915
- const node = this.startNode();
23916
- this.next();
23917
- return this.flowParseEnumDeclaration(node);
23918
- }
23919
-
23920
- const stmt = super.parseStatementLike(flags);
23921
-
23922
- if (this.flowPragma === void 0 && !this.isValidDirective(stmt)) {
23923
- this.flowPragma = null;
23924
- }
23925
-
23926
- return stmt;
23927
- }
23928
-
23929
- parseExpressionStatement(node, expr, decorators) {
23930
- if (expr.type === 'Identifier') {
23931
- if (expr.name === 'declare') {
23932
- if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
23933
- return this.flowParseDeclare(node);
23934
- }
23935
- } else if (tokenIsIdentifier(this.state.type)) {
23936
- if (expr.name === 'interface') {
23937
- return this.flowParseInterface(node);
23938
- } else if (expr.name === 'type') {
23939
- return this.flowParseTypeAlias(node);
23940
- } else if (expr.name === 'opaque') {
23941
- return this.flowParseOpaqueType(node, false);
23942
- }
23943
-
23944
- }
23945
- }
23946
-
23947
- return super.parseExpressionStatement(node, expr, decorators);
23948
- }
23949
-
23950
- shouldParseExportDeclaration() {
23951
- const {type} = this.state;
23952
-
23953
- if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
23954
- return !this.state.containsEsc;
23955
- }
23956
-
23957
- return super.shouldParseExportDeclaration();
23958
- }
23959
-
23960
- isExportDefaultSpecifier() {
23961
- const {type} = this.state;
23962
-
23963
- if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
23964
- return this.state.containsEsc;
23965
- }
23966
-
23967
- return super.isExportDefaultSpecifier();
23968
- }
23969
-
23970
- parseExportDefaultExpression() {
23971
- if (this.isContextual(126)) {
23972
- const node = this.startNode();
23973
- this.next();
23974
- return this.flowParseEnumDeclaration(node);
23975
- }
23976
-
23977
- return super.parseExportDefaultExpression();
23978
- }
23979
-
23980
- parseConditional(expr, startLoc, refExpressionErrors) {
23981
- if (!this.match(17))
23982
- return expr;
23983
-
23984
- if (this.state.maybeInArrowParameters) {
23985
- const nextCh = this.lookaheadCharCode();
23986
-
23987
- if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
23988
- this.setOptionalParametersError(refExpressionErrors);
23989
- return expr;
23990
- }
23991
- }
23992
-
23993
- this.expect(17);
23994
- const state = this.state.clone();
23995
- const originalNoArrowAt = this.state.noArrowAt;
23996
- const node = this.startNodeAt(startLoc);
23997
-
23998
- let {consequent, failed} = this.tryParseConditionalConsequent();
23999
-
24000
- let [valid, invalid] = this.getArrowLikeExpressions(consequent);
24001
-
24002
- if (failed || invalid.length > 0) {
24003
- const noArrowAt = [...originalNoArrowAt];
24004
-
24005
- if (invalid.length > 0) {
24006
- this.state = state;
24007
- this.state.noArrowAt = noArrowAt;
24008
- for (let i = 0; i < invalid.length; i++) {
24009
- noArrowAt.push(invalid[i].start);
24010
- }
24011
-
24012
- ({
24013
- consequent,
24014
- failed,
24015
- } = this.tryParseConditionalConsequent());
24016
- [valid, invalid] = this.getArrowLikeExpressions(consequent);
24017
- }
24018
-
24019
- if (failed && valid.length > 1) {
24020
- this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
24021
- }
24022
-
24023
- if (failed && valid.length === 1) {
24024
- this.state = state;
24025
- noArrowAt.push(valid[0].start);
24026
- this.state.noArrowAt = noArrowAt;
24027
- ({
24028
- consequent,
24029
- failed,
24030
- } = this.tryParseConditionalConsequent());
24031
- }
24032
- }
24033
-
24034
- this.getArrowLikeExpressions(consequent, true);
24035
- this.state.noArrowAt = originalNoArrowAt;
24036
- this.expect(14);
24037
- node.test = expr;
24038
- node.consequent = consequent;
24039
- node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(void 0, void 0));
24040
-
24041
- return this.finishNode(node, 'ConditionalExpression');
24042
- }
24043
-
24044
- tryParseConditionalConsequent() {
24045
- this.state.noArrowParamsConversionAt.push(this.state.start);
24046
- const consequent = this.parseMaybeAssignAllowIn();
24047
- const failed = !this.match(14);
24048
-
24049
- this.state.noArrowParamsConversionAt.pop();
24050
- return {
24051
- consequent,
24052
- failed,
24053
- };
24054
- }
24055
-
24056
- getArrowLikeExpressions(node, disallowInvalid) {
24057
- const stack = [node];
24058
- const arrows = [];
24059
-
24060
- while (stack.length !== 0) {
24061
- const node2 = stack.pop();
24062
-
24063
- if (node2.type === 'ArrowFunctionExpression' && node2.body.type !== 'BlockStatement') {
24064
- if (node2.typeParameters || !node2.returnType) {
24065
- this.finishArrowValidation(node2);
24066
- } else {
24067
- arrows.push(node2);
24068
- }
24069
-
24070
- stack.push(node2.body);
24071
- } else if (node2.type === 'ConditionalExpression') {
24072
- stack.push(node2.consequent);
24073
- stack.push(node2.alternate);
24074
- }
24075
- }
24076
-
24077
- if (disallowInvalid) {
24078
- arrows.forEach((node2) => this.finishArrowValidation(node2));
24079
- return [
24080
- arrows,
24081
- [],
24082
- ];
24083
- }
24084
-
24085
- return partition(arrows, (node2) => node2.params.every((param) => this.isAssignable(param, true)));
24086
- }
24087
-
24088
- finishArrowValidation(node) {
24089
- this.toAssignableList(node.params, node.extra?.trailingCommaLoc, false);
24090
- this.scope.enter(514 | 4);
24091
- super.checkParams(node, false, true);
24092
- this.scope.exit();
24093
- }
24094
-
24095
- forwardNoArrowParamsConversionAt(node, parse3) {
24096
- let result;
24097
-
24098
- if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
24099
- this.state.noArrowParamsConversionAt.push(this.state.start);
24100
- result = parse3();
24101
- this.state.noArrowParamsConversionAt.pop();
24102
- } else {
24103
- result = parse3();
24104
- }
24105
-
24106
- return result;
24107
- }
24108
-
24109
- parseParenItem(node, startLoc) {
24110
- const newNode = super.parseParenItem(node, startLoc);
24111
-
24112
- if (this.eat(17)) {
24113
- newNode.optional = true;
24114
- this.resetEndLocation(node);
24115
- }
24116
-
24117
- if (this.match(14)) {
24118
- const typeCastNode = this.startNodeAt(startLoc);
24119
-
24120
- typeCastNode.expression = newNode;
24121
- typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
24122
- return this.finishNode(typeCastNode, 'TypeCastExpression');
24123
- }
24124
-
24125
- return newNode;
24126
- }
24127
-
24128
- assertModuleNodeAllowed(node) {
24129
- if (node.type === 'ImportDeclaration' && (node.importKind === 'type' || node.importKind === 'typeof') || node.type === 'ExportNamedDeclaration' && node.exportKind === 'type' || node.type === 'ExportAllDeclaration' && node.exportKind === 'type') {
24130
- return;
24131
- }
24132
-
24133
- super.assertModuleNodeAllowed(node);
24134
- }
24135
-
24136
- parseExportDeclaration(node) {
24137
- if (this.isContextual(130)) {
24138
- node.exportKind = 'type';
24139
- const declarationNode = this.startNode();
24140
- this.next();
24141
-
24142
- if (this.match(5)) {
24143
- node.specifiers = this.parseExportSpecifiers(true);
24144
- super.parseExportFrom(node);
24145
- return null;
24146
- } else {
24147
- return this.flowParseTypeAlias(declarationNode);
24148
- }
24149
- } else if (this.isContextual(131)) {
24150
- node.exportKind = 'type';
24151
- const declarationNode = this.startNode();
24152
- this.next();
24153
- return this.flowParseOpaqueType(declarationNode, false);
24154
- } else if (this.isContextual(129)) {
24155
- node.exportKind = 'type';
24156
- const declarationNode = this.startNode();
24157
- this.next();
24158
- return this.flowParseInterface(declarationNode);
24159
- } else if (this.isContextual(126)) {
24160
- node.exportKind = 'value';
24161
- const declarationNode = this.startNode();
24162
- this.next();
24163
- return this.flowParseEnumDeclaration(declarationNode);
24164
- } else {
24165
- return super.parseExportDeclaration(node);
24166
- }
24167
-
24168
-
24169
- }
24170
-
24171
- eatExportStar(node) {
24172
- if (super.eatExportStar(node))
24173
- return true;
24174
-
24175
- if (this.isContextual(130) && this.lookahead().type === 55) {
24176
- node.exportKind = 'type';
24177
- this.next();
24178
- this.next();
24179
- return true;
24180
- }
24181
-
24182
- return false;
24183
- }
24184
-
24185
- maybeParseExportNamespaceSpecifier(node) {
24186
- const {startLoc} = this.state;
24187
-
24188
- const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
24189
-
24190
- if (hasNamespace && node.exportKind === 'type') {
24191
- this.unexpected(startLoc);
24192
- }
24193
-
24194
- return hasNamespace;
24195
- }
24196
-
24197
- parseClassId(node, isStatement5, optionalId) {
24198
- super.parseClassId(node, isStatement5, optionalId);
24199
-
24200
- if (this.match(47)) {
24201
- node.typeParameters = this.flowParseTypeParameterDeclaration();
24202
- }
24203
- }
24204
-
24205
- parseClassMember(classBody2, member, state) {
24206
- const {startLoc} = this.state;
24207
-
24208
- if (this.isContextual(125)) {
24209
- if (super.parseClassMemberFromModifier(classBody2, member)) {
24210
- return;
24211
- }
24212
-
24213
- member.declare = true;
24214
- }
24215
-
24216
- super.parseClassMember(classBody2, member, state);
24217
-
24218
- if (member.declare) {
24219
- if (member.type !== 'ClassProperty' && member.type !== 'ClassPrivateProperty' && member.type !== 'PropertyDefinition') {
24220
- this.raise(FlowErrors.DeclareClassElement, startLoc);
24221
- } else if (member.value) {
24222
- this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
24223
- }
24224
- }
24225
- }
24226
-
24227
- isIterator(word) {
24228
- return word === 'iterator' || word === 'asyncIterator';
24229
- }
24230
-
24231
- readIterator() {
24232
- const word = super.readWord1();
24233
- const fullWord = '@@' + word;
24234
-
24235
- if (!this.isIterator(word) || !this.state.inType) {
24236
- this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
24237
- identifierName: fullWord,
24238
- });
24239
- }
24240
-
24241
- this.finishToken(132, fullWord);
24242
- }
24243
-
24244
- getTokenFromCode(code2) {
24245
- const next = this.input.charCodeAt(this.state.pos + 1);
24246
-
24247
- if (code2 === 123 && next === 124) {
24248
- this.finishOp(6, 2);
24249
- } else if (this.state.inType && (code2 === 62 || code2 === 60)) {
24250
- this.finishOp(code2 === 62 ? 48 : 47, 1);
24251
- } else if (this.state.inType && code2 === 63) {
24252
- if (next === 46) {
24253
- this.finishOp(18, 2);
24254
- } else {
24255
- this.finishOp(17, 1);
24256
- }
24257
- } else if (isIteratorStart(code2, next, this.input.charCodeAt(this.state.pos + 2))) {
24258
- this.state.pos += 2;
24259
- this.readIterator();
24260
- } else {
24261
- super.getTokenFromCode(code2);
24262
- }
24263
-
24264
-
24265
- }
24266
-
24267
- isAssignable(node, isBinding3) {
24268
- if (node.type === 'TypeCastExpression') {
24269
- return this.isAssignable(node.expression, isBinding3);
24270
- } else {
24271
- return super.isAssignable(node, isBinding3);
24272
- }
24273
- }
24274
-
24275
- toAssignable(node, isLHS = false) {
24276
- if (!isLHS && node.type === 'AssignmentExpression' && node.left.type === 'TypeCastExpression') {
24277
- node.left = this.typeCastToParameter(node.left);
24278
- }
24279
-
24280
- super.toAssignable(node, isLHS);
24281
- }
24282
-
24283
- toAssignableList(exprList, trailingCommaLoc, isLHS) {
24284
- for (let i = 0; i < exprList.length; i++) {
24285
- const expr = exprList[i];
24286
-
24287
- if (expr?.type === 'TypeCastExpression') {
24288
- exprList[i] = this.typeCastToParameter(expr);
24289
- }
24290
- }
24291
-
24292
- super.toAssignableList(exprList, trailingCommaLoc, isLHS);
24293
- }
24294
-
24295
- toReferencedList(exprList, isParenthesizedExpr) {
24296
- for (let i = 0; i < exprList.length; i++) {
24297
- const expr = exprList[i];
24298
-
24299
- if (expr && expr.type === 'TypeCastExpression' && !expr.extra?.parenthesized && (exprList.length > 1 || !isParenthesizedExpr)) {
24300
- this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
24301
- }
24302
- }
24303
-
24304
- return exprList;
24305
- }
24306
-
24307
- parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
24308
- const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
24309
-
24310
- if (canBePattern && !this.state.maybeInArrowParameters) {
24311
- this.toReferencedList(node.elements);
24312
- }
24313
-
24314
- return node;
24315
- }
24316
-
24317
- isValidLVal(type, isParenthesized, binding) {
24318
- return type === 'TypeCastExpression' || super.isValidLVal(type, isParenthesized, binding);
24319
- }
24320
-
24321
- parseClassProperty(node) {
24322
- if (this.match(14)) {
24323
- node.typeAnnotation = this.flowParseTypeAnnotation();
24324
- }
24325
-
24326
- return super.parseClassProperty(node);
24327
- }
24328
-
24329
- parseClassPrivateProperty(node) {
24330
- if (this.match(14)) {
24331
- node.typeAnnotation = this.flowParseTypeAnnotation();
24332
- }
24333
-
24334
- return super.parseClassPrivateProperty(node);
24335
- }
24336
-
24337
- isClassMethod() {
24338
- return this.match(47) || super.isClassMethod();
24339
- }
24340
-
24341
- isClassProperty() {
24342
- return this.match(14) || super.isClassProperty();
24343
- }
24344
-
24345
- isNonstaticConstructor(method) {
24346
- return !this.match(14) && super.isNonstaticConstructor(method);
24347
- }
24348
-
24349
- pushClassMethod(classBody2, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
24350
- if (method.variance) {
24351
- this.unexpected(method.variance.loc.start);
24352
- }
24353
-
24354
- delete method.variance;
24355
-
24356
- if (this.match(47)) {
24357
- method.typeParameters = this.flowParseTypeParameterDeclaration();
24358
- }
24359
-
24360
- super.pushClassMethod(classBody2, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
24361
-
24362
- if (method.params && isConstructor) {
24363
- const params = method.params;
24364
-
24365
- if (params.length > 0 && this.isThisParam(params[0])) {
24366
- this.raise(FlowErrors.ThisParamBannedInConstructor, method);
24367
- }
24368
- } else if (method.type === 'MethodDefinition' && isConstructor && method.value.params) {
24369
- const params = method.value.params;
24370
-
24371
- if (params.length > 0 && this.isThisParam(params[0])) {
24372
- this.raise(FlowErrors.ThisParamBannedInConstructor, method);
24373
- }
24374
- }
24375
- }
24376
-
24377
- pushClassPrivateMethod(classBody2, method, isGenerator, isAsync) {
24378
- if (method.variance) {
24379
- this.unexpected(method.variance.loc.start);
24380
- }
24381
-
24382
- delete method.variance;
24383
-
24384
- if (this.match(47)) {
24385
- method.typeParameters = this.flowParseTypeParameterDeclaration();
24386
- }
24387
-
24388
- super.pushClassPrivateMethod(classBody2, method, isGenerator, isAsync);
24389
- }
24390
-
24391
- parseClassSuper(node) {
24392
- super.parseClassSuper(node);
24393
-
24394
- if (node.superClass && (this.match(47) || this.match(51))) {
24395
- {
24396
- node.superTypeArguments = this.flowParseTypeParameterInstantiationInExpression();
24397
- }
24398
- }
24399
-
24400
- if (this.isContextual(113)) {
24401
- this.next();
24402
- const implemented = node.implements = [];
24403
-
24404
- do {
24405
- const node2 = this.startNode();
24406
-
24407
- node2.id = this.flowParseRestrictedIdentifier(true);
24408
-
24409
- if (this.match(47)) {
24410
- node2.typeParameters = this.flowParseTypeParameterInstantiation();
24411
- } else {
24412
- node2.typeParameters = null;
24413
- }
24414
-
24415
- implemented.push(this.finishNode(node2, 'ClassImplements'));
24416
- } while (this.eat(12))
24417
- }
24418
- }
24419
-
24420
- checkGetterSetterParams(method) {
24421
- super.checkGetterSetterParams(method);
24422
- const params = this.getObjectOrClassMethodParams(method);
24423
-
24424
- if (params.length > 0) {
24425
- const param = params[0];
24426
-
24427
- if (this.isThisParam(param) && method.kind === 'get') {
24428
- this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
24429
- } else if (this.isThisParam(param)) {
24430
- this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
24431
- }
24432
- }
24433
- }
24434
-
24435
- parsePropertyNamePrefixOperator(node) {
24436
- node.variance = this.flowParseVariance();
24437
- }
24438
-
24439
- parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern3, isAccessor2, refExpressionErrors) {
24440
- if (prop.variance) {
24441
- this.unexpected(prop.variance.loc.start);
24442
- }
24443
-
24444
- delete prop.variance;
24445
- let typeParameters;
24446
-
24447
- if (this.match(47) && !isAccessor2) {
24448
- typeParameters = this.flowParseTypeParameterDeclaration();
24449
-
24450
- if (!this.match(10))
24451
- this.unexpected();
24452
- }
24453
-
24454
- const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern3, isAccessor2, refExpressionErrors);
24455
-
24456
- if (typeParameters) {
24457
- (result.value || result).typeParameters = typeParameters;
24458
- }
24459
-
24460
- return result;
24461
- }
24462
-
24463
- parseFunctionParamType(param) {
24464
- if (this.eat(17)) {
24465
- if (param.type !== 'Identifier') {
24466
- this.raise(FlowErrors.PatternIsOptional, param);
24467
- }
24468
-
24469
- if (this.isThisParam(param)) {
24470
- this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
24471
- }
24472
-
24473
- param.optional = true;
24474
- }
24475
-
24476
- if (this.match(14)) {
24477
- param.typeAnnotation = this.flowParseTypeAnnotation();
24478
- } else if (this.isThisParam(param)) {
24479
- this.raise(FlowErrors.ThisParamAnnotationRequired, param);
24480
- }
24481
-
24482
- if (this.match(29) && this.isThisParam(param)) {
24483
- this.raise(FlowErrors.ThisParamNoDefault, param);
24484
- }
24485
-
24486
- this.resetEndLocation(param);
24487
- return param;
24488
- }
24489
-
24490
- parseMaybeDefault(startLoc, left) {
24491
- const node = super.parseMaybeDefault(startLoc, left);
24492
-
24493
- if (node.type === 'AssignmentPattern' && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
24494
- this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
24495
- }
24496
-
24497
- return node;
24498
- }
24499
-
24500
- checkImportReflection(node) {
24501
- super.checkImportReflection(node);
24502
-
24503
- if (node.module && node.importKind !== 'value') {
24504
- this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
24505
- }
24506
- }
24507
-
24508
- parseImportSpecifierLocal(node, specifier, type) {
24509
- specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
24510
- node.specifiers.push(this.finishImportSpecifier(specifier, type));
24511
- }
24512
-
24513
- isPotentialImportPhase(isExport) {
24514
- if (super.isPotentialImportPhase(isExport))
24515
- return true;
24516
-
24517
- if (this.isContextual(130)) {
24518
- if (!isExport)
24519
- return true;
24520
-
24521
- const ch = this.lookaheadCharCode();
24522
-
24523
- return ch === 123 || ch === 42;
24524
- }
24525
-
24526
- return !isExport && this.isContextual(87);
24527
- }
24528
-
24529
- applyImportPhase(node, isExport, phase, loc) {
24530
- super.applyImportPhase(node, isExport, phase, loc);
24531
-
24532
- if (isExport) {
24533
- if (!phase && this.match(65)) {
24534
- return;
24535
- }
24536
-
24537
- node.exportKind = phase === 'type' ? phase : 'value';
24538
- } else {
24539
- if (phase === 'type' && this.match(55))
24540
- this.unexpected();
24541
-
24542
- node.importKind = phase === 'type' || phase === 'typeof' ? phase : 'value';
24543
- }
24544
- }
24545
-
24546
- parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
24547
- const firstIdent = specifier.imported;
24548
- let specifierTypeKind = null;
24549
-
24550
- if (firstIdent.type === 'Identifier') {
24551
- if (firstIdent.name === 'type') {
24552
- specifierTypeKind = 'type';
24553
- } else if (firstIdent.name === 'typeof') {
24554
- specifierTypeKind = 'typeof';
24555
- }
24556
- }
24557
-
24558
- let isBinding3 = false;
24559
-
24560
- if (this.isContextual(93) && !this.isLookaheadContextual('as')) {
24561
- const as_ident = this.parseIdentifier(true);
24562
-
24563
- if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
24564
- specifier.imported = as_ident;
24565
- specifier.importKind = specifierTypeKind;
24566
- specifier.local = this.cloneIdentifier(as_ident);
24567
- } else {
24568
- specifier.imported = firstIdent;
24569
- specifier.importKind = null;
24570
- specifier.local = this.parseIdentifier();
24571
- }
24572
- } else {
24573
- if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
24574
- specifier.imported = this.parseIdentifier(true);
24575
- specifier.importKind = specifierTypeKind;
24576
- } else {
24577
- if (importedIsString) {
24578
- throw this.raise(Errors.ImportBindingIsString, specifier, {
24579
- importName: firstIdent.value,
24580
- });
24581
- }
24582
-
24583
- specifier.imported = firstIdent;
24584
- specifier.importKind = null;
24585
- }
24586
-
24587
- if (this.eatContextual(93)) {
24588
- specifier.local = this.parseIdentifier();
24589
- } else {
24590
- isBinding3 = true;
24591
- specifier.local = this.cloneIdentifier(specifier.imported);
24592
- }
24593
- }
24594
-
24595
- const specifierIsTypeImport = hasTypeImportKind(specifier);
24596
-
24597
- if (isInTypeOnlyImport && specifierIsTypeImport) {
24598
- this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
24599
- }
24600
-
24601
- if (isInTypeOnlyImport || specifierIsTypeImport) {
24602
- this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
24603
- }
24604
-
24605
- if (isBinding3 && !isInTypeOnlyImport && !specifierIsTypeImport) {
24606
- this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
24607
- }
24608
-
24609
- return this.finishImportSpecifier(specifier, 'ImportSpecifier');
24610
- }
24611
-
24612
- parseBindingAtom() {
24613
- switch(this.state.type) {
24614
- case 78:
24615
- return this.parseIdentifier(true);
24616
-
24617
- default:
24618
- return super.parseBindingAtom();
24619
- }
24620
- }
24621
-
24622
- parseFunctionParams(node, isConstructor) {
24623
- const kind = node.kind;
24624
-
24625
- if (kind !== 'get' && kind !== 'set' && this.match(47)) {
24626
- node.typeParameters = this.flowParseTypeParameterDeclaration();
24627
- }
24628
-
24629
- super.parseFunctionParams(node, isConstructor);
24630
- }
24631
-
24632
- parseVarId(decl, kind) {
24633
- super.parseVarId(decl, kind);
24634
-
24635
- if (this.match(14)) {
24636
- decl.id.typeAnnotation = this.flowParseTypeAnnotation();
24637
- this.resetEndLocation(decl.id);
24638
- }
24639
- }
24640
-
24641
- parseAsyncArrowFromCallExpression(node, call2) {
24642
- if (this.match(14)) {
24643
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
24644
-
24645
- this.state.noAnonFunctionType = true;
24646
- node.returnType = this.flowParseTypeAnnotation();
24647
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
24648
- }
24649
-
24650
- return super.parseAsyncArrowFromCallExpression(node, call2);
24651
- }
24652
-
24653
- shouldParseAsyncArrow() {
24654
- return this.match(14) || super.shouldParseAsyncArrow();
24655
- }
24656
-
24657
- parseMaybeAssign(refExpressionErrors, afterLeftParse) {
24658
- let state = null;
24659
- let jsx2;
24660
-
24661
- if (this.hasPlugin('jsx') && (this.match(143) || this.match(47))) {
24662
- state = this.state.clone();
24663
- jsx2 = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
24664
-
24665
- if (!jsx2.error)
24666
- return jsx2.node;
24667
-
24668
- const {context} = this.state;
24669
-
24670
- const currentContext = context[context.length - 1];
24671
-
24672
- if (currentContext === types.j_oTag || currentContext === types.j_expr) {
24673
- context.pop();
24674
- }
24675
- }
24676
-
24677
- if (jsx2?.error || this.match(47)) {
24678
- state = state || this.state.clone();
24679
- let typeParameters;
24680
- const arrow = this.tryParse((abort) => {
24681
- typeParameters = this.flowParseTypeParameterDeclaration();
24682
- const arrowExpression2 = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
24683
- const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
24684
- this.resetStartLocationFromNode(result, typeParameters);
24685
- return result;
24686
- });
24687
-
24688
- if (arrowExpression2.extra?.parenthesized)
24689
- abort();
24690
-
24691
- const expr = this.maybeUnwrapTypeCastExpression(arrowExpression2);
24692
-
24693
- if (expr.type !== 'ArrowFunctionExpression')
24694
- abort();
24695
-
24696
- expr.typeParameters = typeParameters;
24697
- this.resetStartLocationFromNode(expr, typeParameters);
24698
- return arrowExpression2;
24699
- }, state);
24700
-
24701
- let arrowExpression = null;
24702
-
24703
- if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === 'ArrowFunctionExpression') {
24704
- if (!arrow.error && !arrow.aborted) {
24705
- if (arrow.node.async) {
24706
- this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
24707
- }
24708
-
24709
- return arrow.node;
24710
- }
24711
-
24712
- arrowExpression = arrow.node;
24713
- }
24714
-
24715
- if (jsx2?.node) {
24716
- this.state = jsx2.failState;
24717
- return jsx2.node;
24718
- }
24719
-
24720
- if (arrowExpression) {
24721
- this.state = arrow.failState;
24722
- return arrowExpression;
24723
- }
24724
-
24725
- if (jsx2?.thrown)
24726
- throw jsx2.error;
24727
-
24728
- if (arrow.thrown)
24729
- throw arrow.error;
24730
-
24731
- throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
24732
- }
24733
-
24734
- return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
24735
- }
24736
-
24737
- parseArrow(node) {
24738
- if (this.match(14)) {
24739
- const result = this.tryParse(() => {
24740
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
24741
-
24742
- this.state.noAnonFunctionType = true;
24743
- const typeNode = this.startNode();
24744
-
24745
- [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
24746
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
24747
-
24748
- if (this.canInsertSemicolon())
24749
- this.unexpected();
24750
-
24751
- if (!this.match(19))
24752
- this.unexpected();
24753
-
24754
- return typeNode;
24755
- });
24756
-
24757
- if (result.thrown)
24758
- return null;
24759
-
24760
- if (result.error)
24761
- this.state = result.failState;
24762
-
24763
- node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, 'TypeAnnotation') : null;
24764
- }
24765
-
24766
- return super.parseArrow(node);
24767
- }
24768
-
24769
- shouldParseArrow(params) {
24770
- return this.match(14) || super.shouldParseArrow(params);
24771
- }
24772
-
24773
- setArrowFunctionParameters(node, params) {
24774
- if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
24775
- node.params = params;
24776
- } else {
24777
- super.setArrowFunctionParameters(node, params);
24778
- }
24779
- }
24780
-
24781
- checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
24782
- if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
24783
- return;
24784
- }
24785
-
24786
- for (let i = 0; i < node.params.length; i++) {
24787
- if (this.isThisParam(node.params[i]) && i > 0) {
24788
- this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
24789
- }
24790
- }
24791
-
24792
- super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
21968
+ 'false',
21969
+ 'in',
21970
+ 'instanceof',
21971
+ 'typeof',
21972
+ 'void',
21973
+ 'delete',
21974
+ 'implements',
21975
+ 'interface',
21976
+ 'let',
21977
+ 'package',
21978
+ 'private',
21979
+ 'protected',
21980
+ 'public',
21981
+ 'static',
21982
+ 'yield',
21983
+ 'eval',
21984
+ 'arguments',
21985
+ 'enum',
21986
+ 'await',
21987
+ ]);
21988
+
21989
+ function canBeReservedWord(word) {
21990
+ return reservedWordLikeSet.has(word);
21991
+ }
21992
+
21993
+ var Scope = class {
21994
+ constructor(flags) {
21995
+ __publicField(this, 'flags', 0);
21996
+ __publicField(this, 'names', /* @__PURE__ */new Map());
21997
+ __publicField(this, 'firstLexicalName', '');
21998
+ this.flags = flags;
24793
21999
  }
24794
-
24795
- parseParenAndDistinguishExpression(canBeArrow) {
24796
- return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
22000
+ };
22001
+
22002
+ var ScopeHandler = class {
22003
+ constructor(parser, inModule) {
22004
+ __publicField(this, 'parser');
22005
+ __publicField(this, 'scopeStack', []);
22006
+ __publicField(this, 'inModule');
22007
+ __publicField(this, 'undefinedExports', /* @__PURE__ */new Map());
22008
+ this.parser = parser;
22009
+ this.inModule = inModule;
24797
22010
  }
24798
22011
 
24799
- parseSubscripts(base, startLoc, noCalls) {
24800
- if (base.type === 'Identifier' && base.name === 'async' && this.state.noArrowAt.includes(startLoc.index)) {
24801
- this.next();
24802
- const node = this.startNodeAt(startLoc);
24803
-
24804
- node.callee = base;
24805
- node.arguments = super.parseCallExpressionArguments();
24806
- base = this.finishNode(node, 'CallExpression');
24807
- } else if (base.type === 'Identifier' && base.name === 'async' && this.match(47)) {
24808
- const state = this.state.clone();
24809
- const arrow = this.tryParse((abort) => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
24810
-
24811
- if (!arrow.error && !arrow.aborted)
24812
- return arrow.node;
24813
-
24814
- const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
24815
-
24816
- if (result.node && !result.error)
24817
- return result.node;
24818
-
24819
- if (arrow.node) {
24820
- this.state = arrow.failState;
24821
- return arrow.node;
24822
- }
24823
-
24824
- if (result.node) {
24825
- this.state = result.failState;
24826
- return result.node;
24827
- }
24828
-
24829
- throw arrow.error || result.error;
24830
- }
24831
-
24832
- return super.parseSubscripts(base, startLoc, noCalls);
22012
+ get inTopLevel() {
22013
+ return (this.currentScope().flags & 1) > 0;
24833
22014
  }
24834
22015
 
24835
- parseSubscript(base, startLoc, noCalls, subscriptState) {
24836
- if (this.match(18) && this.isLookaheadToken_lt()) {
24837
- subscriptState.optionalChainMember = true;
24838
-
24839
- if (noCalls) {
24840
- subscriptState.stop = true;
24841
- return base;
24842
- }
24843
-
24844
- this.next();
24845
- const node = this.startNodeAt(startLoc);
24846
-
24847
- node.callee = base;
24848
- node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
24849
- this.expect(10);
24850
- node.arguments = this.parseCallExpressionArguments();
24851
- node.optional = true;
24852
- return this.finishCallExpression(node, true);
24853
- } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
24854
- const node = this.startNodeAt(startLoc);
24855
-
24856
- node.callee = base;
24857
- const result = this.tryParse(() => {
24858
- node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
24859
- this.expect(10);
24860
- node.arguments = super.parseCallExpressionArguments();
24861
-
24862
- if (subscriptState.optionalChainMember) {
24863
- node.optional = false;
24864
- }
24865
-
24866
- return this.finishCallExpression(node, subscriptState.optionalChainMember);
24867
- });
24868
-
24869
- if (result.node) {
24870
- if (result.error)
24871
- this.state = result.failState;
24872
-
24873
- return result.node;
24874
- }
24875
- }
24876
-
24877
- return super.parseSubscript(base, startLoc, noCalls, subscriptState);
22016
+ get inFunction() {
22017
+ return (this.currentVarScopeFlags() & 2) > 0;
24878
22018
  }
24879
22019
 
24880
- parseNewCallee(node) {
24881
- super.parseNewCallee(node);
24882
- let targs = null;
24883
-
24884
- if (this.shouldParseTypes() && this.match(47)) {
24885
- targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
24886
- }
24887
-
24888
- node.typeArguments = targs;
22020
+ get allowSuper() {
22021
+ return (this.currentThisScopeFlags() & 16) > 0;
24889
22022
  }
24890
22023
 
24891
- parseAsyncArrowWithTypeParameters(startLoc) {
24892
- const node = this.startNodeAt(startLoc);
24893
- this.parseFunctionParams(node, false);
24894
-
24895
- if (!this.parseArrow(node))
24896
- return;
24897
-
24898
- return super.parseArrowExpression(node, void 0, true);
22024
+ get allowDirectSuper() {
22025
+ return (this.currentThisScopeFlags() & 32) > 0;
24899
22026
  }
24900
22027
 
24901
- readToken_mult_modulo(code2) {
24902
- const next = this.input.charCodeAt(this.state.pos + 1);
24903
-
24904
- if (code2 === 42 && next === 47 && this.state.hasFlowComment) {
24905
- this.state.hasFlowComment = false;
24906
- this.state.pos += 2;
24907
- this.nextToken();
24908
- return;
24909
- }
24910
-
24911
- super.readToken_mult_modulo(code2);
22028
+ get allowNewTarget() {
22029
+ return (this.currentThisScopeFlags() & 512) > 0;
24912
22030
  }
24913
22031
 
24914
- readToken_pipe_amp(code2) {
24915
- const next = this.input.charCodeAt(this.state.pos + 1);
24916
-
24917
- if (code2 === 124 && next === 125) {
24918
- this.finishOp(9, 2);
24919
- return;
24920
- }
24921
-
24922
- super.readToken_pipe_amp(code2);
22032
+ get inClass() {
22033
+ return (this.currentThisScopeFlags() & 64) > 0;
24923
22034
  }
24924
22035
 
24925
- parseTopLevel(file2, program3) {
24926
- const fileNode = super.parseTopLevel(file2, program3);
24927
-
24928
- if (this.state.hasFlowComment) {
24929
- this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
24930
- }
24931
-
24932
- return fileNode;
22036
+ get inClassAndNotInNonArrowFunction() {
22037
+ const flags = this.currentThisScopeFlags();
22038
+ return (flags & 64) > 0 && (flags & 2) === 0;
24933
22039
  }
24934
22040
 
24935
- skipBlockComment() {
24936
- if (this.hasPlugin('flowComments') && this.skipFlowComment()) {
24937
- if (this.state.hasFlowComment) {
24938
- throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
24939
- }
24940
-
24941
- this.hasFlowCommentCompletion();
24942
- const commentSkip = this.skipFlowComment();
22041
+ get inStaticBlock() {
22042
+ for (let i = this.scopeStack.length - 1;; i--) {
22043
+ const {flags} = this.scopeStack[i];
24943
22044
 
24944
- if (commentSkip) {
24945
- this.state.pos += commentSkip;
24946
- this.state.hasFlowComment = true;
22045
+ if (flags & 128) {
22046
+ return true;
24947
22047
  }
24948
22048
 
24949
- return;
24950
- }
24951
-
24952
- return super.skipBlockComment(this.state.hasFlowComment ? '*-/' : '*/');
24953
- }
24954
-
24955
- skipFlowComment() {
24956
- const {pos} = this.state;
24957
-
24958
- let shiftToFirstNonWhiteSpace = 2;
24959
-
24960
- while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
24961
- shiftToFirstNonWhiteSpace++;
24962
- }
24963
-
24964
- const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
24965
- const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
24966
-
24967
- if (ch2 === 58 && ch3 === 58) {
24968
- return shiftToFirstNonWhiteSpace + 2;
24969
- }
24970
-
24971
- if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === 'flow-include') {
24972
- return shiftToFirstNonWhiteSpace + 12;
24973
- }
24974
-
24975
- if (ch2 === 58 && ch3 !== 58) {
24976
- return shiftToFirstNonWhiteSpace;
24977
- }
24978
-
24979
- return false;
24980
- }
24981
-
24982
- hasFlowCommentCompletion() {
24983
- const end = this.input.indexOf('*/', this.state.pos);
24984
-
24985
- if (end === -1) {
24986
- throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
22049
+ if (flags & (1667 | 64)) {
22050
+ return false;
22051
+ }
24987
22052
  }
24988
22053
  }
24989
22054
 
24990
- flowEnumErrorBooleanMemberNotInitialized(loc, {enumName, memberName}) {
24991
- this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
24992
- memberName,
24993
- enumName,
24994
- });
22055
+ get inNonArrowFunction() {
22056
+ return (this.currentThisScopeFlags() & 2) > 0;
24995
22057
  }
24996
22058
 
24997
- flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
24998
- return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === 'symbol' ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
22059
+ get inBareCaseStatement() {
22060
+ return (this.currentScope().flags & 256) > 0;
24999
22061
  }
25000
22062
 
25001
- flowEnumErrorNumberMemberNotInitialized(loc, details) {
25002
- this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
22063
+ get treatFunctionsAsVar() {
22064
+ return this.treatFunctionsAsVarInScope(this.currentScope());
25003
22065
  }
25004
22066
 
25005
- flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
25006
- this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
22067
+ createScope(flags) {
22068
+ return new Scope(flags);
25007
22069
  }
25008
22070
 
25009
- flowEnumMemberInit() {
25010
- const startLoc = this.state.startLoc;
25011
- const endOfInit = () => this.match(12) || this.match(8);
25012
-
25013
- switch(this.state.type) {
25014
- case 135: {
25015
- const literal = this.parseNumericLiteral(this.state.value);
25016
-
25017
- if (endOfInit()) {
25018
- return {
25019
- type: 'number',
25020
- loc: literal.loc.start,
25021
- value: literal,
25022
- };
25023
- }
25024
-
25025
- return {
25026
- type: 'invalid',
25027
- loc: startLoc,
25028
- };
25029
- }
25030
-
25031
- case 134: {
25032
- const literal = this.parseStringLiteral(this.state.value);
25033
-
25034
- if (endOfInit()) {
25035
- return {
25036
- type: 'string',
25037
- loc: literal.loc.start,
25038
- value: literal,
25039
- };
25040
- }
25041
-
25042
- return {
25043
- type: 'invalid',
25044
- loc: startLoc,
25045
- };
25046
- }
25047
-
25048
- case 85:
25049
- case 86: {
25050
- const literal = this.parseBooleanLiteral(this.match(85));
25051
-
25052
- if (endOfInit()) {
25053
- return {
25054
- type: 'boolean',
25055
- loc: literal.loc.start,
25056
- value: literal,
25057
- };
25058
- }
25059
-
25060
- return {
25061
- type: 'invalid',
25062
- loc: startLoc,
25063
- };
25064
- }
25065
-
25066
- default:
25067
- return {
25068
- type: 'invalid',
25069
- loc: startLoc,
25070
- };
25071
- }
22071
+ enter(flags) {
22072
+ this.scopeStack.push(this.createScope(flags));
25072
22073
  }
25073
22074
 
25074
- flowEnumMemberRaw() {
25075
- const loc = this.state.startLoc;
25076
- const id = this.parseIdentifier(true);
25077
- const init = this.eat(29) ? this.flowEnumMemberInit() : {
25078
- type: 'none',
25079
- loc,
25080
- };
25081
-
25082
- return {
25083
- id,
25084
- init,
25085
- };
22075
+ exit() {
22076
+ const scope2 = this.scopeStack.pop();
22077
+ return scope2.flags;
25086
22078
  }
25087
22079
 
25088
- flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
25089
- const {explicitType} = context;
25090
-
25091
- if (explicitType === null) {
25092
- return;
25093
- }
25094
-
25095
- if (explicitType !== expectedType) {
25096
- this.flowEnumErrorInvalidMemberInitializer(loc, context);
25097
- }
22080
+ treatFunctionsAsVarInScope(scope2) {
22081
+ return !!(scope2.flags & (2 | 128) || !this.parser.inModule && scope2.flags & 1);
25098
22082
  }
25099
22083
 
25100
- flowEnumMembers({enumName, explicitType}) {
25101
- const seenNames = /* @__PURE__ */new Set();
25102
- const members = {
25103
- booleanMembers: [],
25104
- numberMembers: [],
25105
- stringMembers: [],
25106
- defaultedMembers: [],
25107
- };
25108
-
25109
- let hasUnknownMembers = false;
22084
+ declareName(name, bindingType, loc) {
22085
+ let scope2 = this.currentScope();
25110
22086
 
25111
- while (!this.match(8)) {
25112
- if (this.eat(21)) {
25113
- hasUnknownMembers = true;
25114
- break;
25115
- }
25116
-
25117
- const memberNode = this.startNode();
25118
- const {id, init} = this.flowEnumMemberRaw();
25119
-
25120
- const memberName = id.name;
25121
-
25122
- if (memberName === '') {
25123
- continue;
25124
- }
25125
-
25126
- if (/^[a-z]/.test(memberName)) {
25127
- this.raise(FlowErrors.EnumInvalidMemberName, id, {
25128
- memberName,
25129
- suggestion: memberName[0].toUpperCase() + memberName.slice(1),
25130
- enumName,
25131
- });
25132
- }
25133
-
25134
- if (seenNames.has(memberName)) {
25135
- this.raise(FlowErrors.EnumDuplicateMemberName, id, {
25136
- memberName,
25137
- enumName,
25138
- });
25139
- }
25140
-
25141
- seenNames.add(memberName);
25142
- const context = {
25143
- enumName,
25144
- explicitType,
25145
- memberName,
25146
- };
25147
-
25148
- memberNode.id = id;
25149
- switch(init.type) {
25150
- case 'boolean': {
25151
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'boolean');
25152
- memberNode.init = init.value;
25153
- members.booleanMembers.push(this.finishNode(memberNode, 'EnumBooleanMember'));
25154
- break;
25155
- }
22087
+ if (bindingType & 8 || bindingType & 16) {
22088
+ this.checkRedeclarationInScope(scope2, name, bindingType, loc);
22089
+ let type = scope2.names.get(name) || 0;
25156
22090
 
25157
- case 'number': {
25158
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'number');
25159
- memberNode.init = init.value;
25160
- members.numberMembers.push(this.finishNode(memberNode, 'EnumNumberMember'));
25161
- break;
22091
+ if (bindingType & 16) {
22092
+ type = type | 4;
22093
+ } else {
22094
+ if (!scope2.firstLexicalName) {
22095
+ scope2.firstLexicalName = name;
22096
+ }
22097
+
22098
+ type = type | 2;
25162
22099
  }
25163
22100
 
25164
- case 'string': {
25165
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'string');
25166
- memberNode.init = init.value;
25167
- members.stringMembers.push(this.finishNode(memberNode, 'EnumStringMember'));
25168
- break;
25169
- }
22101
+ scope2.names.set(name, type);
25170
22102
 
25171
- case 'invalid': {
25172
- throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
22103
+ if (bindingType & 8) {
22104
+ this.maybeExportDefined(scope2, name);
25173
22105
  }
25174
-
25175
- case 'none': {
25176
- switch(explicitType) {
25177
- case 'boolean':
25178
- this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
25179
- break;
22106
+ } else if (bindingType & 4) {
22107
+ for (let i = this.scopeStack.length - 1; i >= 0; --i) {
22108
+ scope2 = this.scopeStack[i];
22109
+ this.checkRedeclarationInScope(scope2, name, bindingType, loc);
22110
+ scope2.names.set(name, (scope2.names.get(name) || 0) | 1);
22111
+ this.maybeExportDefined(scope2, name);
25180
22112
 
25181
- case 'number':
25182
- this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
22113
+ if (scope2.flags & 1667)
25183
22114
  break;
25184
-
25185
- default:
25186
- members.defaultedMembers.push(this.finishNode(memberNode, 'EnumDefaultedMember'));
25187
- }
25188
- }
25189
- }
25190
-
25191
- if (!this.match(8)) {
25192
- this.expect(12);
25193
22115
  }
25194
22116
  }
25195
22117
 
25196
- return {
25197
- members,
25198
- hasUnknownMembers,
25199
- };
22118
+ if (this.parser.inModule && scope2.flags & 1) {
22119
+ this.undefinedExports.delete(name);
22120
+ }
25200
22121
  }
25201
22122
 
25202
- flowEnumStringMembers(initializedMembers, defaultedMembers, {enumName}) {
25203
- if (initializedMembers.length === 0) {
25204
- return defaultedMembers;
25205
- } else if (defaultedMembers.length === 0) {
25206
- return initializedMembers;
25207
- } else if (defaultedMembers.length > initializedMembers.length) {
25208
- for (const member of initializedMembers) {
25209
- this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
25210
- enumName,
25211
- });
25212
- }
25213
-
25214
- return defaultedMembers;
25215
- } else {
25216
- for (const member of defaultedMembers) {
25217
- this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
25218
- enumName,
25219
- });
25220
- }
25221
-
25222
- return initializedMembers;
22123
+ maybeExportDefined(scope2, name) {
22124
+ if (this.parser.inModule && scope2.flags & 1) {
22125
+ this.undefinedExports.delete(name);
25223
22126
  }
25224
-
25225
22127
  }
25226
22128
 
25227
- flowEnumParseExplicitType({enumName}) {
25228
- if (!this.eatContextual(102))
25229
- return null;
25230
-
25231
- if (!tokenIsIdentifier(this.state.type)) {
25232
- throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
25233
- enumName,
22129
+ checkRedeclarationInScope(scope2, name, bindingType, loc) {
22130
+ if (this.isRedeclaredInScope(scope2, name, bindingType)) {
22131
+ this.parser.raise(Errors.VarRedeclaration, loc, {
22132
+ identifierName: name,
25234
22133
  });
25235
22134
  }
22135
+ }
22136
+
22137
+ isRedeclaredInScope(scope2, name, bindingType) {
22138
+ if (!(bindingType & 1))
22139
+ return false;
25236
22140
 
25237
- const {value} = this.state;
22141
+ if (bindingType & 8) {
22142
+ return scope2.names.has(name);
22143
+ }
25238
22144
 
25239
- this.next();
22145
+ const type = scope2.names.get(name);
25240
22146
 
25241
- if (value !== 'boolean' && value !== 'number' && value !== 'string' && value !== 'symbol') {
25242
- this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
25243
- enumName,
25244
- invalidEnumType: value,
25245
- });
22147
+ if (bindingType & 16) {
22148
+ return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope2) && (type & 1) > 0;
25246
22149
  }
25247
22150
 
25248
- return value;
22151
+ return (type & 2) > 0 && !(scope2.flags & 8 && scope2.firstLexicalName === name)
22152
+ || !this.treatFunctionsAsVarInScope(scope2) && (type & 4) > 0;
25249
22153
  }
25250
22154
 
25251
- flowEnumBody(node, id) {
25252
- const enumName = id.name;
25253
- const nameLoc = id.loc.start;
25254
- const explicitType = this.flowEnumParseExplicitType({
25255
- enumName,
25256
- });
25257
-
25258
- this.expect(5);
25259
- const {
25260
- members,
25261
- hasUnknownMembers,
25262
- } = this.flowEnumMembers({
25263
- enumName,
25264
- explicitType,
25265
- });
25266
-
25267
- node.hasUnknownMembers = hasUnknownMembers;
25268
- switch(explicitType) {
25269
- case 'boolean':
25270
- node.explicitType = true;
25271
- node.members = members.booleanMembers;
25272
- this.expect(8);
25273
- return this.finishNode(node, 'EnumBooleanBody');
25274
-
25275
- case 'number':
25276
- node.explicitType = true;
25277
- node.members = members.numberMembers;
25278
- this.expect(8);
25279
- return this.finishNode(node, 'EnumNumberBody');
25280
-
25281
- case 'string':
25282
- node.explicitType = true;
25283
- node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
25284
- enumName,
25285
- });
25286
- this.expect(8);
25287
- return this.finishNode(node, 'EnumStringBody');
22155
+ checkLocalExport(id) {
22156
+ const {name} = id;
25288
22157
 
25289
- case 'symbol':
25290
- node.members = members.defaultedMembers;
25291
- this.expect(8);
25292
- return this.finishNode(node, 'EnumSymbolBody');
22158
+ const topLevelScope = this.scopeStack[0];
25293
22159
 
25294
- default: {
25295
- const empty = () => {
25296
- node.members = [];
25297
- this.expect(8);
25298
- return this.finishNode(node, 'EnumStringBody');
25299
- };
25300
-
25301
- node.explicitType = false;
25302
- const boolsLen = members.booleanMembers.length;
25303
- const numsLen = members.numberMembers.length;
25304
- const strsLen = members.stringMembers.length;
25305
- const defaultedLen = members.defaultedMembers.length;
25306
-
25307
- if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
25308
- return empty();
25309
- } else if (!boolsLen && !numsLen) {
25310
- node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
25311
- enumName,
25312
- });
25313
- this.expect(8);
25314
- return this.finishNode(node, 'EnumStringBody');
25315
- } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
25316
- for (const member of members.defaultedMembers) {
25317
- this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
25318
- enumName,
25319
- memberName: member.id.name,
25320
- });
25321
- }
25322
-
25323
- node.members = members.booleanMembers;
25324
- this.expect(8);
25325
-
25326
- return this.finishNode(node, 'EnumBooleanBody');
25327
- } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
25328
- for (const member of members.defaultedMembers) {
25329
- this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
25330
- enumName,
25331
- memberName: member.id.name,
25332
- });
25333
- }
25334
-
25335
- node.members = members.numberMembers;
25336
- this.expect(8);
25337
-
25338
- return this.finishNode(node, 'EnumNumberBody');
25339
- } else {
25340
- this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
25341
- enumName,
25342
- });
25343
- return empty();
25344
- }
25345
-
25346
-
25347
- }
22160
+ if (!topLevelScope.names.has(name)) {
22161
+ this.undefinedExports.set(name, id.loc.start);
25348
22162
  }
25349
22163
  }
25350
22164
 
25351
- flowParseEnumDeclaration(node) {
25352
- const id = this.parseIdentifier();
25353
-
25354
- node.id = id;
25355
- node.body = this.flowEnumBody(this.startNode(), id);
25356
- return this.finishNode(node, 'EnumDeclaration');
22165
+ currentScope() {
22166
+ return this.scopeStack[this.scopeStack.length - 1];
25357
22167
  }
25358
22168
 
25359
- jsxParseOpeningElementAfterName(node) {
25360
- if (this.shouldParseTypes()) {
25361
- if (this.match(47) || this.match(51)) {
25362
- node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
22169
+ currentVarScopeFlags() {
22170
+ for (let i = this.scopeStack.length - 1;; i--) {
22171
+ const {flags} = this.scopeStack[i];
22172
+
22173
+ if (flags & 1667) {
22174
+ return flags;
25363
22175
  }
25364
22176
  }
25365
-
25366
- return super.jsxParseOpeningElementAfterName(node);
25367
22177
  }
25368
22178
 
25369
- isLookaheadToken_lt() {
25370
- const next = this.nextTokenStart();
25371
-
25372
- if (this.input.charCodeAt(next) === 60) {
25373
- const afterNext = this.input.charCodeAt(next + 1);
25374
- return afterNext !== 60 && afterNext !== 61;
22179
+ currentThisScopeFlags() {
22180
+ for (let i = this.scopeStack.length - 1;; i--) {
22181
+ const {flags} = this.scopeStack[i];
22182
+
22183
+ if (flags & (1667 | 64) && !(flags & 4)) {
22184
+ return flags;
22185
+ }
25375
22186
  }
25376
-
25377
- return false;
22187
+ }
22188
+ };
22189
+
22190
+ var FlowScope = class extends Scope {
22191
+ constructor() {
22192
+ super(...arguments);
22193
+ __publicField(this, 'declareFunctions', /* @__PURE__ */new Set());
22194
+ }
22195
+ };
22196
+
22197
+ var FlowScopeHandler = class extends ScopeHandler {
22198
+ createScope(flags) {
22199
+ return new FlowScope(flags);
25378
22200
  }
25379
22201
 
25380
- reScan_lt_gt() {
25381
- const {type} = this.state;
22202
+ declareName(name, bindingType, loc) {
22203
+ const scope2 = this.currentScope();
25382
22204
 
25383
- if (type === 47) {
25384
- this.state.pos -= 1;
25385
- this.readToken_lt();
25386
- } else if (type === 48) {
25387
- this.state.pos -= 1;
25388
- this.readToken_gt();
22205
+ if (bindingType & 2048) {
22206
+ this.checkRedeclarationInScope(scope2, name, bindingType, loc);
22207
+ this.maybeExportDefined(scope2, name);
22208
+ scope2.declareFunctions.add(name);
22209
+ return;
25389
22210
  }
22211
+
22212
+ super.declareName(name, bindingType, loc);
25390
22213
  }
25391
22214
 
25392
- reScan_lt() {
25393
- const {type} = this.state;
22215
+ isRedeclaredInScope(scope2, name, bindingType) {
22216
+ if (super.isRedeclaredInScope(scope2, name, bindingType))
22217
+ return true;
25394
22218
 
25395
- if (type === 51) {
25396
- this.state.pos -= 2;
25397
- this.finishOp(47, 1);
25398
- return 47;
22219
+ if (bindingType & 2048 && !scope2.declareFunctions.has(name)) {
22220
+ const type = scope2.names.get(name);
22221
+ return (type & 4) > 0 || (type & 2) > 0;
25399
22222
  }
25400
22223
 
25401
- return type;
22224
+ return false;
25402
22225
  }
25403
22226
 
25404
- maybeUnwrapTypeCastExpression(node) {
25405
- return node.type === 'TypeCastExpression' ? node.expression : node;
22227
+ checkLocalExport(id) {
22228
+ if (!this.scopeStack[0].declareFunctions.has(id.name)) {
22229
+ super.checkLocalExport(id);
22230
+ }
25406
22231
  }
25407
22232
  };
25408
22233
 
22234
+ var reservedTypes = /* @__PURE__ */new Set([
22235
+ '_',
22236
+ 'any',
22237
+ 'bool',
22238
+ 'boolean',
22239
+ 'empty',
22240
+ 'extends',
22241
+ 'false',
22242
+ 'interface',
22243
+ 'mixed',
22244
+ 'null',
22245
+ 'number',
22246
+ 'static',
22247
+ 'string',
22248
+ 'true',
22249
+ 'typeof',
22250
+ 'void',
22251
+ ]);
22252
+
22253
+ function isEsModuleType(bodyElement) {
22254
+ return bodyElement.type === 'DeclareExportAllDeclaration'
22255
+ || bodyElement.type === 'DeclareExportDeclaration'
22256
+ && (!bodyElement.declaration
22257
+ || bodyElement.declaration.type !== 'TypeAlias'
22258
+ && bodyElement.declaration.type !== 'InterfaceDeclaration');
22259
+ }
22260
+
22261
+ function hasTypeImportKind(node) {
22262
+ return node.importKind === 'type' || node.importKind === 'typeof';
22263
+ }
22264
+
22265
+ var exportSuggestions = {
22266
+ const: 'declare export var',
22267
+ let: 'declare export var',
22268
+ type: 'export type',
22269
+ interface: 'export interface',
22270
+ };
22271
+
22272
+ function partition(list, test) {
22273
+ const list1 = [];
22274
+ const list2 = [];
22275
+
22276
+ for (let i = 0; i < list.length; i++) {
22277
+ (test(list[i], i, list) ? list1 : list2).push(list[i]);
22278
+ }
22279
+
22280
+ return [list1, list2];
22281
+ }
22282
+
22283
+ var FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
22284
+
25409
22285
  var entities = {
25410
22286
  __proto__: null,
25411
22287
  quot: '"',
@@ -30128,6 +27004,7 @@ var typescript = (superClass) => class TypeScriptParserMixin extends superClass
30128
27004
  node.properties = [
30129
27005
  this.finishObjectProperty(withProperty),
30130
27006
  ];
27007
+ this.eat(12);
30131
27008
  this.expect(8);
30132
27009
  return this.finishNode(node, 'ObjectExpression');
30133
27010
  }
@@ -31839,6 +28716,7 @@ var typescript = (superClass) => class TypeScriptParserMixin extends superClass
31839
28716
  const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(startLoc);
31840
28717
 
31841
28718
  if (asyncArrowFn) {
28719
+ state.stop = true;
31842
28720
  return asyncArrowFn;
31843
28721
  }
31844
28722
  }
@@ -33189,6 +30067,11 @@ var typescript = (superClass) => class TypeScriptParserMixin extends superClass
33189
30067
  node.extends ?? (node.extends = []);
33190
30068
  return;
33191
30069
 
30070
+ case 'TSMappedType':
30071
+ node.optional ?? (node.optional = false);
30072
+ node.readonly ?? (node.readonly = void 0);
30073
+ return;
30074
+
33192
30075
  case 'TSModuleDeclaration':
33193
30076
  node.declare ?? (node.declare = false);
33194
30077
  node.global ?? (node.global = node.kind === 'global');
@@ -33692,7 +30575,6 @@ function validatePlugins(pluginsMap) {
33692
30575
  var mixinPlugins = {
33693
30576
  estree,
33694
30577
  jsx,
33695
- flow,
33696
30578
  typescript,
33697
30579
  v8intrinsic,
33698
30580
  placeholders,
@@ -39076,8 +35958,7 @@ function populatePlaceholders(metadata, replacements) {
39076
35958
  });
39077
35959
  }
39078
35960
 
39079
- metadata
39080
- .placeholders
35961
+ metadata.placeholders
39081
35962
  .slice()
39082
35963
  .reverse()
39083
35964
  .forEach((placeholder2) => {
@@ -39349,8 +36230,7 @@ function extendedTrace(fn) {
39349
36230
  throw new Error();
39350
36231
  } catch(error) {
39351
36232
  if (error.stack) {
39352
- rootStack = error
39353
- .stack
36233
+ rootStack = error.stack
39354
36234
  .split('\n')
39355
36235
  .slice(3)
39356
36236
  .join('\n');
@@ -41973,10 +38853,6 @@ function NewExpression2(node, parent) {
41973
38853
 
41974
38854
  this.print(node.typeArguments);
41975
38855
 
41976
- if (node.optional) {
41977
- this.token('?.');
41978
- }
41979
-
41980
38856
  if (node.arguments.length === 0 && this.tokenMap && !this.tokenMap.endMatches(node, ')')) {
41981
38857
  return;
41982
38858
  }
@@ -46560,7 +43436,7 @@ function normalizeOptions(code2, opts, ast) {
46560
43436
  }
46561
43437
 
46562
43438
  if (!Array.isArray(ast.tokens)) {
46563
- throw new Error('`experimental_preserveFormat` requires the AST to have attatched the token of the input code. Make sure to enable the `tokens: true` parser option.');
43439
+ throw new Error('`experimental_preserveFormat` requires the AST to have attached the token of the input code. Make sure to enable the `tokens: true` parser option.');
46564
43440
  }
46565
43441
  }
46566
43442
 
@@ -46634,8 +43510,78 @@ function generate(ast, opts = {}, code2) {
46634
43510
 
46635
43511
  // node_modules/@babel/traverse/lib/index.js
46636
43512
  var import_debug = __toESM(require_src(), 1);
46637
- var import_module = require('module');
46638
- var import_meta = {};
43513
+
43514
+ // node_modules/@babel/helper-globals/data/builtin-lower.json
43515
+ var builtin_lower_default = [
43516
+ 'decodeURI',
43517
+ 'decodeURIComponent',
43518
+ 'encodeURI',
43519
+ 'encodeURIComponent',
43520
+ 'escape',
43521
+ 'eval',
43522
+ 'globalThis',
43523
+ 'isFinite',
43524
+ 'isNaN',
43525
+ 'parseFloat',
43526
+ 'parseInt',
43527
+ 'undefined',
43528
+ 'unescape',
43529
+ ];
43530
+
43531
+ // node_modules/@babel/helper-globals/data/builtin-upper.json
43532
+ var builtin_upper_default = [
43533
+ 'AggregateError',
43534
+ 'Array',
43535
+ 'ArrayBuffer',
43536
+ 'Atomics',
43537
+ 'BigInt',
43538
+ 'BigInt64Array',
43539
+ 'BigUint64Array',
43540
+ 'Boolean',
43541
+ 'DataView',
43542
+ 'Date',
43543
+ 'Error',
43544
+ 'EvalError',
43545
+ 'FinalizationRegistry',
43546
+ 'Float16Array',
43547
+ 'Float32Array',
43548
+ 'Float64Array',
43549
+ 'Function',
43550
+ 'Infinity',
43551
+ 'Int16Array',
43552
+ 'Int32Array',
43553
+ 'Int8Array',
43554
+ 'Intl',
43555
+ 'Iterator',
43556
+ 'JSON',
43557
+ 'Map',
43558
+ 'Math',
43559
+ 'NaN',
43560
+ 'Number',
43561
+ 'Object',
43562
+ 'Promise',
43563
+ 'Proxy',
43564
+ 'RangeError',
43565
+ 'ReferenceError',
43566
+ 'Reflect',
43567
+ 'RegExp',
43568
+ 'Set',
43569
+ 'SharedArrayBuffer',
43570
+ 'String',
43571
+ 'Symbol',
43572
+ 'SyntaxError',
43573
+ 'TypeError',
43574
+ 'Uint16Array',
43575
+ 'Uint32Array',
43576
+ 'Uint8Array',
43577
+ 'Uint8ClampedArray',
43578
+ 'URIError',
43579
+ 'WeakMap',
43580
+ 'WeakRef',
43581
+ 'WeakSet',
43582
+ ];
43583
+
43584
+ // node_modules/@babel/traverse/lib/index.js
46639
43585
  var ReferencedIdentifier = [
46640
43586
  'Identifier',
46641
43587
  'JSXIdentifier',
@@ -46993,7 +43939,7 @@ function verify$1(visitor) {
46993
43939
  continue;
46994
43940
 
46995
43941
  if (!TYPES2.includes(nodeType)) {
46996
- throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${'8.0.0-beta.1'}`);
43942
+ throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${'8.0.0-beta.2'}`);
46997
43943
  }
46998
43944
 
46999
43945
  const visitors2 = visitor[nodeType];
@@ -47446,9 +44392,6 @@ var cache = /* @__PURE__ */Object.freeze({
47446
44392
  },
47447
44393
  });
47448
44394
 
47449
- var globalsBuiltinLower = require('@babel/helper-globals/data/builtin-lower.json');
47450
- var globalsBuiltinUpper = require('@babel/helper-globals/data/builtin-upper.json');
47451
-
47452
44395
  var {
47453
44396
  assignmentExpression: assignmentExpression$3,
47454
44397
  callExpression: callExpression$3,
@@ -47737,8 +44680,7 @@ var collectorVisitor = {
47737
44680
  },
47738
44681
  },
47739
44682
  LabeledStatement(path) {
47740
- path
47741
- .scope
44683
+ path.scope
47742
44684
  .getBlockParent()
47743
44685
  .registerDeclaration(path);
47744
44686
  },
@@ -48491,7 +45433,8 @@ collectorVisitor]));
48491
45433
  const binding = scope2.getOwnBinding(name);
48492
45434
 
48493
45435
  if (binding) {
48494
- if (previousPath?.isPattern() && binding.kind !== 'param' && binding.kind !== 'local'); else {
45436
+ if (previousPath?.isPattern() && binding.kind !== 'param' && binding.kind !== 'local');
45437
+ else {
48495
45438
  return binding;
48496
45439
  }
48497
45440
  } else if (!binding && name === 'arguments' && scope2.path.isFunction() && !scope2.path.isArrowFunctionExpression()) {
@@ -48643,7 +45586,7 @@ collectorVisitor]));
48643
45586
  }
48644
45587
  };
48645
45588
 
48646
- __publicField(_Scope, 'globals', [...globalsBuiltinLower, ...globalsBuiltinUpper]);
45589
+ __publicField(_Scope, 'globals', [...builtin_lower_default, ...builtin_upper_default]);
48647
45590
  __publicField(_Scope, 'contextVariables', [
48648
45591
  'arguments',
48649
45592
  'undefined',
@@ -48857,6 +45800,7 @@ function infererReference(node) {
48857
45800
  } else if (node.name === 'NaN' || node.name === 'Infinity') {
48858
45801
  return numberTypeAnnotation$1();
48859
45802
  } else if (node.name === 'arguments');
45803
+
48860
45804
  }
48861
45805
 
48862
45806
  function getTypeAnnotationBindingConstantViolations(binding, path, name) {
@@ -49238,6 +46182,7 @@ function resolveCall(callee) {
49238
46182
  return callee.node.returnType;
49239
46183
  } else
49240
46184
  ;
46185
+
49241
46186
  }
49242
46187
  }
49243
46188
  }
@@ -49589,8 +46534,9 @@ function insertBefore(nodes_) {
49589
46534
  } else if (this.isStatementOrBlock()) {
49590
46535
  const node = this.node;
49591
46536
  const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
49592
- this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
49593
- return this.unshiftContainer('body', nodes2);
46537
+ const [blockPath] = this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
46538
+
46539
+ return blockPath.unshiftContainer('body', nodes2);
49594
46540
  } else {
49595
46541
  throw new Error('We don\'t know what to do with this node type. We were previously a Statement but we can\'t fit in here?');
49596
46542
  }
@@ -49708,8 +46654,9 @@ function insertAfter(nodes_) {
49708
46654
  } else if (this.isStatementOrBlock()) {
49709
46655
  const node = this.node;
49710
46656
  const shouldInsertCurrentNode = node && (!this.isExpressionStatement() || node.expression != null);
49711
- this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
49712
- return this.pushContainer('body', nodes2);
46657
+ const [blockPath] = this.replaceWith(blockStatement$2(shouldInsertCurrentNode ? [node] : []));
46658
+
46659
+ return blockPath.pushContainer('body', nodes2);
49713
46660
  } else {
49714
46661
  throw new Error('We don\'t know what to do with this node type. We were previously a Statement but we can\'t fit in here?');
49715
46662
  }
@@ -49768,16 +46715,18 @@ function _verifyNodeList(nodes2) {
49768
46715
 
49769
46716
  function unshiftContainer(listKey, nodes2) {
49770
46717
  _assertUnremoved.call(this);
49771
- nodes2 = _verifyNodeList.call(this, nodes2);
46718
+ const verifiedNodes = _verifyNodeList.call(this, nodes2);
46719
+ const container = this.node[listKey];
46720
+
49772
46721
  const path = NodePath_Final.get({
49773
46722
  parentPath: this,
49774
46723
  parent: this.node,
49775
- container: this.node[listKey],
46724
+ container,
49776
46725
  listKey,
49777
46726
  key: 0,
49778
46727
  }).setContext(this.context);
49779
46728
 
49780
- return _containerInsertBefore.call(path, nodes2);
46729
+ return _containerInsertBefore.call(path, verifiedNodes);
49781
46730
  }
49782
46731
 
49783
46732
  function pushContainer(listKey, nodes2) {
@@ -49829,9 +46778,9 @@ var {
49829
46778
 
49830
46779
  function replaceWithMultiple(nodes2) {
49831
46780
  resync.call(this);
49832
- nodes2 = _verifyNodeList.call(this, nodes2);
49833
- inheritLeadingComments2(nodes2[0], this.node);
49834
- inheritTrailingComments2(nodes2[nodes2.length - 1], this.node);
46781
+ const verifiedNodes = _verifyNodeList.call(this, nodes2);
46782
+ inheritLeadingComments2(verifiedNodes[0], this.node);
46783
+ inheritTrailingComments2(verifiedNodes[verifiedNodes.length - 1], this.node);
49835
46784
  getCachedPaths(this)?.delete(this.node);
49836
46785
  this.node =
49837
46786
  this.container[this.key] = null;