@putout/babel 4.2.0 → 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
@@ -8259,196 +8259,15 @@ function isPrivate(node, opts) {
8259
8259
  return opts == null || shallowEqual(node, opts);
8260
8260
  }
8261
8261
 
8262
- function isFlow(node, opts) {
8263
- if (!node)
8264
- return false;
8265
-
8266
- switch(node.type) {
8267
- case 'AnyTypeAnnotation':
8268
- case 'ArrayTypeAnnotation':
8269
- case 'BooleanTypeAnnotation':
8270
- case 'BooleanLiteralTypeAnnotation':
8271
- case 'NullLiteralTypeAnnotation':
8272
- case 'ClassImplements':
8273
- case 'DeclareClass':
8274
- case 'DeclareFunction':
8275
- case 'DeclareInterface':
8276
- case 'DeclareModule':
8277
- case 'DeclareModuleExports':
8278
- case 'DeclareTypeAlias':
8279
- case 'DeclareOpaqueType':
8280
- case 'DeclareVariable':
8281
- case 'DeclareExportDeclaration':
8282
- case 'DeclareExportAllDeclaration':
8283
- case 'DeclaredPredicate':
8284
- case 'ExistsTypeAnnotation':
8285
- case 'FunctionTypeAnnotation':
8286
- case 'FunctionTypeParam':
8287
- case 'GenericTypeAnnotation':
8288
- case 'InferredPredicate':
8289
- case 'InterfaceExtends':
8290
- case 'InterfaceDeclaration':
8291
- case 'InterfaceTypeAnnotation':
8292
- case 'IntersectionTypeAnnotation':
8293
- case 'MixedTypeAnnotation':
8294
- case 'EmptyTypeAnnotation':
8295
- case 'NullableTypeAnnotation':
8296
- case 'NumberLiteralTypeAnnotation':
8297
- case 'NumberTypeAnnotation':
8298
- case 'ObjectTypeAnnotation':
8299
- case 'ObjectTypeInternalSlot':
8300
- case 'ObjectTypeCallProperty':
8301
- case 'ObjectTypeIndexer':
8302
- case 'ObjectTypeProperty':
8303
- case 'ObjectTypeSpreadProperty':
8304
- case 'OpaqueType':
8305
- case 'QualifiedTypeIdentifier':
8306
- case 'StringLiteralTypeAnnotation':
8307
- case 'StringTypeAnnotation':
8308
- case 'SymbolTypeAnnotation':
8309
- case 'ThisTypeAnnotation':
8310
- case 'TupleTypeAnnotation':
8311
- case 'TypeofTypeAnnotation':
8312
- case 'TypeAlias':
8313
- case 'TypeAnnotation':
8314
- case 'TypeCastExpression':
8315
- case 'TypeParameter':
8316
- case 'TypeParameterDeclaration':
8317
- case 'TypeParameterInstantiation':
8318
- case 'UnionTypeAnnotation':
8319
- case 'Variance':
8320
- case 'VoidTypeAnnotation':
8321
- case 'EnumDeclaration':
8322
- case 'EnumBooleanBody':
8323
- case 'EnumNumberBody':
8324
- case 'EnumStringBody':
8325
- case 'EnumSymbolBody':
8326
- case 'EnumBooleanMember':
8327
- case 'EnumNumberMember':
8328
- case 'EnumStringMember':
8329
- case 'EnumDefaultedMember':
8330
- case 'IndexedAccessType':
8331
- case 'OptionalIndexedAccessType':
8332
- break;
8333
-
8334
- default:
8335
- return false;
8336
- }
8337
-
8338
-
8339
- return opts == null || shallowEqual(node, opts);
8340
- }
8262
+ function isFlow() {}
8341
8263
 
8342
- function isFlowType(node, opts) {
8343
- if (!node)
8344
- return false;
8345
-
8346
- switch(node.type) {
8347
- case 'AnyTypeAnnotation':
8348
- case 'ArrayTypeAnnotation':
8349
- case 'BooleanTypeAnnotation':
8350
- case 'BooleanLiteralTypeAnnotation':
8351
- case 'NullLiteralTypeAnnotation':
8352
- case 'ExistsTypeAnnotation':
8353
- case 'FunctionTypeAnnotation':
8354
- case 'GenericTypeAnnotation':
8355
- case 'InterfaceTypeAnnotation':
8356
- case 'IntersectionTypeAnnotation':
8357
- case 'MixedTypeAnnotation':
8358
- case 'EmptyTypeAnnotation':
8359
- case 'NullableTypeAnnotation':
8360
- case 'NumberLiteralTypeAnnotation':
8361
- case 'NumberTypeAnnotation':
8362
- case 'ObjectTypeAnnotation':
8363
- case 'StringLiteralTypeAnnotation':
8364
- case 'StringTypeAnnotation':
8365
- case 'SymbolTypeAnnotation':
8366
- case 'ThisTypeAnnotation':
8367
- case 'TupleTypeAnnotation':
8368
- case 'TypeofTypeAnnotation':
8369
- case 'UnionTypeAnnotation':
8370
- case 'VoidTypeAnnotation':
8371
- case 'IndexedAccessType':
8372
- case 'OptionalIndexedAccessType':
8373
- break;
8374
-
8375
- default:
8376
- return false;
8377
- }
8378
-
8379
-
8380
- return opts == null || shallowEqual(node, opts);
8381
- }
8264
+ function isFlowType() {}
8382
8265
 
8383
- function isFlowBaseAnnotation(node, opts) {
8384
- if (!node)
8385
- return false;
8386
-
8387
- switch(node.type) {
8388
- case 'AnyTypeAnnotation':
8389
- case 'BooleanTypeAnnotation':
8390
- case 'NullLiteralTypeAnnotation':
8391
- case 'MixedTypeAnnotation':
8392
- case 'EmptyTypeAnnotation':
8393
- case 'NumberTypeAnnotation':
8394
- case 'StringTypeAnnotation':
8395
- case 'SymbolTypeAnnotation':
8396
- case 'ThisTypeAnnotation':
8397
- case 'VoidTypeAnnotation':
8398
- break;
8399
-
8400
- default:
8401
- return false;
8402
- }
8403
-
8404
-
8405
- return opts == null || shallowEqual(node, opts);
8406
- }
8266
+ function isFlowBaseAnnotation() {}
8407
8267
 
8408
- function isFlowDeclaration(node, opts) {
8409
- if (!node)
8410
- return false;
8411
-
8412
- switch(node.type) {
8413
- case 'DeclareClass':
8414
- case 'DeclareFunction':
8415
- case 'DeclareInterface':
8416
- case 'DeclareModule':
8417
- case 'DeclareModuleExports':
8418
- case 'DeclareTypeAlias':
8419
- case 'DeclareOpaqueType':
8420
- case 'DeclareVariable':
8421
- case 'DeclareExportDeclaration':
8422
- case 'DeclareExportAllDeclaration':
8423
- case 'InterfaceDeclaration':
8424
- case 'OpaqueType':
8425
- case 'TypeAlias':
8426
- break;
8427
-
8428
- default:
8429
- return false;
8430
- }
8431
-
8432
-
8433
- return opts == null || shallowEqual(node, opts);
8434
- }
8268
+ function isFlowDeclaration() {}
8435
8269
 
8436
- function isFlowPredicate(node, opts) {
8437
- if (!node)
8438
- return false;
8439
-
8440
- switch(node.type) {
8441
- case 'DeclaredPredicate':
8442
- case 'InferredPredicate':
8443
- break;
8444
-
8445
- default:
8446
- return false;
8447
- }
8448
-
8449
-
8450
- return opts == null || shallowEqual(node, opts);
8451
- }
8270
+ function isFlowPredicate() {}
8452
8271
 
8453
8272
  function isEnumBody(node, opts) {
8454
8273
  if (!node)
@@ -22431,59 +22250,6 @@ var reservedTypes = /* @__PURE__ */new Set([
22431
22250
  'void',
22432
22251
  ]);
22433
22252
 
22434
- var FlowErrors = ParseErrorEnum`flow`({
22435
- AmbiguousConditionalArrow: 'Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.',
22436
- AmbiguousDeclareModuleKind: 'Found both `declare module.exports` and `declare export` in the same module. Modules can only have 1 since they are either an ES module or they are a CommonJS module.',
22437
- AssignReservedType: ({reservedType}) => `Cannot overwrite reserved type ${reservedType}.`,
22438
- DeclareClassElement: 'The `declare` modifier can only appear on class fields.',
22439
- DeclareClassFieldInitializer: 'Initializers are not allowed in fields with the `declare` modifier.',
22440
- DuplicateDeclareModuleExports: 'Duplicate `declare module.exports` statement.',
22441
- EnumBooleanMemberNotInitialized: ({memberName, enumName}) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
22442
- EnumDuplicateMemberName: ({memberName, enumName}) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
22443
- EnumInconsistentMemberValues: ({enumName}) => `Enum \`${enumName}\` has inconsistent member initializers. Either use no initializers, or consistently use literals (either booleans, numbers, or strings) for all member initializers.`,
22444
- EnumInvalidExplicitType: ({invalidEnumType, enumName}) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
22445
- EnumInvalidExplicitTypeUnknownSupplied: ({enumName}) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
22446
- EnumInvalidMemberInitializerPrimaryType: ({enumName, memberName, explicitType}) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
22447
- EnumInvalidMemberInitializerSymbolType: ({enumName, memberName}) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
22448
- EnumInvalidMemberInitializerUnknownType: ({enumName, memberName}) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
22449
- EnumInvalidMemberName: ({enumName, memberName, suggestion}) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
22450
- EnumNumberMemberNotInitialized: ({enumName, memberName}) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
22451
- EnumStringMemberInconsistentlyInitialized: ({enumName}) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
22452
- GetterMayNotHaveThisParam: 'A getter cannot have a `this` parameter.',
22453
- ImportReflectionHasImportType: 'An `import module` declaration can not use `type` or `typeof` keyword.',
22454
- ImportTypeShorthandOnlyInPureImport: 'The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements.',
22455
- InexactInsideExact: 'Explicit inexact syntax cannot appear inside an explicit exact object type.',
22456
- InexactInsideNonObject: 'Explicit inexact syntax cannot appear in class or interface definitions.',
22457
- InexactVariance: 'Explicit inexact syntax cannot have variance.',
22458
- InvalidNonTypeImportInDeclareModule: 'Imports within a `declare module` body must always be `import type` or `import typeof`.',
22459
- MissingTypeParamDefault: 'Type parameter declaration needs a default, since a preceding type parameter declaration has a default.',
22460
- NestedDeclareModule: '`declare module` cannot be used inside another `declare module`.',
22461
- NestedFlowComment: 'Cannot have a flow comment inside another flow comment.',
22462
- PatternIsOptional: Object.assign({
22463
- message: 'A binding pattern parameter cannot be optional in an implementation signature.',
22464
- }, {}),
22465
- SetterMayNotHaveThisParam: 'A setter cannot have a `this` parameter.',
22466
- SpreadVariance: 'Spread properties cannot have variance.',
22467
- ThisParamAnnotationRequired: 'A type annotation is required for the `this` parameter.',
22468
- ThisParamBannedInConstructor: 'Constructors cannot have a `this` parameter; constructors don\'t bind `this` like other functions.',
22469
- ThisParamMayNotBeOptional: 'The `this` parameter cannot be optional.',
22470
- ThisParamMustBeFirst: 'The `this` parameter must be the first function parameter.',
22471
- ThisParamNoDefault: 'The `this` parameter may not have a default value.',
22472
- TypeBeforeInitializer: 'Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.',
22473
- TypeCastInPattern: 'The type cast expression is expected to be wrapped with parenthesis.',
22474
- UnexpectedExplicitInexactInObject: 'Explicit inexact syntax must appear at the end of an inexact object.',
22475
- UnexpectedReservedType: ({reservedType}) => `Unexpected reserved type ${reservedType}.`,
22476
- UnexpectedReservedUnderscore: '`_` is only allowed as a type argument to call or new.',
22477
- UnexpectedSpaceBetweenModuloChecks: 'Spaces between `%` and `checks` are not allowed here.',
22478
- UnexpectedSpreadType: 'Spread operator cannot appear in class or interface definitions.',
22479
- UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
22480
- UnexpectedTokenAfterTypeParameter: 'Expected an arrow function after this type parameter declaration.',
22481
- UnexpectedTypeParameterBeforeAsyncArrowFunction: 'Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.',
22482
- UnsupportedDeclareExportKind: ({unsupportedExportKind, suggestion}) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
22483
- UnsupportedStatementInDeclareModule: 'Only declares and type imports are allowed inside declare module.',
22484
- UnterminatedFlowComment: 'Unterminated flow-comment.',
22485
- });
22486
-
22487
22253
  function isEsModuleType(bodyElement) {
22488
22254
  return bodyElement.type === 'DeclareExportAllDeclaration'
22489
22255
  || bodyElement.type === 'DeclareExportDeclaration'
@@ -22516,2893 +22282,6 @@ function partition(list, test) {
22516
22282
 
22517
22283
  var FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
22518
22284
 
22519
- var flow = (superClass) => class FlowParserMixin extends superClass {
22520
- constructor() {
22521
- super(...arguments);
22522
- __publicField(this, 'flowPragma');
22523
- }
22524
-
22525
- getScopeHandler() {
22526
- return FlowScopeHandler;
22527
- }
22528
-
22529
- shouldParseTypes() {
22530
- return this.getPluginOption('flow', 'all') || this.flowPragma === 'flow';
22531
- }
22532
-
22533
- finishToken(type, val) {
22534
- if (type !== 134 && type !== 13 && type !== 28) {
22535
- if (this.flowPragma === void 0) {
22536
- this.flowPragma = null;
22537
- }
22538
- }
22539
-
22540
- super.finishToken(type, val);
22541
- }
22542
-
22543
- addComment(comment) {
22544
- if (this.flowPragma === void 0) {
22545
- const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
22546
-
22547
- if (!matches);
22548
- else if (matches[1] === 'flow') {
22549
- this.flowPragma = 'flow';
22550
- } else if (matches[1] === 'noflow') {
22551
- this.flowPragma = 'noflow';
22552
- } else {
22553
- throw new Error('Unexpected flow pragma');
22554
- }
22555
-
22556
- }
22557
-
22558
- super.addComment(comment);
22559
- }
22560
-
22561
- flowParseTypeInitialiser(tok) {
22562
- const oldInType = this.state.inType;
22563
-
22564
- this.state.inType = true;
22565
- this.expect(tok || 14);
22566
- const type = this.flowParseType();
22567
-
22568
- this.state.inType = oldInType;
22569
- return type;
22570
- }
22571
-
22572
- flowParsePredicate() {
22573
- const node = this.startNode();
22574
- const moduloLoc = this.state.startLoc;
22575
- this.next();
22576
- this.expectContextual(110);
22577
-
22578
- if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
22579
- this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
22580
- }
22581
-
22582
- if (this.eat(10)) {
22583
- node.value = super.parseExpression();
22584
- this.expect(11);
22585
- return this.finishNode(node, 'DeclaredPredicate');
22586
- } else {
22587
- return this.finishNode(node, 'InferredPredicate');
22588
- }
22589
- }
22590
-
22591
- flowParseTypeAndPredicateInitialiser() {
22592
- const oldInType = this.state.inType;
22593
-
22594
- this.state.inType = true;
22595
- this.expect(14);
22596
- let type = null;
22597
- let predicate = null;
22598
-
22599
- if (this.match(54)) {
22600
- this.state.inType = oldInType;
22601
- predicate = this.flowParsePredicate();
22602
- } else {
22603
- type = this.flowParseType();
22604
- this.state.inType = oldInType;
22605
-
22606
- if (this.match(54)) {
22607
- predicate = this.flowParsePredicate();
22608
- }
22609
- }
22610
-
22611
- return [type, predicate];
22612
- }
22613
-
22614
- flowParseDeclareClass(node) {
22615
- this.next();
22616
- this.flowParseInterfaceish(node, true);
22617
- return this.finishNode(node, 'DeclareClass');
22618
- }
22619
-
22620
- flowParseDeclareFunction(node) {
22621
- this.next();
22622
- const id = node.id = this.parseIdentifier();
22623
- const typeNode = this.startNode();
22624
- const typeContainer = this.startNode();
22625
-
22626
- if (this.match(47)) {
22627
- typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
22628
- } else {
22629
- typeNode.typeParameters = null;
22630
- }
22631
-
22632
- this.expect(10);
22633
- const tmp = this.flowParseFunctionTypeParams();
22634
-
22635
- typeNode.params = tmp.params;
22636
- typeNode.rest = tmp.rest;
22637
- typeNode.this = tmp._this;
22638
- this.expect(11);
22639
- [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
22640
- typeContainer.typeAnnotation = this.finishNode(typeNode, 'FunctionTypeAnnotation');
22641
- id.typeAnnotation = this.finishNode(typeContainer, 'TypeAnnotation');
22642
- this.resetEndLocation(id);
22643
- this.semicolon();
22644
- this.scope.declareName(node.id.name, 2048, node.id.loc.start);
22645
- return this.finishNode(node, 'DeclareFunction');
22646
- }
22647
-
22648
- flowParseDeclare(node, insideModule) {
22649
- if (this.match(80)) {
22650
- return this.flowParseDeclareClass(node);
22651
- } else if (this.match(68)) {
22652
- return this.flowParseDeclareFunction(node);
22653
- } else if (this.match(74)) {
22654
- return this.flowParseDeclareVariable(node);
22655
- } else if (this.eatContextual(127)) {
22656
- if (this.match(16)) {
22657
- return this.flowParseDeclareModuleExports(node);
22658
- } else {
22659
- if (insideModule) {
22660
- this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
22661
- }
22662
-
22663
- return this.flowParseDeclareModule(node);
22664
- }
22665
- } else if (this.isContextual(130)) {
22666
- return this.flowParseDeclareTypeAlias(node);
22667
- } else if (this.isContextual(131)) {
22668
- return this.flowParseDeclareOpaqueType(node);
22669
- } else if (this.isContextual(129)) {
22670
- return this.flowParseDeclareInterface(node);
22671
- } else if (this.match(82)) {
22672
- return this.flowParseDeclareExportDeclaration(node, insideModule);
22673
- } else {
22674
- this.unexpected();
22675
- }
22676
-
22677
-
22678
-
22679
-
22680
-
22681
-
22682
- }
22683
-
22684
- flowParseDeclareVariable(node) {
22685
- this.next();
22686
- node.id = this.flowParseTypeAnnotatableIdentifier(true);
22687
- this.scope.declareName(node.id.name, 5, node.id.loc.start);
22688
- this.semicolon();
22689
- return this.finishNode(node, 'DeclareVariable');
22690
- }
22691
-
22692
- flowParseDeclareModule(node) {
22693
- this.scope.enter(0);
22694
-
22695
- if (this.match(134)) {
22696
- node.id = super.parseExprAtom();
22697
- } else {
22698
- node.id = this.parseIdentifier();
22699
- }
22700
-
22701
- const bodyNode = node.body = this.startNode();
22702
- const body = bodyNode.body = [];
22703
-
22704
- this.expect(5);
22705
- while (!this.match(8)) {
22706
- let bodyNode2 = this.startNode();
22707
-
22708
- if (this.match(83)) {
22709
- this.next();
22710
-
22711
- if (!this.isContextual(130) && !this.match(87)) {
22712
- this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
22713
- }
22714
-
22715
- super.parseImport(bodyNode2);
22716
- } else {
22717
- this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
22718
- bodyNode2 = this.flowParseDeclare(bodyNode2, true);
22719
- }
22720
-
22721
- body.push(bodyNode2);
22722
- }
22723
-
22724
- this.scope.exit();
22725
- this.expect(8);
22726
- this.finishNode(bodyNode, 'BlockStatement');
22727
- let kind = null;
22728
- let hasModuleExport = false;
22729
-
22730
- body.forEach((bodyElement) => {
22731
- if (isEsModuleType(bodyElement)) {
22732
- if (kind === 'CommonJS') {
22733
- this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
22734
- }
22735
-
22736
- kind = 'ES';
22737
- } else if (bodyElement.type === 'DeclareModuleExports') {
22738
- if (hasModuleExport) {
22739
- this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
22740
- }
22741
-
22742
- if (kind === 'ES') {
22743
- this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
22744
- }
22745
-
22746
- kind = 'CommonJS';
22747
- hasModuleExport = true;
22748
- }
22749
- });
22750
- node.kind = kind || 'CommonJS';
22751
- return this.finishNode(node, 'DeclareModule');
22752
- }
22753
-
22754
- flowParseDeclareExportDeclaration(node, insideModule) {
22755
- this.expect(82);
22756
-
22757
- if (this.eat(65)) {
22758
- if (this.match(68) || this.match(80)) {
22759
- node.declaration = this.flowParseDeclare(this.startNode());
22760
- } else {
22761
- node.declaration = this.flowParseType();
22762
- this.semicolon();
22763
- }
22764
-
22765
- node.default = true;
22766
- return this.finishNode(node, 'DeclareExportDeclaration');
22767
- } else {
22768
- if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
22769
- const label = this.state.value;
22770
-
22771
- throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
22772
- unsupportedExportKind: label,
22773
- suggestion: exportSuggestions[label],
22774
- });
22775
- }
22776
-
22777
- if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
22778
- node.declaration = this.flowParseDeclare(this.startNode());
22779
- node.default = false;
22780
- return this.finishNode(node, 'DeclareExportDeclaration');
22781
- } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
22782
- node = this.parseExport(node, null);
22783
-
22784
- if (node.type === 'ExportNamedDeclaration') {
22785
- node.default = false;
22786
- delete node.exportKind;
22787
- return this.castNodeTo(node, 'DeclareExportDeclaration');
22788
- } else {
22789
- return this.castNodeTo(node, 'DeclareExportAllDeclaration');
22790
- }
22791
- }
22792
- }
22793
-
22794
- this.unexpected();
22795
- }
22796
-
22797
- flowParseDeclareModuleExports(node) {
22798
- this.next();
22799
- this.expectContextual(111);
22800
- node.typeAnnotation = this.flowParseTypeAnnotation();
22801
- this.semicolon();
22802
- return this.finishNode(node, 'DeclareModuleExports');
22803
- }
22804
-
22805
- flowParseDeclareTypeAlias(node) {
22806
- this.next();
22807
- const finished = this.flowParseTypeAlias(node);
22808
- this.castNodeTo(finished, 'DeclareTypeAlias');
22809
- return finished;
22810
- }
22811
-
22812
- flowParseDeclareOpaqueType(node) {
22813
- this.next();
22814
- const finished = this.flowParseOpaqueType(node, true);
22815
- this.castNodeTo(finished, 'DeclareOpaqueType');
22816
- return finished;
22817
- }
22818
-
22819
- flowParseDeclareInterface(node) {
22820
- this.next();
22821
- this.flowParseInterfaceish(node, false);
22822
- return this.finishNode(node, 'DeclareInterface');
22823
- }
22824
-
22825
- flowParseInterfaceish(node, isClass3) {
22826
- node.id = this.flowParseRestrictedIdentifier(!isClass3, true);
22827
- this.scope.declareName(node.id.name, isClass3 ? 17 : 8201, node.id.loc.start);
22828
-
22829
- if (this.match(47)) {
22830
- node.typeParameters = this.flowParseTypeParameterDeclaration();
22831
- } else {
22832
- node.typeParameters = null;
22833
- }
22834
-
22835
- node.extends = [];
22836
-
22837
- if (this.eat(81)) {
22838
- do {
22839
- node.extends.push(this.flowParseInterfaceExtends());
22840
- } while (!isClass3 && this.eat(12))
22841
- }
22842
-
22843
- if (isClass3) {
22844
- node.implements = [];
22845
- node.mixins = [];
22846
-
22847
- if (this.eatContextual(117)) {
22848
- do {
22849
- node.mixins.push(this.flowParseInterfaceExtends());
22850
- } while (this.eat(12))
22851
- }
22852
-
22853
- if (this.eatContextual(113)) {
22854
- do {
22855
- node.implements.push(this.flowParseInterfaceExtends());
22856
- } while (this.eat(12))
22857
- }
22858
- }
22859
-
22860
- node.body = this.flowParseObjectType({
22861
- allowStatic: isClass3,
22862
- allowExact: false,
22863
- allowSpread: false,
22864
- allowProto: isClass3,
22865
- allowInexact: false,
22866
- });
22867
- }
22868
-
22869
- flowParseInterfaceExtends() {
22870
- const node = this.startNode();
22871
-
22872
- node.id = this.flowParseQualifiedTypeIdentifier();
22873
-
22874
- if (this.match(47)) {
22875
- node.typeParameters = this.flowParseTypeParameterInstantiation();
22876
- } else {
22877
- node.typeParameters = null;
22878
- }
22879
-
22880
- return this.finishNode(node, 'InterfaceExtends');
22881
- }
22882
-
22883
- flowParseInterface(node) {
22884
- this.flowParseInterfaceish(node, false);
22885
- return this.finishNode(node, 'InterfaceDeclaration');
22886
- }
22887
-
22888
- checkNotUnderscore(word) {
22889
- if (word === '_') {
22890
- this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
22891
- }
22892
- }
22893
-
22894
- checkReservedType(word, startLoc, declaration) {
22895
- if (!reservedTypes.has(word))
22896
- return;
22897
-
22898
- this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
22899
- reservedType: word,
22900
- });
22901
- }
22902
-
22903
- flowParseRestrictedIdentifier(liberal, declaration) {
22904
- this.checkReservedType(this.state.value, this.state.startLoc, declaration);
22905
- return this.parseIdentifier(liberal);
22906
- }
22907
-
22908
- flowParseTypeAlias(node) {
22909
- node.id = this.flowParseRestrictedIdentifier(false, true);
22910
- this.scope.declareName(node.id.name, 8201, node.id.loc.start);
22911
-
22912
- if (this.match(47)) {
22913
- node.typeParameters = this.flowParseTypeParameterDeclaration();
22914
- } else {
22915
- node.typeParameters = null;
22916
- }
22917
-
22918
- node.right = this.flowParseTypeInitialiser(29);
22919
- this.semicolon();
22920
- return this.finishNode(node, 'TypeAlias');
22921
- }
22922
-
22923
- flowParseOpaqueType(node, declare) {
22924
- this.expectContextual(130);
22925
- node.id = this.flowParseRestrictedIdentifier(true, true);
22926
- this.scope.declareName(node.id.name, 8201, node.id.loc.start);
22927
-
22928
- if (this.match(47)) {
22929
- node.typeParameters = this.flowParseTypeParameterDeclaration();
22930
- } else {
22931
- node.typeParameters = null;
22932
- }
22933
-
22934
- node.supertype = null;
22935
-
22936
- if (this.match(14)) {
22937
- node.supertype = this.flowParseTypeInitialiser(14);
22938
- }
22939
-
22940
- node.impltype = null;
22941
-
22942
- if (!declare) {
22943
- node.impltype = this.flowParseTypeInitialiser(29);
22944
- }
22945
-
22946
- this.semicolon();
22947
- return this.finishNode(node, 'OpaqueType');
22948
- }
22949
-
22950
- flowParseTypeParameter(requireDefault = false) {
22951
- const nodeStartLoc = this.state.startLoc;
22952
- const node = this.startNode();
22953
- const variance2 = this.flowParseVariance();
22954
- const ident = this.flowParseTypeAnnotatableIdentifier();
22955
-
22956
- node.name = ident.name;
22957
- node.variance = variance2;
22958
- node.bound = ident.typeAnnotation;
22959
-
22960
- if (this.match(29)) {
22961
- this.eat(29);
22962
- node.default = this.flowParseType();
22963
- } else {
22964
- if (requireDefault) {
22965
- this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
22966
- }
22967
- }
22968
-
22969
- return this.finishNode(node, 'TypeParameter');
22970
- }
22971
-
22972
- flowParseTypeParameterDeclaration() {
22973
- const oldInType = this.state.inType;
22974
- const node = this.startNode();
22975
-
22976
- node.params = [];
22977
- this.state.inType = true;
22978
-
22979
- if (this.match(47) || this.match(143)) {
22980
- this.next();
22981
- } else {
22982
- this.unexpected();
22983
- }
22984
-
22985
- let defaultRequired = false;
22986
-
22987
- do {
22988
- const typeParameter2 = this.flowParseTypeParameter(defaultRequired);
22989
- node.params.push(typeParameter2);
22990
-
22991
- if (typeParameter2.default) {
22992
- defaultRequired = true;
22993
- }
22994
-
22995
- if (!this.match(48)) {
22996
- this.expect(12);
22997
- }
22998
- } while (!this.match(48))
22999
- this.expect(48);
23000
- this.state.inType = oldInType;
23001
- return this.finishNode(node, 'TypeParameterDeclaration');
23002
- }
23003
-
23004
- flowInTopLevelContext(cb) {
23005
- if (this.curContext() !== types.brace) {
23006
- const oldContext = this.state.context;
23007
-
23008
- this.state.context = [oldContext[0]];
23009
- try {
23010
- return cb();
23011
- } finally {
23012
- this.state.context = oldContext;
23013
- }
23014
- } else {
23015
- return cb();
23016
- }
23017
- }
23018
-
23019
- flowParseTypeParameterInstantiationInExpression() {
23020
- if (this.reScan_lt() !== 47)
23021
- return;
23022
-
23023
- return this.flowParseTypeParameterInstantiation();
23024
- }
23025
-
23026
- flowParseTypeParameterInstantiation() {
23027
- const node = this.startNode();
23028
- const oldInType = this.state.inType;
23029
-
23030
- this.state.inType = true;
23031
- node.params = [];
23032
- this.flowInTopLevelContext(() => {
23033
- this.expect(47);
23034
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
23035
-
23036
- this.state.noAnonFunctionType = false;
23037
- while (!this.match(48)) {
23038
- node.params.push(this.flowParseType());
23039
-
23040
- if (!this.match(48)) {
23041
- this.expect(12);
23042
- }
23043
- }
23044
-
23045
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
23046
- });
23047
- this.state.inType = oldInType;
23048
-
23049
- if (!this.state.inType && this.curContext() === types.brace) {
23050
- this.reScan_lt_gt();
23051
- }
23052
-
23053
- this.expect(48);
23054
- return this.finishNode(node, 'TypeParameterInstantiation');
23055
- }
23056
-
23057
- flowParseTypeParameterInstantiationCallOrNew() {
23058
- if (this.reScan_lt() !== 47)
23059
- return;
23060
-
23061
- const node = this.startNode();
23062
- const oldInType = this.state.inType;
23063
-
23064
- node.params = [];
23065
- this.state.inType = true;
23066
- this.expect(47);
23067
- while (!this.match(48)) {
23068
- node.params.push(this.flowParseTypeOrImplicitInstantiation());
23069
-
23070
- if (!this.match(48)) {
23071
- this.expect(12);
23072
- }
23073
- }
23074
-
23075
- this.expect(48);
23076
- this.state.inType = oldInType;
23077
- return this.finishNode(node, 'TypeParameterInstantiation');
23078
- }
23079
-
23080
- flowParseInterfaceType() {
23081
- const node = this.startNode();
23082
- this.expectContextual(129);
23083
- node.extends = [];
23084
-
23085
- if (this.eat(81)) {
23086
- do {
23087
- node.extends.push(this.flowParseInterfaceExtends());
23088
- } while (this.eat(12))
23089
- }
23090
-
23091
- node.body = this.flowParseObjectType({
23092
- allowStatic: false,
23093
- allowExact: false,
23094
- allowSpread: false,
23095
- allowProto: false,
23096
- allowInexact: false,
23097
- });
23098
- return this.finishNode(node, 'InterfaceTypeAnnotation');
23099
- }
23100
-
23101
- flowParseObjectPropertyKey() {
23102
- return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
23103
- }
23104
-
23105
- flowParseObjectTypeIndexer(node, isStatic2, variance2) {
23106
- node.static = isStatic2;
23107
-
23108
- if (this.lookahead().type === 14) {
23109
- node.id = this.flowParseObjectPropertyKey();
23110
- node.key = this.flowParseTypeInitialiser();
23111
- } else {
23112
- node.id = null;
23113
- node.key = this.flowParseType();
23114
- }
23115
-
23116
- this.expect(3);
23117
- node.value = this.flowParseTypeInitialiser();
23118
- node.variance = variance2;
23119
- return this.finishNode(node, 'ObjectTypeIndexer');
23120
- }
23121
-
23122
- flowParseObjectTypeInternalSlot(node, isStatic2) {
23123
- node.static = isStatic2;
23124
- node.id = this.flowParseObjectPropertyKey();
23125
- this.expect(3);
23126
- this.expect(3);
23127
-
23128
- if (this.match(47) || this.match(10)) {
23129
- node.method = true;
23130
- node.optional = false;
23131
- node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
23132
- } else {
23133
- node.method = false;
23134
-
23135
- if (this.eat(17)) {
23136
- node.optional = true;
23137
- }
23138
-
23139
- node.value = this.flowParseTypeInitialiser();
23140
- }
23141
-
23142
- return this.finishNode(node, 'ObjectTypeInternalSlot');
23143
- }
23144
-
23145
- flowParseObjectTypeMethodish(node) {
23146
- node.params = [];
23147
- node.rest = null;
23148
- node.typeParameters = null;
23149
- node.this = null;
23150
-
23151
- if (this.match(47)) {
23152
- node.typeParameters = this.flowParseTypeParameterDeclaration();
23153
- }
23154
-
23155
- this.expect(10);
23156
-
23157
- if (this.match(78)) {
23158
- node.this = this.flowParseFunctionTypeParam(true);
23159
- node.this.name = null;
23160
-
23161
- if (!this.match(11)) {
23162
- this.expect(12);
23163
- }
23164
- }
23165
-
23166
- while (!this.match(11) && !this.match(21)) {
23167
- node.params.push(this.flowParseFunctionTypeParam(false));
23168
-
23169
- if (!this.match(11)) {
23170
- this.expect(12);
23171
- }
23172
- }
23173
-
23174
- if (this.eat(21)) {
23175
- node.rest = this.flowParseFunctionTypeParam(false);
23176
- }
23177
-
23178
- this.expect(11);
23179
- node.returnType = this.flowParseTypeInitialiser();
23180
- return this.finishNode(node, 'FunctionTypeAnnotation');
23181
- }
23182
-
23183
- flowParseObjectTypeCallProperty(node, isStatic2) {
23184
- const valueNode = this.startNode();
23185
-
23186
- node.static = isStatic2;
23187
- node.value = this.flowParseObjectTypeMethodish(valueNode);
23188
- return this.finishNode(node, 'ObjectTypeCallProperty');
23189
- }
23190
-
23191
- flowParseObjectType({allowStatic, allowExact, allowSpread, allowProto, allowInexact}) {
23192
- const oldInType = this.state.inType;
23193
-
23194
- this.state.inType = true;
23195
- const nodeStart = this.startNode();
23196
-
23197
- nodeStart.callProperties = [];
23198
- nodeStart.properties = [];
23199
- nodeStart.indexers = [];
23200
- nodeStart.internalSlots = [];
23201
- let endDelim;
23202
- let exact;
23203
- let inexact = false;
23204
-
23205
- if (allowExact && this.match(6)) {
23206
- this.expect(6);
23207
- endDelim = 9;
23208
- exact = true;
23209
- } else {
23210
- this.expect(5);
23211
- endDelim = 8;
23212
- exact = false;
23213
- }
23214
-
23215
- nodeStart.exact = exact;
23216
- while (!this.match(endDelim)) {
23217
- let isStatic2 = false;
23218
- let protoStartLoc = null;
23219
- let inexactStartLoc = null;
23220
- const node = this.startNode();
23221
-
23222
- if (allowProto && this.isContextual(118)) {
23223
- const lookahead = this.lookahead();
23224
-
23225
- if (lookahead.type !== 14 && lookahead.type !== 17) {
23226
- this.next();
23227
- protoStartLoc = this.state.startLoc;
23228
- allowStatic = false;
23229
- }
23230
- }
23231
-
23232
- if (allowStatic && this.isContextual(106)) {
23233
- const lookahead = this.lookahead();
23234
-
23235
- if (lookahead.type !== 14 && lookahead.type !== 17) {
23236
- this.next();
23237
- isStatic2 = true;
23238
- }
23239
- }
23240
-
23241
- const variance2 = this.flowParseVariance();
23242
-
23243
- if (this.eat(0)) {
23244
- if (protoStartLoc != null) {
23245
- this.unexpected(protoStartLoc);
23246
- }
23247
-
23248
- if (this.eat(0)) {
23249
- if (variance2) {
23250
- this.unexpected(variance2.loc.start);
23251
- }
23252
-
23253
- nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic2));
23254
- } else {
23255
- nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic2, variance2));
23256
- }
23257
- } else if (this.match(10) || this.match(47)) {
23258
- if (protoStartLoc != null) {
23259
- this.unexpected(protoStartLoc);
23260
- }
23261
-
23262
- if (variance2) {
23263
- this.unexpected(variance2.loc.start);
23264
- }
23265
-
23266
- nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic2));
23267
- } else {
23268
- let kind = 'init';
23269
-
23270
- if (this.isContextual(99) || this.isContextual(104)) {
23271
- const lookahead = this.lookahead();
23272
-
23273
- if (tokenIsLiteralPropertyName(lookahead.type)) {
23274
- kind = this.state.value;
23275
- this.next();
23276
- }
23277
- }
23278
-
23279
- const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic2, protoStartLoc, variance2, kind, allowSpread, allowInexact ?? !exact);
23280
-
23281
- if (propOrInexact === null) {
23282
- inexact = true;
23283
- inexactStartLoc = this.state.lastTokStartLoc;
23284
- } else {
23285
- nodeStart.properties.push(propOrInexact);
23286
- }
23287
- }
23288
-
23289
- this.flowObjectTypeSemicolon();
23290
-
23291
- if (inexactStartLoc && !this.match(8) && !this.match(9)) {
23292
- this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
23293
- }
23294
- }
23295
-
23296
- this.expect(endDelim);
23297
-
23298
- if (allowSpread) {
23299
- nodeStart.inexact = inexact;
23300
- }
23301
-
23302
- const out = this.finishNode(nodeStart, 'ObjectTypeAnnotation');
23303
-
23304
- this.state.inType = oldInType;
23305
- return out;
23306
- }
23307
-
23308
- flowParseObjectTypeProperty(node, isStatic2, protoStartLoc, variance2, kind, allowSpread, allowInexact) {
23309
- if (this.eat(21)) {
23310
- const isInexactToken = this.match(12)
23311
- || this.match(13)
23312
- || this.match(8)
23313
- || this.match(9);
23314
-
23315
- if (isInexactToken) {
23316
- if (!allowSpread) {
23317
- this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
23318
- } else if (!allowInexact) {
23319
- this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
23320
- }
23321
-
23322
- if (variance2) {
23323
- this.raise(FlowErrors.InexactVariance, variance2);
23324
- }
23325
-
23326
- return null;
23327
- }
23328
-
23329
- if (!allowSpread) {
23330
- this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
23331
- }
23332
-
23333
- if (protoStartLoc != null) {
23334
- this.unexpected(protoStartLoc);
23335
- }
23336
-
23337
- if (variance2) {
23338
- this.raise(FlowErrors.SpreadVariance, variance2);
23339
- }
23340
-
23341
- node.argument = this.flowParseType();
23342
- return this.finishNode(node, 'ObjectTypeSpreadProperty');
23343
- } else {
23344
- node.key = this.flowParseObjectPropertyKey();
23345
- node.static = isStatic2;
23346
- node.proto = protoStartLoc != null;
23347
- node.kind = kind;
23348
- let optional = false;
23349
-
23350
- if (this.match(47) || this.match(10)) {
23351
- node.method = true;
23352
-
23353
- if (protoStartLoc != null) {
23354
- this.unexpected(protoStartLoc);
23355
- }
23356
-
23357
- if (variance2) {
23358
- this.unexpected(variance2.loc.start);
23359
- }
23360
-
23361
- node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
23362
-
23363
- if (kind === 'get' || kind === 'set') {
23364
- this.flowCheckGetterSetterParams(node);
23365
- }
23366
-
23367
- if (!allowSpread && node.key.name === 'constructor' && node.value.this) {
23368
- this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
23369
- }
23370
- } else {
23371
- if (kind !== 'init')
23372
- this.unexpected();
23373
-
23374
- node.method = false;
23375
-
23376
- if (this.eat(17)) {
23377
- optional = true;
23378
- }
23379
-
23380
- node.value = this.flowParseTypeInitialiser();
23381
- node.variance = variance2;
23382
- }
23383
-
23384
- node.optional = optional;
23385
- return this.finishNode(node, 'ObjectTypeProperty');
23386
- }
23387
- }
23388
-
23389
- flowCheckGetterSetterParams(property) {
23390
- const paramCount = property.kind === 'get' ? 0 : 1;
23391
- const length = property.value.params.length + (property.value.rest ? 1 : 0);
23392
-
23393
- if (property.value.this) {
23394
- this.raise(property.kind === 'get' ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
23395
- }
23396
-
23397
- if (length !== paramCount) {
23398
- this.raise(property.kind === 'get' ? Errors.BadGetterArity : Errors.BadSetterArity, property);
23399
- }
23400
-
23401
- if (property.kind === 'set' && property.value.rest) {
23402
- this.raise(Errors.BadSetterRestParameter, property);
23403
- }
23404
- }
23405
-
23406
- flowObjectTypeSemicolon() {
23407
- if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
23408
- this.unexpected();
23409
- }
23410
- }
23411
-
23412
- flowParseQualifiedTypeIdentifier(startLoc, id) {
23413
- startLoc ?? (startLoc = this.state.startLoc);
23414
- let node = id || this.flowParseRestrictedIdentifier(true);
23415
-
23416
- while (this.eat(16)) {
23417
- const node2 = this.startNodeAt(startLoc);
23418
-
23419
- node2.qualification = node;
23420
- node2.id = this.flowParseRestrictedIdentifier(true);
23421
- node = this.finishNode(node2, 'QualifiedTypeIdentifier');
23422
- }
23423
-
23424
- return node;
23425
- }
23426
-
23427
- flowParseGenericType(startLoc, id) {
23428
- const node = this.startNodeAt(startLoc);
23429
-
23430
- node.typeParameters = null;
23431
- node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
23432
-
23433
- if (this.match(47)) {
23434
- node.typeParameters = this.flowParseTypeParameterInstantiation();
23435
- }
23436
-
23437
- return this.finishNode(node, 'GenericTypeAnnotation');
23438
- }
23439
-
23440
- flowParseTypeofType() {
23441
- const node = this.startNode();
23442
- this.expect(87);
23443
- node.argument = this.flowParsePrimaryType();
23444
- return this.finishNode(node, 'TypeofTypeAnnotation');
23445
- }
23446
-
23447
- flowParseTupleType() {
23448
- const node = this.startNode();
23449
-
23450
- node.types = [];
23451
- this.expect(0);
23452
- while (this.state.pos < this.length && !this.match(3)) {
23453
- node.types.push(this.flowParseType());
23454
-
23455
- if (this.match(3))
23456
- break;
23457
-
23458
- this.expect(12);
23459
- }
23460
-
23461
- this.expect(3);
23462
- return this.finishNode(node, 'TupleTypeAnnotation');
23463
- }
23464
-
23465
- flowParseFunctionTypeParam(first) {
23466
- let name = null;
23467
- let optional = false;
23468
- let typeAnnotation2 = null;
23469
- const node = this.startNode();
23470
- const lh = this.lookahead();
23471
- const isThis = this.state.type === 78;
23472
-
23473
- if (lh.type === 14 || lh.type === 17) {
23474
- if (isThis && !first) {
23475
- this.raise(FlowErrors.ThisParamMustBeFirst, node);
23476
- }
23477
-
23478
- name = this.parseIdentifier(isThis);
23479
-
23480
- if (this.eat(17)) {
23481
- optional = true;
23482
-
23483
- if (isThis) {
23484
- this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
23485
- }
23486
- }
23487
-
23488
- typeAnnotation2 = this.flowParseTypeInitialiser();
23489
- } else {
23490
- typeAnnotation2 = this.flowParseType();
23491
- }
23492
-
23493
- node.name = name;
23494
- node.optional = optional;
23495
- node.typeAnnotation = typeAnnotation2;
23496
- return this.finishNode(node, 'FunctionTypeParam');
23497
- }
23498
-
23499
- reinterpretTypeAsFunctionTypeParam(type) {
23500
- const node = this.startNodeAt(type.loc.start);
23501
-
23502
- node.name = null;
23503
- node.optional = false;
23504
- node.typeAnnotation = type;
23505
- return this.finishNode(node, 'FunctionTypeParam');
23506
- }
23507
-
23508
- flowParseFunctionTypeParams(params = []) {
23509
- let rest = null;
23510
- let _this = null;
23511
-
23512
- if (this.match(78)) {
23513
- _this = this.flowParseFunctionTypeParam(true);
23514
- _this.name = null;
23515
-
23516
- if (!this.match(11)) {
23517
- this.expect(12);
23518
- }
23519
- }
23520
-
23521
- while (!this.match(11) && !this.match(21)) {
23522
- params.push(this.flowParseFunctionTypeParam(false));
23523
-
23524
- if (!this.match(11)) {
23525
- this.expect(12);
23526
- }
23527
- }
23528
-
23529
- if (this.eat(21)) {
23530
- rest = this.flowParseFunctionTypeParam(false);
23531
- }
23532
-
23533
- return {
23534
- params,
23535
- rest,
23536
- _this,
23537
- };
23538
- }
23539
-
23540
- flowIdentToTypeAnnotation(startLoc, node, id) {
23541
- switch(id.name) {
23542
- case 'any':
23543
- return this.finishNode(node, 'AnyTypeAnnotation');
23544
-
23545
- case 'bool':
23546
- case 'boolean':
23547
- return this.finishNode(node, 'BooleanTypeAnnotation');
23548
-
23549
- case 'mixed':
23550
- return this.finishNode(node, 'MixedTypeAnnotation');
23551
-
23552
- case 'empty':
23553
- return this.finishNode(node, 'EmptyTypeAnnotation');
23554
-
23555
- case 'number':
23556
- return this.finishNode(node, 'NumberTypeAnnotation');
23557
-
23558
- case 'string':
23559
- return this.finishNode(node, 'StringTypeAnnotation');
23560
-
23561
- case 'symbol':
23562
- return this.finishNode(node, 'SymbolTypeAnnotation');
23563
-
23564
- default:
23565
- this.checkNotUnderscore(id.name);
23566
- return this.flowParseGenericType(startLoc, id);
23567
- }
23568
- }
23569
-
23570
- flowParsePrimaryType() {
23571
- const startLoc = this.state.startLoc;
23572
- const node = this.startNode();
23573
- let tmp;
23574
- let type;
23575
- let isGroupedType = false;
23576
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
23577
-
23578
- switch(this.state.type) {
23579
- case 5:
23580
- return this.flowParseObjectType({
23581
- allowStatic: false,
23582
- allowExact: false,
23583
- allowSpread: true,
23584
- allowProto: false,
23585
- allowInexact: true,
23586
- });
23587
-
23588
- case 6:
23589
- return this.flowParseObjectType({
23590
- allowStatic: false,
23591
- allowExact: true,
23592
- allowSpread: true,
23593
- allowProto: false,
23594
- allowInexact: false,
23595
- });
23596
-
23597
- case 0:
23598
- this.state.noAnonFunctionType = false;
23599
- type = this.flowParseTupleType();
23600
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
23601
- return type;
23602
-
23603
- case 47: {
23604
- const node2 = this.startNode();
23605
-
23606
- node2.typeParameters = this.flowParseTypeParameterDeclaration();
23607
- this.expect(10);
23608
- tmp = this.flowParseFunctionTypeParams();
23609
- node2.params = tmp.params;
23610
- node2.rest = tmp.rest;
23611
- node2.this = tmp._this;
23612
- this.expect(11);
23613
- this.expect(19);
23614
- node2.returnType = this.flowParseType();
23615
- return this.finishNode(node2, 'FunctionTypeAnnotation');
23616
- }
23617
-
23618
- case 10: {
23619
- const node2 = this.startNode();
23620
- this.next();
23621
-
23622
- if (!this.match(11) && !this.match(21)) {
23623
- if (tokenIsIdentifier(this.state.type) || this.match(78)) {
23624
- const token = this.lookahead().type;
23625
- isGroupedType = token !== 17 && token !== 14;
23626
- } else {
23627
- isGroupedType = true;
23628
- }
23629
- }
23630
-
23631
- if (isGroupedType) {
23632
- this.state.noAnonFunctionType = false;
23633
- type = this.flowParseType();
23634
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
23635
-
23636
- if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
23637
- this.expect(11);
23638
- return type;
23639
- } else {
23640
- this.eat(12);
23641
- }
23642
- }
23643
-
23644
- if (type) {
23645
- tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
23646
- } else {
23647
- tmp = this.flowParseFunctionTypeParams();
23648
- }
23649
-
23650
- node2.params = tmp.params;
23651
- node2.rest = tmp.rest;
23652
- node2.this = tmp._this;
23653
- this.expect(11);
23654
- this.expect(19);
23655
- node2.returnType = this.flowParseType();
23656
- node2.typeParameters = null;
23657
- return this.finishNode(node2, 'FunctionTypeAnnotation');
23658
- }
23659
-
23660
- case 134:
23661
- return this.parseLiteral(this.state.value, 'StringLiteralTypeAnnotation');
23662
-
23663
- case 85:
23664
- case 86:
23665
- node.value = this.match(85);
23666
- this.next();
23667
- return this.finishNode(node, 'BooleanLiteralTypeAnnotation');
23668
-
23669
- case 53:
23670
- if (this.state.value === '-') {
23671
- this.next();
23672
-
23673
- if (this.match(135)) {
23674
- return this.parseLiteralAtNode(-this.state.value, 'NumberLiteralTypeAnnotation', node);
23675
- }
23676
-
23677
- if (this.match(136)) {
23678
- return this.parseLiteralAtNode(-this.state.value, 'BigIntLiteralTypeAnnotation', node);
23679
- }
23680
-
23681
- throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
23682
- }
23683
-
23684
- this.unexpected();
23685
- return;
23686
-
23687
- case 135:
23688
- return this.parseLiteral(this.state.value, 'NumberLiteralTypeAnnotation');
23689
-
23690
- case 136:
23691
- return this.parseLiteral(this.state.value, 'BigIntLiteralTypeAnnotation');
23692
-
23693
- case 88:
23694
- this.next();
23695
- return this.finishNode(node, 'VoidTypeAnnotation');
23696
-
23697
- case 84:
23698
- this.next();
23699
- return this.finishNode(node, 'NullLiteralTypeAnnotation');
23700
-
23701
- case 78:
23702
- this.next();
23703
- return this.finishNode(node, 'ThisTypeAnnotation');
23704
-
23705
- case 55:
23706
- this.next();
23707
- return this.finishNode(node, 'ExistsTypeAnnotation');
23708
-
23709
- case 87:
23710
- return this.flowParseTypeofType();
23711
-
23712
- default:
23713
- if (tokenIsKeyword(this.state.type)) {
23714
- const label = tokenLabelName(this.state.type);
23715
- this.next();
23716
- return super.createIdentifier(node, label);
23717
- } else if (tokenIsIdentifier(this.state.type)) {
23718
- if (this.isContextual(129)) {
23719
- return this.flowParseInterfaceType();
23720
- }
23721
-
23722
- return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
23723
- }
23724
- }
23725
-
23726
- this.unexpected();
23727
- }
23728
-
23729
- flowParsePostfixType() {
23730
- const startLoc = this.state.startLoc;
23731
- let type = this.flowParsePrimaryType();
23732
- let seenOptionalIndexedAccess = false;
23733
-
23734
- while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
23735
- const node = this.startNodeAt(startLoc);
23736
- const optional = this.eat(18);
23737
-
23738
- seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
23739
- this.expect(0);
23740
-
23741
- if (!optional && this.match(3)) {
23742
- node.elementType = type;
23743
- this.next();
23744
- type = this.finishNode(node, 'ArrayTypeAnnotation');
23745
- } else {
23746
- node.objectType = type;
23747
- node.indexType = this.flowParseType();
23748
- this.expect(3);
23749
-
23750
- if (seenOptionalIndexedAccess) {
23751
- node.optional = optional;
23752
- type = this.finishNode(node, 'OptionalIndexedAccessType');
23753
- } else {
23754
- type = this.finishNode(node, 'IndexedAccessType');
23755
- }
23756
- }
23757
- }
23758
-
23759
- return type;
23760
- }
23761
-
23762
- flowParsePrefixType() {
23763
- const node = this.startNode();
23764
-
23765
- if (this.eat(17)) {
23766
- node.typeAnnotation = this.flowParsePrefixType();
23767
- return this.finishNode(node, 'NullableTypeAnnotation');
23768
- } else {
23769
- return this.flowParsePostfixType();
23770
- }
23771
- }
23772
-
23773
- flowParseAnonFunctionWithoutParens() {
23774
- const param = this.flowParsePrefixType();
23775
-
23776
- if (!this.state.noAnonFunctionType && this.eat(19)) {
23777
- const node = this.startNodeAt(param.loc.start);
23778
-
23779
- node.params = [
23780
- this.reinterpretTypeAsFunctionTypeParam(param),
23781
- ];
23782
- node.rest = null;
23783
- node.this = null;
23784
- node.returnType = this.flowParseType();
23785
- node.typeParameters = null;
23786
- return this.finishNode(node, 'FunctionTypeAnnotation');
23787
- }
23788
-
23789
- return param;
23790
- }
23791
-
23792
- flowParseIntersectionType() {
23793
- const node = this.startNode();
23794
- this.eat(45);
23795
- const type = this.flowParseAnonFunctionWithoutParens();
23796
-
23797
- node.types = [type];
23798
- while (this.eat(45)) {
23799
- node.types.push(this.flowParseAnonFunctionWithoutParens());
23800
- }
23801
-
23802
- return node.types.length === 1 ? type : this.finishNode(node, 'IntersectionTypeAnnotation');
23803
- }
23804
-
23805
- flowParseUnionType() {
23806
- const node = this.startNode();
23807
- this.eat(43);
23808
- const type = this.flowParseIntersectionType();
23809
-
23810
- node.types = [type];
23811
- while (this.eat(43)) {
23812
- node.types.push(this.flowParseIntersectionType());
23813
- }
23814
-
23815
- return node.types.length === 1 ? type : this.finishNode(node, 'UnionTypeAnnotation');
23816
- }
23817
-
23818
- flowParseType() {
23819
- const oldInType = this.state.inType;
23820
-
23821
- this.state.inType = true;
23822
- const type = this.flowParseUnionType();
23823
-
23824
- this.state.inType = oldInType;
23825
- return type;
23826
- }
23827
-
23828
- flowParseTypeOrImplicitInstantiation() {
23829
- if (this.state.type === 132 && this.state.value === '_') {
23830
- const startLoc = this.state.startLoc;
23831
- const node = this.parseIdentifier();
23832
-
23833
- return this.flowParseGenericType(startLoc, node);
23834
- } else {
23835
- return this.flowParseType();
23836
- }
23837
- }
23838
-
23839
- flowParseTypeAnnotation() {
23840
- const node = this.startNode();
23841
-
23842
- node.typeAnnotation = this.flowParseTypeInitialiser();
23843
- return this.finishNode(node, 'TypeAnnotation');
23844
- }
23845
-
23846
- flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
23847
- const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
23848
-
23849
- if (this.match(14)) {
23850
- ident.typeAnnotation = this.flowParseTypeAnnotation();
23851
- this.resetEndLocation(ident);
23852
- }
23853
-
23854
- return ident;
23855
- }
23856
-
23857
- typeCastToParameter(node) {
23858
- node.expression.typeAnnotation = node.typeAnnotation;
23859
- this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
23860
- return node.expression;
23861
- }
23862
-
23863
- flowParseVariance() {
23864
- let variance2 = null;
23865
-
23866
- if (this.match(53)) {
23867
- variance2 = this.startNode();
23868
-
23869
- if (this.state.value === '+') {
23870
- variance2.kind = 'plus';
23871
- } else {
23872
- variance2.kind = 'minus';
23873
- }
23874
-
23875
- this.next();
23876
- return this.finishNode(variance2, 'Variance');
23877
- }
23878
-
23879
- return variance2;
23880
- }
23881
-
23882
- parseFunctionBody(node, allowExpressionBody, isMethod3 = false) {
23883
- if (allowExpressionBody) {
23884
- this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod3));
23885
- return;
23886
- }
23887
-
23888
- super.parseFunctionBody(node, false, isMethod3);
23889
- }
23890
-
23891
- parseFunctionBodyAndFinish(node, type, isMethod3 = false) {
23892
- if (this.match(14)) {
23893
- const typeNode = this.startNode();
23894
-
23895
- [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
23896
- node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, 'TypeAnnotation') : null;
23897
- }
23898
-
23899
- return super.parseFunctionBodyAndFinish(node, type, isMethod3);
23900
- }
23901
-
23902
- parseStatementLike(flags) {
23903
- if (this.state.strict && this.isContextual(129)) {
23904
- const lookahead = this.lookahead();
23905
-
23906
- if (tokenIsKeywordOrIdentifier(lookahead.type)) {
23907
- const node = this.startNode();
23908
- this.next();
23909
- return this.flowParseInterface(node);
23910
- }
23911
- } else if (this.isContextual(126)) {
23912
- const node = this.startNode();
23913
- this.next();
23914
- return this.flowParseEnumDeclaration(node);
23915
- }
23916
-
23917
- const stmt = super.parseStatementLike(flags);
23918
-
23919
- if (this.flowPragma === void 0 && !this.isValidDirective(stmt)) {
23920
- this.flowPragma = null;
23921
- }
23922
-
23923
- return stmt;
23924
- }
23925
-
23926
- parseExpressionStatement(node, expr, decorators) {
23927
- if (expr.type === 'Identifier') {
23928
- if (expr.name === 'declare') {
23929
- if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
23930
- return this.flowParseDeclare(node);
23931
- }
23932
- } else if (tokenIsIdentifier(this.state.type)) {
23933
- if (expr.name === 'interface') {
23934
- return this.flowParseInterface(node);
23935
- } else if (expr.name === 'type') {
23936
- return this.flowParseTypeAlias(node);
23937
- } else if (expr.name === 'opaque') {
23938
- return this.flowParseOpaqueType(node, false);
23939
- }
23940
-
23941
- }
23942
- }
23943
-
23944
- return super.parseExpressionStatement(node, expr, decorators);
23945
- }
23946
-
23947
- shouldParseExportDeclaration() {
23948
- const {type} = this.state;
23949
-
23950
- if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
23951
- return !this.state.containsEsc;
23952
- }
23953
-
23954
- return super.shouldParseExportDeclaration();
23955
- }
23956
-
23957
- isExportDefaultSpecifier() {
23958
- const {type} = this.state;
23959
-
23960
- if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
23961
- return this.state.containsEsc;
23962
- }
23963
-
23964
- return super.isExportDefaultSpecifier();
23965
- }
23966
-
23967
- parseExportDefaultExpression() {
23968
- if (this.isContextual(126)) {
23969
- const node = this.startNode();
23970
- this.next();
23971
- return this.flowParseEnumDeclaration(node);
23972
- }
23973
-
23974
- return super.parseExportDefaultExpression();
23975
- }
23976
-
23977
- parseConditional(expr, startLoc, refExpressionErrors) {
23978
- if (!this.match(17))
23979
- return expr;
23980
-
23981
- if (this.state.maybeInArrowParameters) {
23982
- const nextCh = this.lookaheadCharCode();
23983
-
23984
- if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
23985
- this.setOptionalParametersError(refExpressionErrors);
23986
- return expr;
23987
- }
23988
- }
23989
-
23990
- this.expect(17);
23991
- const state = this.state.clone();
23992
- const originalNoArrowAt = this.state.noArrowAt;
23993
- const node = this.startNodeAt(startLoc);
23994
-
23995
- let {consequent, failed} = this.tryParseConditionalConsequent();
23996
-
23997
- let [valid, invalid] = this.getArrowLikeExpressions(consequent);
23998
-
23999
- if (failed || invalid.length > 0) {
24000
- const noArrowAt = [...originalNoArrowAt];
24001
-
24002
- if (invalid.length > 0) {
24003
- this.state = state;
24004
- this.state.noArrowAt = noArrowAt;
24005
- for (let i = 0; i < invalid.length; i++) {
24006
- noArrowAt.push(invalid[i].start);
24007
- }
24008
-
24009
- ({
24010
- consequent,
24011
- failed,
24012
- } = this.tryParseConditionalConsequent());
24013
- [valid, invalid] = this.getArrowLikeExpressions(consequent);
24014
- }
24015
-
24016
- if (failed && valid.length > 1) {
24017
- this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
24018
- }
24019
-
24020
- if (failed && valid.length === 1) {
24021
- this.state = state;
24022
- noArrowAt.push(valid[0].start);
24023
- this.state.noArrowAt = noArrowAt;
24024
- ({
24025
- consequent,
24026
- failed,
24027
- } = this.tryParseConditionalConsequent());
24028
- }
24029
- }
24030
-
24031
- this.getArrowLikeExpressions(consequent, true);
24032
- this.state.noArrowAt = originalNoArrowAt;
24033
- this.expect(14);
24034
- node.test = expr;
24035
- node.consequent = consequent;
24036
- node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(void 0, void 0));
24037
-
24038
- return this.finishNode(node, 'ConditionalExpression');
24039
- }
24040
-
24041
- tryParseConditionalConsequent() {
24042
- this.state.noArrowParamsConversionAt.push(this.state.start);
24043
- const consequent = this.parseMaybeAssignAllowIn();
24044
- const failed = !this.match(14);
24045
-
24046
- this.state.noArrowParamsConversionAt.pop();
24047
- return {
24048
- consequent,
24049
- failed,
24050
- };
24051
- }
24052
-
24053
- getArrowLikeExpressions(node, disallowInvalid) {
24054
- const stack = [node];
24055
- const arrows = [];
24056
-
24057
- while (stack.length !== 0) {
24058
- const node2 = stack.pop();
24059
-
24060
- if (node2.type === 'ArrowFunctionExpression' && node2.body.type !== 'BlockStatement') {
24061
- if (node2.typeParameters || !node2.returnType) {
24062
- this.finishArrowValidation(node2);
24063
- } else {
24064
- arrows.push(node2);
24065
- }
24066
-
24067
- stack.push(node2.body);
24068
- } else if (node2.type === 'ConditionalExpression') {
24069
- stack.push(node2.consequent);
24070
- stack.push(node2.alternate);
24071
- }
24072
- }
24073
-
24074
- if (disallowInvalid) {
24075
- arrows.forEach((node2) => this.finishArrowValidation(node2));
24076
- return [
24077
- arrows,
24078
- [],
24079
- ];
24080
- }
24081
-
24082
- return partition(arrows, (node2) => node2.params.every((param) => this.isAssignable(param, true)));
24083
- }
24084
-
24085
- finishArrowValidation(node) {
24086
- this.toAssignableList(node.params, node.extra?.trailingCommaLoc, false);
24087
- this.scope.enter(514 | 4);
24088
- super.checkParams(node, false, true);
24089
- this.scope.exit();
24090
- }
24091
-
24092
- forwardNoArrowParamsConversionAt(node, parse3) {
24093
- let result;
24094
-
24095
- if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
24096
- this.state.noArrowParamsConversionAt.push(this.state.start);
24097
- result = parse3();
24098
- this.state.noArrowParamsConversionAt.pop();
24099
- } else {
24100
- result = parse3();
24101
- }
24102
-
24103
- return result;
24104
- }
24105
-
24106
- parseParenItem(node, startLoc) {
24107
- const newNode = super.parseParenItem(node, startLoc);
24108
-
24109
- if (this.eat(17)) {
24110
- newNode.optional = true;
24111
- this.resetEndLocation(node);
24112
- }
24113
-
24114
- if (this.match(14)) {
24115
- const typeCastNode = this.startNodeAt(startLoc);
24116
-
24117
- typeCastNode.expression = newNode;
24118
- typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
24119
- return this.finishNode(typeCastNode, 'TypeCastExpression');
24120
- }
24121
-
24122
- return newNode;
24123
- }
24124
-
24125
- assertModuleNodeAllowed(node) {
24126
- if (node.type === 'ImportDeclaration' && (node.importKind === 'type' || node.importKind === 'typeof') || node.type === 'ExportNamedDeclaration' && node.exportKind === 'type' || node.type === 'ExportAllDeclaration' && node.exportKind === 'type') {
24127
- return;
24128
- }
24129
-
24130
- super.assertModuleNodeAllowed(node);
24131
- }
24132
-
24133
- parseExportDeclaration(node) {
24134
- if (this.isContextual(130)) {
24135
- node.exportKind = 'type';
24136
- const declarationNode = this.startNode();
24137
- this.next();
24138
-
24139
- if (this.match(5)) {
24140
- node.specifiers = this.parseExportSpecifiers(true);
24141
- super.parseExportFrom(node);
24142
- return null;
24143
- } else {
24144
- return this.flowParseTypeAlias(declarationNode);
24145
- }
24146
- } else if (this.isContextual(131)) {
24147
- node.exportKind = 'type';
24148
- const declarationNode = this.startNode();
24149
- this.next();
24150
- return this.flowParseOpaqueType(declarationNode, false);
24151
- } else if (this.isContextual(129)) {
24152
- node.exportKind = 'type';
24153
- const declarationNode = this.startNode();
24154
- this.next();
24155
- return this.flowParseInterface(declarationNode);
24156
- } else if (this.isContextual(126)) {
24157
- node.exportKind = 'value';
24158
- const declarationNode = this.startNode();
24159
- this.next();
24160
- return this.flowParseEnumDeclaration(declarationNode);
24161
- } else {
24162
- return super.parseExportDeclaration(node);
24163
- }
24164
-
24165
-
24166
- }
24167
-
24168
- eatExportStar(node) {
24169
- if (super.eatExportStar(node))
24170
- return true;
24171
-
24172
- if (this.isContextual(130) && this.lookahead().type === 55) {
24173
- node.exportKind = 'type';
24174
- this.next();
24175
- this.next();
24176
- return true;
24177
- }
24178
-
24179
- return false;
24180
- }
24181
-
24182
- maybeParseExportNamespaceSpecifier(node) {
24183
- const {startLoc} = this.state;
24184
-
24185
- const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
24186
-
24187
- if (hasNamespace && node.exportKind === 'type') {
24188
- this.unexpected(startLoc);
24189
- }
24190
-
24191
- return hasNamespace;
24192
- }
24193
-
24194
- parseClassId(node, isStatement5, optionalId) {
24195
- super.parseClassId(node, isStatement5, optionalId);
24196
-
24197
- if (this.match(47)) {
24198
- node.typeParameters = this.flowParseTypeParameterDeclaration();
24199
- }
24200
- }
24201
-
24202
- parseClassMember(classBody2, member, state) {
24203
- const {startLoc} = this.state;
24204
-
24205
- if (this.isContextual(125)) {
24206
- if (super.parseClassMemberFromModifier(classBody2, member)) {
24207
- return;
24208
- }
24209
-
24210
- member.declare = true;
24211
- }
24212
-
24213
- super.parseClassMember(classBody2, member, state);
24214
-
24215
- if (member.declare) {
24216
- if (member.type !== 'ClassProperty' && member.type !== 'ClassPrivateProperty' && member.type !== 'PropertyDefinition') {
24217
- this.raise(FlowErrors.DeclareClassElement, startLoc);
24218
- } else if (member.value) {
24219
- this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
24220
- }
24221
- }
24222
- }
24223
-
24224
- isIterator(word) {
24225
- return word === 'iterator' || word === 'asyncIterator';
24226
- }
24227
-
24228
- readIterator() {
24229
- const word = super.readWord1();
24230
- const fullWord = '@@' + word;
24231
-
24232
- if (!this.isIterator(word) || !this.state.inType) {
24233
- this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
24234
- identifierName: fullWord,
24235
- });
24236
- }
24237
-
24238
- this.finishToken(132, fullWord);
24239
- }
24240
-
24241
- getTokenFromCode(code2) {
24242
- const next = this.input.charCodeAt(this.state.pos + 1);
24243
-
24244
- if (code2 === 123 && next === 124) {
24245
- this.finishOp(6, 2);
24246
- } else if (this.state.inType && (code2 === 62 || code2 === 60)) {
24247
- this.finishOp(code2 === 62 ? 48 : 47, 1);
24248
- } else if (this.state.inType && code2 === 63) {
24249
- if (next === 46) {
24250
- this.finishOp(18, 2);
24251
- } else {
24252
- this.finishOp(17, 1);
24253
- }
24254
- } else if (isIteratorStart(code2, next, this.input.charCodeAt(this.state.pos + 2))) {
24255
- this.state.pos += 2;
24256
- this.readIterator();
24257
- } else {
24258
- super.getTokenFromCode(code2);
24259
- }
24260
-
24261
-
24262
- }
24263
-
24264
- isAssignable(node, isBinding3) {
24265
- if (node.type === 'TypeCastExpression') {
24266
- return this.isAssignable(node.expression, isBinding3);
24267
- } else {
24268
- return super.isAssignable(node, isBinding3);
24269
- }
24270
- }
24271
-
24272
- toAssignable(node, isLHS = false) {
24273
- if (!isLHS && node.type === 'AssignmentExpression' && node.left.type === 'TypeCastExpression') {
24274
- node.left = this.typeCastToParameter(node.left);
24275
- }
24276
-
24277
- super.toAssignable(node, isLHS);
24278
- }
24279
-
24280
- toAssignableList(exprList, trailingCommaLoc, isLHS) {
24281
- for (let i = 0; i < exprList.length; i++) {
24282
- const expr = exprList[i];
24283
-
24284
- if (expr?.type === 'TypeCastExpression') {
24285
- exprList[i] = this.typeCastToParameter(expr);
24286
- }
24287
- }
24288
-
24289
- super.toAssignableList(exprList, trailingCommaLoc, isLHS);
24290
- }
24291
-
24292
- toReferencedList(exprList, isParenthesizedExpr) {
24293
- for (let i = 0; i < exprList.length; i++) {
24294
- const expr = exprList[i];
24295
-
24296
- if (expr && expr.type === 'TypeCastExpression' && !expr.extra?.parenthesized && (exprList.length > 1 || !isParenthesizedExpr)) {
24297
- this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
24298
- }
24299
- }
24300
-
24301
- return exprList;
24302
- }
24303
-
24304
- parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
24305
- const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
24306
-
24307
- if (canBePattern && !this.state.maybeInArrowParameters) {
24308
- this.toReferencedList(node.elements);
24309
- }
24310
-
24311
- return node;
24312
- }
24313
-
24314
- isValidLVal(type, isParenthesized, binding) {
24315
- return type === 'TypeCastExpression' || super.isValidLVal(type, isParenthesized, binding);
24316
- }
24317
-
24318
- parseClassProperty(node) {
24319
- if (this.match(14)) {
24320
- node.typeAnnotation = this.flowParseTypeAnnotation();
24321
- }
24322
-
24323
- return super.parseClassProperty(node);
24324
- }
24325
-
24326
- parseClassPrivateProperty(node) {
24327
- if (this.match(14)) {
24328
- node.typeAnnotation = this.flowParseTypeAnnotation();
24329
- }
24330
-
24331
- return super.parseClassPrivateProperty(node);
24332
- }
24333
-
24334
- isClassMethod() {
24335
- return this.match(47) || super.isClassMethod();
24336
- }
24337
-
24338
- isClassProperty() {
24339
- return this.match(14) || super.isClassProperty();
24340
- }
24341
-
24342
- isNonstaticConstructor(method) {
24343
- return !this.match(14) && super.isNonstaticConstructor(method);
24344
- }
24345
-
24346
- pushClassMethod(classBody2, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
24347
- if (method.variance) {
24348
- this.unexpected(method.variance.loc.start);
24349
- }
24350
-
24351
- delete method.variance;
24352
-
24353
- if (this.match(47)) {
24354
- method.typeParameters = this.flowParseTypeParameterDeclaration();
24355
- }
24356
-
24357
- super.pushClassMethod(classBody2, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
24358
-
24359
- if (method.params && isConstructor) {
24360
- const params = method.params;
24361
-
24362
- if (params.length > 0 && this.isThisParam(params[0])) {
24363
- this.raise(FlowErrors.ThisParamBannedInConstructor, method);
24364
- }
24365
- } else if (method.type === 'MethodDefinition' && isConstructor && method.value.params) {
24366
- const params = method.value.params;
24367
-
24368
- if (params.length > 0 && this.isThisParam(params[0])) {
24369
- this.raise(FlowErrors.ThisParamBannedInConstructor, method);
24370
- }
24371
- }
24372
- }
24373
-
24374
- pushClassPrivateMethod(classBody2, method, isGenerator, isAsync) {
24375
- if (method.variance) {
24376
- this.unexpected(method.variance.loc.start);
24377
- }
24378
-
24379
- delete method.variance;
24380
-
24381
- if (this.match(47)) {
24382
- method.typeParameters = this.flowParseTypeParameterDeclaration();
24383
- }
24384
-
24385
- super.pushClassPrivateMethod(classBody2, method, isGenerator, isAsync);
24386
- }
24387
-
24388
- parseClassSuper(node) {
24389
- super.parseClassSuper(node);
24390
-
24391
- if (node.superClass && (this.match(47) || this.match(51))) {
24392
- {
24393
- node.superTypeArguments = this.flowParseTypeParameterInstantiationInExpression();
24394
- }
24395
- }
24396
-
24397
- if (this.isContextual(113)) {
24398
- this.next();
24399
- const implemented = node.implements = [];
24400
-
24401
- do {
24402
- const node2 = this.startNode();
24403
-
24404
- node2.id = this.flowParseRestrictedIdentifier(true);
24405
-
24406
- if (this.match(47)) {
24407
- node2.typeParameters = this.flowParseTypeParameterInstantiation();
24408
- } else {
24409
- node2.typeParameters = null;
24410
- }
24411
-
24412
- implemented.push(this.finishNode(node2, 'ClassImplements'));
24413
- } while (this.eat(12))
24414
- }
24415
- }
24416
-
24417
- checkGetterSetterParams(method) {
24418
- super.checkGetterSetterParams(method);
24419
- const params = this.getObjectOrClassMethodParams(method);
24420
-
24421
- if (params.length > 0) {
24422
- const param = params[0];
24423
-
24424
- if (this.isThisParam(param) && method.kind === 'get') {
24425
- this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
24426
- } else if (this.isThisParam(param)) {
24427
- this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
24428
- }
24429
- }
24430
- }
24431
-
24432
- parsePropertyNamePrefixOperator(node) {
24433
- node.variance = this.flowParseVariance();
24434
- }
24435
-
24436
- parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern3, isAccessor2, refExpressionErrors) {
24437
- if (prop.variance) {
24438
- this.unexpected(prop.variance.loc.start);
24439
- }
24440
-
24441
- delete prop.variance;
24442
- let typeParameters;
24443
-
24444
- if (this.match(47) && !isAccessor2) {
24445
- typeParameters = this.flowParseTypeParameterDeclaration();
24446
-
24447
- if (!this.match(10))
24448
- this.unexpected();
24449
- }
24450
-
24451
- const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern3, isAccessor2, refExpressionErrors);
24452
-
24453
- if (typeParameters) {
24454
- (result.value || result).typeParameters = typeParameters;
24455
- }
24456
-
24457
- return result;
24458
- }
24459
-
24460
- parseFunctionParamType(param) {
24461
- if (this.eat(17)) {
24462
- if (param.type !== 'Identifier') {
24463
- this.raise(FlowErrors.PatternIsOptional, param);
24464
- }
24465
-
24466
- if (this.isThisParam(param)) {
24467
- this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
24468
- }
24469
-
24470
- param.optional = true;
24471
- }
24472
-
24473
- if (this.match(14)) {
24474
- param.typeAnnotation = this.flowParseTypeAnnotation();
24475
- } else if (this.isThisParam(param)) {
24476
- this.raise(FlowErrors.ThisParamAnnotationRequired, param);
24477
- }
24478
-
24479
- if (this.match(29) && this.isThisParam(param)) {
24480
- this.raise(FlowErrors.ThisParamNoDefault, param);
24481
- }
24482
-
24483
- this.resetEndLocation(param);
24484
- return param;
24485
- }
24486
-
24487
- parseMaybeDefault(startLoc, left) {
24488
- const node = super.parseMaybeDefault(startLoc, left);
24489
-
24490
- if (node.type === 'AssignmentPattern' && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
24491
- this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
24492
- }
24493
-
24494
- return node;
24495
- }
24496
-
24497
- checkImportReflection(node) {
24498
- super.checkImportReflection(node);
24499
-
24500
- if (node.module && node.importKind !== 'value') {
24501
- this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
24502
- }
24503
- }
24504
-
24505
- parseImportSpecifierLocal(node, specifier, type) {
24506
- specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
24507
- node.specifiers.push(this.finishImportSpecifier(specifier, type));
24508
- }
24509
-
24510
- isPotentialImportPhase(isExport) {
24511
- if (super.isPotentialImportPhase(isExport))
24512
- return true;
24513
-
24514
- if (this.isContextual(130)) {
24515
- if (!isExport)
24516
- return true;
24517
-
24518
- const ch = this.lookaheadCharCode();
24519
-
24520
- return ch === 123 || ch === 42;
24521
- }
24522
-
24523
- return !isExport && this.isContextual(87);
24524
- }
24525
-
24526
- applyImportPhase(node, isExport, phase, loc) {
24527
- super.applyImportPhase(node, isExport, phase, loc);
24528
-
24529
- if (isExport) {
24530
- if (!phase && this.match(65)) {
24531
- return;
24532
- }
24533
-
24534
- node.exportKind = phase === 'type' ? phase : 'value';
24535
- } else {
24536
- if (phase === 'type' && this.match(55))
24537
- this.unexpected();
24538
-
24539
- node.importKind = phase === 'type' || phase === 'typeof' ? phase : 'value';
24540
- }
24541
- }
24542
-
24543
- parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
24544
- const firstIdent = specifier.imported;
24545
- let specifierTypeKind = null;
24546
-
24547
- if (firstIdent.type === 'Identifier') {
24548
- if (firstIdent.name === 'type') {
24549
- specifierTypeKind = 'type';
24550
- } else if (firstIdent.name === 'typeof') {
24551
- specifierTypeKind = 'typeof';
24552
- }
24553
- }
24554
-
24555
- let isBinding3 = false;
24556
-
24557
- if (this.isContextual(93) && !this.isLookaheadContextual('as')) {
24558
- const as_ident = this.parseIdentifier(true);
24559
-
24560
- if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
24561
- specifier.imported = as_ident;
24562
- specifier.importKind = specifierTypeKind;
24563
- specifier.local = this.cloneIdentifier(as_ident);
24564
- } else {
24565
- specifier.imported = firstIdent;
24566
- specifier.importKind = null;
24567
- specifier.local = this.parseIdentifier();
24568
- }
24569
- } else {
24570
- if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
24571
- specifier.imported = this.parseIdentifier(true);
24572
- specifier.importKind = specifierTypeKind;
24573
- } else {
24574
- if (importedIsString) {
24575
- throw this.raise(Errors.ImportBindingIsString, specifier, {
24576
- importName: firstIdent.value,
24577
- });
24578
- }
24579
-
24580
- specifier.imported = firstIdent;
24581
- specifier.importKind = null;
24582
- }
24583
-
24584
- if (this.eatContextual(93)) {
24585
- specifier.local = this.parseIdentifier();
24586
- } else {
24587
- isBinding3 = true;
24588
- specifier.local = this.cloneIdentifier(specifier.imported);
24589
- }
24590
- }
24591
-
24592
- const specifierIsTypeImport = hasTypeImportKind(specifier);
24593
-
24594
- if (isInTypeOnlyImport && specifierIsTypeImport) {
24595
- this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
24596
- }
24597
-
24598
- if (isInTypeOnlyImport || specifierIsTypeImport) {
24599
- this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
24600
- }
24601
-
24602
- if (isBinding3 && !isInTypeOnlyImport && !specifierIsTypeImport) {
24603
- this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
24604
- }
24605
-
24606
- return this.finishImportSpecifier(specifier, 'ImportSpecifier');
24607
- }
24608
-
24609
- parseBindingAtom() {
24610
- switch(this.state.type) {
24611
- case 78:
24612
- return this.parseIdentifier(true);
24613
-
24614
- default:
24615
- return super.parseBindingAtom();
24616
- }
24617
- }
24618
-
24619
- parseFunctionParams(node, isConstructor) {
24620
- const kind = node.kind;
24621
-
24622
- if (kind !== 'get' && kind !== 'set' && this.match(47)) {
24623
- node.typeParameters = this.flowParseTypeParameterDeclaration();
24624
- }
24625
-
24626
- super.parseFunctionParams(node, isConstructor);
24627
- }
24628
-
24629
- parseVarId(decl, kind) {
24630
- super.parseVarId(decl, kind);
24631
-
24632
- if (this.match(14)) {
24633
- decl.id.typeAnnotation = this.flowParseTypeAnnotation();
24634
- this.resetEndLocation(decl.id);
24635
- }
24636
- }
24637
-
24638
- parseAsyncArrowFromCallExpression(node, call2) {
24639
- if (this.match(14)) {
24640
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
24641
-
24642
- this.state.noAnonFunctionType = true;
24643
- node.returnType = this.flowParseTypeAnnotation();
24644
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
24645
- }
24646
-
24647
- return super.parseAsyncArrowFromCallExpression(node, call2);
24648
- }
24649
-
24650
- shouldParseAsyncArrow() {
24651
- return this.match(14) || super.shouldParseAsyncArrow();
24652
- }
24653
-
24654
- parseMaybeAssign(refExpressionErrors, afterLeftParse) {
24655
- let state = null;
24656
- let jsx2;
24657
-
24658
- if (this.hasPlugin('jsx') && (this.match(143) || this.match(47))) {
24659
- state = this.state.clone();
24660
- jsx2 = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
24661
-
24662
- if (!jsx2.error)
24663
- return jsx2.node;
24664
-
24665
- const {context} = this.state;
24666
-
24667
- const currentContext = context[context.length - 1];
24668
-
24669
- if (currentContext === types.j_oTag || currentContext === types.j_expr) {
24670
- context.pop();
24671
- }
24672
- }
24673
-
24674
- if (jsx2?.error || this.match(47)) {
24675
- state = state || this.state.clone();
24676
- let typeParameters;
24677
- const arrow = this.tryParse((abort) => {
24678
- typeParameters = this.flowParseTypeParameterDeclaration();
24679
- const arrowExpression2 = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
24680
- const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
24681
- this.resetStartLocationFromNode(result, typeParameters);
24682
- return result;
24683
- });
24684
-
24685
- if (arrowExpression2.extra?.parenthesized)
24686
- abort();
24687
-
24688
- const expr = this.maybeUnwrapTypeCastExpression(arrowExpression2);
24689
-
24690
- if (expr.type !== 'ArrowFunctionExpression')
24691
- abort();
24692
-
24693
- expr.typeParameters = typeParameters;
24694
- this.resetStartLocationFromNode(expr, typeParameters);
24695
- return arrowExpression2;
24696
- }, state);
24697
-
24698
- let arrowExpression = null;
24699
-
24700
- if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === 'ArrowFunctionExpression') {
24701
- if (!arrow.error && !arrow.aborted) {
24702
- if (arrow.node.async) {
24703
- this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
24704
- }
24705
-
24706
- return arrow.node;
24707
- }
24708
-
24709
- arrowExpression = arrow.node;
24710
- }
24711
-
24712
- if (jsx2?.node) {
24713
- this.state = jsx2.failState;
24714
- return jsx2.node;
24715
- }
24716
-
24717
- if (arrowExpression) {
24718
- this.state = arrow.failState;
24719
- return arrowExpression;
24720
- }
24721
-
24722
- if (jsx2?.thrown)
24723
- throw jsx2.error;
24724
-
24725
- if (arrow.thrown)
24726
- throw arrow.error;
24727
-
24728
- throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
24729
- }
24730
-
24731
- return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
24732
- }
24733
-
24734
- parseArrow(node) {
24735
- if (this.match(14)) {
24736
- const result = this.tryParse(() => {
24737
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
24738
-
24739
- this.state.noAnonFunctionType = true;
24740
- const typeNode = this.startNode();
24741
-
24742
- [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
24743
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
24744
-
24745
- if (this.canInsertSemicolon())
24746
- this.unexpected();
24747
-
24748
- if (!this.match(19))
24749
- this.unexpected();
24750
-
24751
- return typeNode;
24752
- });
24753
-
24754
- if (result.thrown)
24755
- return null;
24756
-
24757
- if (result.error)
24758
- this.state = result.failState;
24759
-
24760
- node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, 'TypeAnnotation') : null;
24761
- }
24762
-
24763
- return super.parseArrow(node);
24764
- }
24765
-
24766
- shouldParseArrow(params) {
24767
- return this.match(14) || super.shouldParseArrow(params);
24768
- }
24769
-
24770
- setArrowFunctionParameters(node, params) {
24771
- if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
24772
- node.params = params;
24773
- } else {
24774
- super.setArrowFunctionParameters(node, params);
24775
- }
24776
- }
24777
-
24778
- checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
24779
- if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
24780
- return;
24781
- }
24782
-
24783
- for (let i = 0; i < node.params.length; i++) {
24784
- if (this.isThisParam(node.params[i]) && i > 0) {
24785
- this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
24786
- }
24787
- }
24788
-
24789
- super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
24790
- }
24791
-
24792
- parseParenAndDistinguishExpression(canBeArrow) {
24793
- return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
24794
- }
24795
-
24796
- parseSubscripts(base, startLoc, noCalls) {
24797
- if (base.type === 'Identifier' && base.name === 'async' && this.state.noArrowAt.includes(startLoc.index)) {
24798
- this.next();
24799
- const node = this.startNodeAt(startLoc);
24800
-
24801
- node.callee = base;
24802
- node.arguments = super.parseCallExpressionArguments();
24803
- base = this.finishNode(node, 'CallExpression');
24804
- } else if (base.type === 'Identifier' && base.name === 'async' && this.match(47)) {
24805
- const state = this.state.clone();
24806
- const arrow = this.tryParse((abort) => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
24807
-
24808
- if (!arrow.error && !arrow.aborted)
24809
- return arrow.node;
24810
-
24811
- const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
24812
-
24813
- if (result.node && !result.error)
24814
- return result.node;
24815
-
24816
- if (arrow.node) {
24817
- this.state = arrow.failState;
24818
- return arrow.node;
24819
- }
24820
-
24821
- if (result.node) {
24822
- this.state = result.failState;
24823
- return result.node;
24824
- }
24825
-
24826
- throw arrow.error || result.error;
24827
- }
24828
-
24829
- return super.parseSubscripts(base, startLoc, noCalls);
24830
- }
24831
-
24832
- parseSubscript(base, startLoc, noCalls, subscriptState) {
24833
- if (this.match(18) && this.isLookaheadToken_lt()) {
24834
- subscriptState.optionalChainMember = true;
24835
-
24836
- if (noCalls) {
24837
- subscriptState.stop = true;
24838
- return base;
24839
- }
24840
-
24841
- this.next();
24842
- const node = this.startNodeAt(startLoc);
24843
-
24844
- node.callee = base;
24845
- node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
24846
- this.expect(10);
24847
- node.arguments = this.parseCallExpressionArguments();
24848
- node.optional = true;
24849
- return this.finishCallExpression(node, true);
24850
- } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
24851
- const node = this.startNodeAt(startLoc);
24852
-
24853
- node.callee = base;
24854
- const result = this.tryParse(() => {
24855
- node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
24856
- this.expect(10);
24857
- node.arguments = super.parseCallExpressionArguments();
24858
-
24859
- if (subscriptState.optionalChainMember) {
24860
- node.optional = false;
24861
- }
24862
-
24863
- return this.finishCallExpression(node, subscriptState.optionalChainMember);
24864
- });
24865
-
24866
- if (result.node) {
24867
- if (result.error)
24868
- this.state = result.failState;
24869
-
24870
- return result.node;
24871
- }
24872
- }
24873
-
24874
- return super.parseSubscript(base, startLoc, noCalls, subscriptState);
24875
- }
24876
-
24877
- parseNewCallee(node) {
24878
- super.parseNewCallee(node);
24879
- let targs = null;
24880
-
24881
- if (this.shouldParseTypes() && this.match(47)) {
24882
- targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
24883
- }
24884
-
24885
- node.typeArguments = targs;
24886
- }
24887
-
24888
- parseAsyncArrowWithTypeParameters(startLoc) {
24889
- const node = this.startNodeAt(startLoc);
24890
- this.parseFunctionParams(node, false);
24891
-
24892
- if (!this.parseArrow(node))
24893
- return;
24894
-
24895
- return super.parseArrowExpression(node, void 0, true);
24896
- }
24897
-
24898
- readToken_mult_modulo(code2) {
24899
- const next = this.input.charCodeAt(this.state.pos + 1);
24900
-
24901
- if (code2 === 42 && next === 47 && this.state.hasFlowComment) {
24902
- this.state.hasFlowComment = false;
24903
- this.state.pos += 2;
24904
- this.nextToken();
24905
- return;
24906
- }
24907
-
24908
- super.readToken_mult_modulo(code2);
24909
- }
24910
-
24911
- readToken_pipe_amp(code2) {
24912
- const next = this.input.charCodeAt(this.state.pos + 1);
24913
-
24914
- if (code2 === 124 && next === 125) {
24915
- this.finishOp(9, 2);
24916
- return;
24917
- }
24918
-
24919
- super.readToken_pipe_amp(code2);
24920
- }
24921
-
24922
- parseTopLevel(file2, program3) {
24923
- const fileNode = super.parseTopLevel(file2, program3);
24924
-
24925
- if (this.state.hasFlowComment) {
24926
- this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
24927
- }
24928
-
24929
- return fileNode;
24930
- }
24931
-
24932
- skipBlockComment() {
24933
- if (this.hasPlugin('flowComments') && this.skipFlowComment()) {
24934
- if (this.state.hasFlowComment) {
24935
- throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
24936
- }
24937
-
24938
- this.hasFlowCommentCompletion();
24939
- const commentSkip = this.skipFlowComment();
24940
-
24941
- if (commentSkip) {
24942
- this.state.pos += commentSkip;
24943
- this.state.hasFlowComment = true;
24944
- }
24945
-
24946
- return;
24947
- }
24948
-
24949
- return super.skipBlockComment(this.state.hasFlowComment ? '*-/' : '*/');
24950
- }
24951
-
24952
- skipFlowComment() {
24953
- const {pos} = this.state;
24954
-
24955
- let shiftToFirstNonWhiteSpace = 2;
24956
-
24957
- while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
24958
- shiftToFirstNonWhiteSpace++;
24959
- }
24960
-
24961
- const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
24962
- const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
24963
-
24964
- if (ch2 === 58 && ch3 === 58) {
24965
- return shiftToFirstNonWhiteSpace + 2;
24966
- }
24967
-
24968
- if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === 'flow-include') {
24969
- return shiftToFirstNonWhiteSpace + 12;
24970
- }
24971
-
24972
- if (ch2 === 58 && ch3 !== 58) {
24973
- return shiftToFirstNonWhiteSpace;
24974
- }
24975
-
24976
- return false;
24977
- }
24978
-
24979
- hasFlowCommentCompletion() {
24980
- const end = this.input.indexOf('*/', this.state.pos);
24981
-
24982
- if (end === -1) {
24983
- throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
24984
- }
24985
- }
24986
-
24987
- flowEnumErrorBooleanMemberNotInitialized(loc, {enumName, memberName}) {
24988
- this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
24989
- memberName,
24990
- enumName,
24991
- });
24992
- }
24993
-
24994
- flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
24995
- return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === 'symbol' ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
24996
- }
24997
-
24998
- flowEnumErrorNumberMemberNotInitialized(loc, details) {
24999
- this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
25000
- }
25001
-
25002
- flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
25003
- this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
25004
- }
25005
-
25006
- flowEnumMemberInit() {
25007
- const startLoc = this.state.startLoc;
25008
- const endOfInit = () => this.match(12) || this.match(8);
25009
-
25010
- switch(this.state.type) {
25011
- case 135: {
25012
- const literal = this.parseNumericLiteral(this.state.value);
25013
-
25014
- if (endOfInit()) {
25015
- return {
25016
- type: 'number',
25017
- loc: literal.loc.start,
25018
- value: literal,
25019
- };
25020
- }
25021
-
25022
- return {
25023
- type: 'invalid',
25024
- loc: startLoc,
25025
- };
25026
- }
25027
-
25028
- case 134: {
25029
- const literal = this.parseStringLiteral(this.state.value);
25030
-
25031
- if (endOfInit()) {
25032
- return {
25033
- type: 'string',
25034
- loc: literal.loc.start,
25035
- value: literal,
25036
- };
25037
- }
25038
-
25039
- return {
25040
- type: 'invalid',
25041
- loc: startLoc,
25042
- };
25043
- }
25044
-
25045
- case 85:
25046
- case 86: {
25047
- const literal = this.parseBooleanLiteral(this.match(85));
25048
-
25049
- if (endOfInit()) {
25050
- return {
25051
- type: 'boolean',
25052
- loc: literal.loc.start,
25053
- value: literal,
25054
- };
25055
- }
25056
-
25057
- return {
25058
- type: 'invalid',
25059
- loc: startLoc,
25060
- };
25061
- }
25062
-
25063
- default:
25064
- return {
25065
- type: 'invalid',
25066
- loc: startLoc,
25067
- };
25068
- }
25069
- }
25070
-
25071
- flowEnumMemberRaw() {
25072
- const loc = this.state.startLoc;
25073
- const id = this.parseIdentifier(true);
25074
- const init = this.eat(29) ? this.flowEnumMemberInit() : {
25075
- type: 'none',
25076
- loc,
25077
- };
25078
-
25079
- return {
25080
- id,
25081
- init,
25082
- };
25083
- }
25084
-
25085
- flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
25086
- const {explicitType} = context;
25087
-
25088
- if (explicitType === null) {
25089
- return;
25090
- }
25091
-
25092
- if (explicitType !== expectedType) {
25093
- this.flowEnumErrorInvalidMemberInitializer(loc, context);
25094
- }
25095
- }
25096
-
25097
- flowEnumMembers({enumName, explicitType}) {
25098
- const seenNames = /* @__PURE__ */new Set();
25099
- const members = {
25100
- booleanMembers: [],
25101
- numberMembers: [],
25102
- stringMembers: [],
25103
- defaultedMembers: [],
25104
- };
25105
-
25106
- let hasUnknownMembers = false;
25107
-
25108
- while (!this.match(8)) {
25109
- if (this.eat(21)) {
25110
- hasUnknownMembers = true;
25111
- break;
25112
- }
25113
-
25114
- const memberNode = this.startNode();
25115
- const {id, init} = this.flowEnumMemberRaw();
25116
-
25117
- const memberName = id.name;
25118
-
25119
- if (memberName === '') {
25120
- continue;
25121
- }
25122
-
25123
- if (/^[a-z]/.test(memberName)) {
25124
- this.raise(FlowErrors.EnumInvalidMemberName, id, {
25125
- memberName,
25126
- suggestion: memberName[0].toUpperCase() + memberName.slice(1),
25127
- enumName,
25128
- });
25129
- }
25130
-
25131
- if (seenNames.has(memberName)) {
25132
- this.raise(FlowErrors.EnumDuplicateMemberName, id, {
25133
- memberName,
25134
- enumName,
25135
- });
25136
- }
25137
-
25138
- seenNames.add(memberName);
25139
- const context = {
25140
- enumName,
25141
- explicitType,
25142
- memberName,
25143
- };
25144
-
25145
- memberNode.id = id;
25146
- switch(init.type) {
25147
- case 'boolean': {
25148
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'boolean');
25149
- memberNode.init = init.value;
25150
- members.booleanMembers.push(this.finishNode(memberNode, 'EnumBooleanMember'));
25151
- break;
25152
- }
25153
-
25154
- case 'number': {
25155
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'number');
25156
- memberNode.init = init.value;
25157
- members.numberMembers.push(this.finishNode(memberNode, 'EnumNumberMember'));
25158
- break;
25159
- }
25160
-
25161
- case 'string': {
25162
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'string');
25163
- memberNode.init = init.value;
25164
- members.stringMembers.push(this.finishNode(memberNode, 'EnumStringMember'));
25165
- break;
25166
- }
25167
-
25168
- case 'invalid': {
25169
- throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
25170
- }
25171
-
25172
- case 'none': {
25173
- switch(explicitType) {
25174
- case 'boolean':
25175
- this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
25176
- break;
25177
-
25178
- case 'number':
25179
- this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
25180
- break;
25181
-
25182
- default:
25183
- members.defaultedMembers.push(this.finishNode(memberNode, 'EnumDefaultedMember'));
25184
- }
25185
- }
25186
- }
25187
-
25188
- if (!this.match(8)) {
25189
- this.expect(12);
25190
- }
25191
- }
25192
-
25193
- return {
25194
- members,
25195
- hasUnknownMembers,
25196
- };
25197
- }
25198
-
25199
- flowEnumStringMembers(initializedMembers, defaultedMembers, {enumName}) {
25200
- if (initializedMembers.length === 0) {
25201
- return defaultedMembers;
25202
- } else if (defaultedMembers.length === 0) {
25203
- return initializedMembers;
25204
- } else if (defaultedMembers.length > initializedMembers.length) {
25205
- for (const member of initializedMembers) {
25206
- this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
25207
- enumName,
25208
- });
25209
- }
25210
-
25211
- return defaultedMembers;
25212
- } else {
25213
- for (const member of defaultedMembers) {
25214
- this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
25215
- enumName,
25216
- });
25217
- }
25218
-
25219
- return initializedMembers;
25220
- }
25221
-
25222
- }
25223
-
25224
- flowEnumParseExplicitType({enumName}) {
25225
- if (!this.eatContextual(102))
25226
- return null;
25227
-
25228
- if (!tokenIsIdentifier(this.state.type)) {
25229
- throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
25230
- enumName,
25231
- });
25232
- }
25233
-
25234
- const {value} = this.state;
25235
-
25236
- this.next();
25237
-
25238
- if (value !== 'boolean' && value !== 'number' && value !== 'string' && value !== 'symbol') {
25239
- this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
25240
- enumName,
25241
- invalidEnumType: value,
25242
- });
25243
- }
25244
-
25245
- return value;
25246
- }
25247
-
25248
- flowEnumBody(node, id) {
25249
- const enumName = id.name;
25250
- const nameLoc = id.loc.start;
25251
- const explicitType = this.flowEnumParseExplicitType({
25252
- enumName,
25253
- });
25254
-
25255
- this.expect(5);
25256
- const {
25257
- members,
25258
- hasUnknownMembers,
25259
- } = this.flowEnumMembers({
25260
- enumName,
25261
- explicitType,
25262
- });
25263
-
25264
- node.hasUnknownMembers = hasUnknownMembers;
25265
- switch(explicitType) {
25266
- case 'boolean':
25267
- node.explicitType = true;
25268
- node.members = members.booleanMembers;
25269
- this.expect(8);
25270
- return this.finishNode(node, 'EnumBooleanBody');
25271
-
25272
- case 'number':
25273
- node.explicitType = true;
25274
- node.members = members.numberMembers;
25275
- this.expect(8);
25276
- return this.finishNode(node, 'EnumNumberBody');
25277
-
25278
- case 'string':
25279
- node.explicitType = true;
25280
- node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
25281
- enumName,
25282
- });
25283
- this.expect(8);
25284
- return this.finishNode(node, 'EnumStringBody');
25285
-
25286
- case 'symbol':
25287
- node.members = members.defaultedMembers;
25288
- this.expect(8);
25289
- return this.finishNode(node, 'EnumSymbolBody');
25290
-
25291
- default: {
25292
- const empty = () => {
25293
- node.members = [];
25294
- this.expect(8);
25295
- return this.finishNode(node, 'EnumStringBody');
25296
- };
25297
-
25298
- node.explicitType = false;
25299
- const boolsLen = members.booleanMembers.length;
25300
- const numsLen = members.numberMembers.length;
25301
- const strsLen = members.stringMembers.length;
25302
- const defaultedLen = members.defaultedMembers.length;
25303
-
25304
- if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
25305
- return empty();
25306
- } else if (!boolsLen && !numsLen) {
25307
- node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
25308
- enumName,
25309
- });
25310
- this.expect(8);
25311
- return this.finishNode(node, 'EnumStringBody');
25312
- } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
25313
- for (const member of members.defaultedMembers) {
25314
- this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
25315
- enumName,
25316
- memberName: member.id.name,
25317
- });
25318
- }
25319
-
25320
- node.members = members.booleanMembers;
25321
- this.expect(8);
25322
-
25323
- return this.finishNode(node, 'EnumBooleanBody');
25324
- } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
25325
- for (const member of members.defaultedMembers) {
25326
- this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
25327
- enumName,
25328
- memberName: member.id.name,
25329
- });
25330
- }
25331
-
25332
- node.members = members.numberMembers;
25333
- this.expect(8);
25334
-
25335
- return this.finishNode(node, 'EnumNumberBody');
25336
- } else {
25337
- this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
25338
- enumName,
25339
- });
25340
- return empty();
25341
- }
25342
-
25343
-
25344
- }
25345
- }
25346
- }
25347
-
25348
- flowParseEnumDeclaration(node) {
25349
- const id = this.parseIdentifier();
25350
-
25351
- node.id = id;
25352
- node.body = this.flowEnumBody(this.startNode(), id);
25353
- return this.finishNode(node, 'EnumDeclaration');
25354
- }
25355
-
25356
- jsxParseOpeningElementAfterName(node) {
25357
- if (this.shouldParseTypes()) {
25358
- if (this.match(47) || this.match(51)) {
25359
- node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
25360
- }
25361
- }
25362
-
25363
- return super.jsxParseOpeningElementAfterName(node);
25364
- }
25365
-
25366
- isLookaheadToken_lt() {
25367
- const next = this.nextTokenStart();
25368
-
25369
- if (this.input.charCodeAt(next) === 60) {
25370
- const afterNext = this.input.charCodeAt(next + 1);
25371
- return afterNext !== 60 && afterNext !== 61;
25372
- }
25373
-
25374
- return false;
25375
- }
25376
-
25377
- reScan_lt_gt() {
25378
- const {type} = this.state;
25379
-
25380
- if (type === 47) {
25381
- this.state.pos -= 1;
25382
- this.readToken_lt();
25383
- } else if (type === 48) {
25384
- this.state.pos -= 1;
25385
- this.readToken_gt();
25386
- }
25387
- }
25388
-
25389
- reScan_lt() {
25390
- const {type} = this.state;
25391
-
25392
- if (type === 51) {
25393
- this.state.pos -= 2;
25394
- this.finishOp(47, 1);
25395
- return 47;
25396
- }
25397
-
25398
- return type;
25399
- }
25400
-
25401
- maybeUnwrapTypeCastExpression(node) {
25402
- return node.type === 'TypeCastExpression' ? node.expression : node;
25403
- }
25404
- };
25405
-
25406
22285
  var entities = {
25407
22286
  __proto__: null,
25408
22287
  quot: '"',
@@ -33696,7 +30575,6 @@ function validatePlugins(pluginsMap) {
33696
30575
  var mixinPlugins = {
33697
30576
  estree,
33698
30577
  jsx,
33699
- flow,
33700
30578
  typescript,
33701
30579
  v8intrinsic,
33702
30580
  placeholders,