@putout/bundle 4.6.6 → 4.6.7

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/putout.js CHANGED
@@ -11209,196 +11209,15 @@ function isPrivate(node, opts) {
11209
11209
  return opts == null || shallowEqual(node, opts);
11210
11210
  }
11211
11211
 
11212
- function isFlow(node, opts) {
11213
- if (!node)
11214
- return false;
11215
-
11216
- switch(node.type) {
11217
- case 'AnyTypeAnnotation':
11218
- case 'ArrayTypeAnnotation':
11219
- case 'BooleanTypeAnnotation':
11220
- case 'BooleanLiteralTypeAnnotation':
11221
- case 'NullLiteralTypeAnnotation':
11222
- case 'ClassImplements':
11223
- case 'DeclareClass':
11224
- case 'DeclareFunction':
11225
- case 'DeclareInterface':
11226
- case 'DeclareModule':
11227
- case 'DeclareModuleExports':
11228
- case 'DeclareTypeAlias':
11229
- case 'DeclareOpaqueType':
11230
- case 'DeclareVariable':
11231
- case 'DeclareExportDeclaration':
11232
- case 'DeclareExportAllDeclaration':
11233
- case 'DeclaredPredicate':
11234
- case 'ExistsTypeAnnotation':
11235
- case 'FunctionTypeAnnotation':
11236
- case 'FunctionTypeParam':
11237
- case 'GenericTypeAnnotation':
11238
- case 'InferredPredicate':
11239
- case 'InterfaceExtends':
11240
- case 'InterfaceDeclaration':
11241
- case 'InterfaceTypeAnnotation':
11242
- case 'IntersectionTypeAnnotation':
11243
- case 'MixedTypeAnnotation':
11244
- case 'EmptyTypeAnnotation':
11245
- case 'NullableTypeAnnotation':
11246
- case 'NumberLiteralTypeAnnotation':
11247
- case 'NumberTypeAnnotation':
11248
- case 'ObjectTypeAnnotation':
11249
- case 'ObjectTypeInternalSlot':
11250
- case 'ObjectTypeCallProperty':
11251
- case 'ObjectTypeIndexer':
11252
- case 'ObjectTypeProperty':
11253
- case 'ObjectTypeSpreadProperty':
11254
- case 'OpaqueType':
11255
- case 'QualifiedTypeIdentifier':
11256
- case 'StringLiteralTypeAnnotation':
11257
- case 'StringTypeAnnotation':
11258
- case 'SymbolTypeAnnotation':
11259
- case 'ThisTypeAnnotation':
11260
- case 'TupleTypeAnnotation':
11261
- case 'TypeofTypeAnnotation':
11262
- case 'TypeAlias':
11263
- case 'TypeAnnotation':
11264
- case 'TypeCastExpression':
11265
- case 'TypeParameter':
11266
- case 'TypeParameterDeclaration':
11267
- case 'TypeParameterInstantiation':
11268
- case 'UnionTypeAnnotation':
11269
- case 'Variance':
11270
- case 'VoidTypeAnnotation':
11271
- case 'EnumDeclaration':
11272
- case 'EnumBooleanBody':
11273
- case 'EnumNumberBody':
11274
- case 'EnumStringBody':
11275
- case 'EnumSymbolBody':
11276
- case 'EnumBooleanMember':
11277
- case 'EnumNumberMember':
11278
- case 'EnumStringMember':
11279
- case 'EnumDefaultedMember':
11280
- case 'IndexedAccessType':
11281
- case 'OptionalIndexedAccessType':
11282
- break;
11283
-
11284
- default:
11285
- return false;
11286
- }
11287
-
11288
-
11289
- return opts == null || shallowEqual(node, opts);
11290
- }
11212
+ function isFlow() {}
11291
11213
 
11292
- function isFlowType(node, opts) {
11293
- if (!node)
11294
- return false;
11295
-
11296
- switch(node.type) {
11297
- case 'AnyTypeAnnotation':
11298
- case 'ArrayTypeAnnotation':
11299
- case 'BooleanTypeAnnotation':
11300
- case 'BooleanLiteralTypeAnnotation':
11301
- case 'NullLiteralTypeAnnotation':
11302
- case 'ExistsTypeAnnotation':
11303
- case 'FunctionTypeAnnotation':
11304
- case 'GenericTypeAnnotation':
11305
- case 'InterfaceTypeAnnotation':
11306
- case 'IntersectionTypeAnnotation':
11307
- case 'MixedTypeAnnotation':
11308
- case 'EmptyTypeAnnotation':
11309
- case 'NullableTypeAnnotation':
11310
- case 'NumberLiteralTypeAnnotation':
11311
- case 'NumberTypeAnnotation':
11312
- case 'ObjectTypeAnnotation':
11313
- case 'StringLiteralTypeAnnotation':
11314
- case 'StringTypeAnnotation':
11315
- case 'SymbolTypeAnnotation':
11316
- case 'ThisTypeAnnotation':
11317
- case 'TupleTypeAnnotation':
11318
- case 'TypeofTypeAnnotation':
11319
- case 'UnionTypeAnnotation':
11320
- case 'VoidTypeAnnotation':
11321
- case 'IndexedAccessType':
11322
- case 'OptionalIndexedAccessType':
11323
- break;
11324
-
11325
- default:
11326
- return false;
11327
- }
11328
-
11329
-
11330
- return opts == null || shallowEqual(node, opts);
11331
- }
11214
+ function isFlowType() {}
11332
11215
 
11333
- function isFlowBaseAnnotation(node, opts) {
11334
- if (!node)
11335
- return false;
11336
-
11337
- switch(node.type) {
11338
- case 'AnyTypeAnnotation':
11339
- case 'BooleanTypeAnnotation':
11340
- case 'NullLiteralTypeAnnotation':
11341
- case 'MixedTypeAnnotation':
11342
- case 'EmptyTypeAnnotation':
11343
- case 'NumberTypeAnnotation':
11344
- case 'StringTypeAnnotation':
11345
- case 'SymbolTypeAnnotation':
11346
- case 'ThisTypeAnnotation':
11347
- case 'VoidTypeAnnotation':
11348
- break;
11349
-
11350
- default:
11351
- return false;
11352
- }
11353
-
11354
-
11355
- return opts == null || shallowEqual(node, opts);
11356
- }
11216
+ function isFlowBaseAnnotation() {}
11357
11217
 
11358
- function isFlowDeclaration(node, opts) {
11359
- if (!node)
11360
- return false;
11361
-
11362
- switch(node.type) {
11363
- case 'DeclareClass':
11364
- case 'DeclareFunction':
11365
- case 'DeclareInterface':
11366
- case 'DeclareModule':
11367
- case 'DeclareModuleExports':
11368
- case 'DeclareTypeAlias':
11369
- case 'DeclareOpaqueType':
11370
- case 'DeclareVariable':
11371
- case 'DeclareExportDeclaration':
11372
- case 'DeclareExportAllDeclaration':
11373
- case 'InterfaceDeclaration':
11374
- case 'OpaqueType':
11375
- case 'TypeAlias':
11376
- break;
11377
-
11378
- default:
11379
- return false;
11380
- }
11381
-
11382
-
11383
- return opts == null || shallowEqual(node, opts);
11384
- }
11218
+ function isFlowDeclaration() {}
11385
11219
 
11386
- function isFlowPredicate(node, opts) {
11387
- if (!node)
11388
- return false;
11389
-
11390
- switch(node.type) {
11391
- case 'DeclaredPredicate':
11392
- case 'InferredPredicate':
11393
- break;
11394
-
11395
- default:
11396
- return false;
11397
- }
11398
-
11399
-
11400
- return opts == null || shallowEqual(node, opts);
11401
- }
11220
+ function isFlowPredicate() {}
11402
11221
 
11403
11222
  function isEnumBody(node, opts) {
11404
11223
  if (!node)
@@ -21125,7 +20944,7 @@ function removeTypeDuplicates$1(nodesIn) {
21125
20944
  return [node];
21126
20945
  }
21127
20946
 
21128
- if (isFlowBaseAnnotation(node)) {
20947
+ if (isFlowBaseAnnotation()) {
21129
20948
  bases.set(node.type, node);
21130
20949
  continue;
21131
20950
  }
@@ -23942,10 +23761,6 @@ function tokenIsAssignment(token) {
23942
23761
  return token >= 29 && token <= 33;
23943
23762
  }
23944
23763
 
23945
- function tokenIsFlowInterfaceOrTypeOrOpaque(token) {
23946
- return token >= 129 && token <= 131;
23947
- }
23948
-
23949
23764
  function tokenIsLoop(token) {
23950
23765
  return token >= 90 && token <= 92;
23951
23766
  }
@@ -25062,10 +24877,6 @@ function isKeyword2(word) {
25062
24877
  return keywords2.has(word);
25063
24878
  }
25064
24879
 
25065
- function isIteratorStart(current, next, next2) {
25066
- return current === 64 && next === 64 && isIdentifierStart2(next2);
25067
- }
25068
-
25069
24880
  var reservedWordLikeSet = /* @__PURE__ */new Set([
25070
24881
  'break',
25071
24882
  'case',
@@ -25147,3209 +24958,174 @@ var ScopeHandler = class {
25147
24958
  get inFunction() {
25148
24959
  return (this.currentVarScopeFlags() & 2) > 0;
25149
24960
  }
25150
-
25151
- get allowSuper() {
25152
- return (this.currentThisScopeFlags() & 16) > 0;
25153
- }
25154
-
25155
- get allowDirectSuper() {
25156
- return (this.currentThisScopeFlags() & 32) > 0;
25157
- }
25158
-
25159
- get allowNewTarget() {
25160
- return (this.currentThisScopeFlags() & 512) > 0;
25161
- }
25162
-
25163
- get inClass() {
25164
- return (this.currentThisScopeFlags() & 64) > 0;
25165
- }
25166
-
25167
- get inClassAndNotInNonArrowFunction() {
25168
- const flags = this.currentThisScopeFlags();
25169
- return (flags & 64) > 0 && (flags & 2) === 0;
25170
- }
25171
-
25172
- get inStaticBlock() {
25173
- for (let i = this.scopeStack.length - 1;; i--) {
25174
- const {flags} = this.scopeStack[i];
25175
-
25176
- if (flags & 128) {
25177
- return true;
25178
- }
25179
-
25180
- if (flags & (1667 | 64)) {
25181
- return false;
25182
- }
25183
- }
25184
- }
25185
-
25186
- get inNonArrowFunction() {
25187
- return (this.currentThisScopeFlags() & 2) > 0;
25188
- }
25189
-
25190
- get inBareCaseStatement() {
25191
- return (this.currentScope().flags & 256) > 0;
25192
- }
25193
-
25194
- get treatFunctionsAsVar() {
25195
- return this.treatFunctionsAsVarInScope(this.currentScope());
25196
- }
25197
-
25198
- createScope(flags) {
25199
- return new Scope(flags);
25200
- }
25201
-
25202
- enter(flags) {
25203
- this.scopeStack.push(this.createScope(flags));
25204
- }
25205
-
25206
- exit() {
25207
- const scope2 = this.scopeStack.pop();
25208
- return scope2.flags;
25209
- }
25210
-
25211
- treatFunctionsAsVarInScope(scope2) {
25212
- return !!(scope2.flags & (2 | 128) || !this.parser.inModule && scope2.flags & 1);
25213
- }
25214
-
25215
- declareName(name, bindingType, loc) {
25216
- let scope2 = this.currentScope();
25217
-
25218
- if (bindingType & 8 || bindingType & 16) {
25219
- this.checkRedeclarationInScope(scope2, name, bindingType, loc);
25220
- let type = scope2.names.get(name) || 0;
25221
-
25222
- if (bindingType & 16) {
25223
- type = type | 4;
25224
- } else {
25225
- if (!scope2.firstLexicalName) {
25226
- scope2.firstLexicalName = name;
25227
- }
25228
-
25229
- type = type | 2;
25230
- }
25231
-
25232
- scope2.names.set(name, type);
25233
-
25234
- if (bindingType & 8) {
25235
- this.maybeExportDefined(scope2, name);
25236
- }
25237
- } else if (bindingType & 4) {
25238
- for (let i = this.scopeStack.length - 1; i >= 0; --i) {
25239
- scope2 = this.scopeStack[i];
25240
- this.checkRedeclarationInScope(scope2, name, bindingType, loc);
25241
- scope2.names.set(name, (scope2.names.get(name) || 0) | 1);
25242
- this.maybeExportDefined(scope2, name);
25243
-
25244
- if (scope2.flags & 1667)
25245
- break;
25246
- }
25247
- }
25248
-
25249
- if (this.parser.inModule && scope2.flags & 1) {
25250
- this.undefinedExports.delete(name);
25251
- }
25252
- }
25253
-
25254
- maybeExportDefined(scope2, name) {
25255
- if (this.parser.inModule && scope2.flags & 1) {
25256
- this.undefinedExports.delete(name);
25257
- }
25258
- }
25259
-
25260
- checkRedeclarationInScope(scope2, name, bindingType, loc) {
25261
- if (this.isRedeclaredInScope(scope2, name, bindingType)) {
25262
- this.parser.raise(Errors.VarRedeclaration, loc, {
25263
- identifierName: name,
25264
- });
25265
- }
25266
- }
25267
-
25268
- isRedeclaredInScope(scope2, name, bindingType) {
25269
- if (!(bindingType & 1))
25270
- return false;
25271
-
25272
- if (bindingType & 8) {
25273
- return scope2.names.has(name);
25274
- }
25275
-
25276
- const type = scope2.names.get(name);
25277
-
25278
- if (bindingType & 16) {
25279
- return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope2) && (type & 1) > 0;
25280
- }
25281
-
25282
- return (type & 2) > 0 && !(scope2.flags & 8 && scope2.firstLexicalName === name)
25283
- || !this.treatFunctionsAsVarInScope(scope2) && (type & 4) > 0;
25284
- }
25285
-
25286
- checkLocalExport(id) {
25287
- const {name} = id;
25288
-
25289
- const topLevelScope = this.scopeStack[0];
25290
-
25291
- if (!topLevelScope.names.has(name)) {
25292
- this.undefinedExports.set(name, id.loc.start);
25293
- }
25294
- }
25295
-
25296
- currentScope() {
25297
- return this.scopeStack[this.scopeStack.length - 1];
25298
- }
25299
-
25300
- currentVarScopeFlags() {
25301
- for (let i = this.scopeStack.length - 1;; i--) {
25302
- const {flags} = this.scopeStack[i];
25303
-
25304
- if (flags & 1667) {
25305
- return flags;
25306
- }
25307
- }
25308
- }
25309
-
25310
- currentThisScopeFlags() {
25311
- for (let i = this.scopeStack.length - 1;; i--) {
25312
- const {flags} = this.scopeStack[i];
25313
-
25314
- if (flags & (1667 | 64) && !(flags & 4)) {
25315
- return flags;
25316
- }
25317
- }
25318
- }
25319
- };
25320
-
25321
- var FlowScope = class extends Scope {
25322
- constructor() {
25323
- super(...arguments);
25324
- __publicField(this, 'declareFunctions', /* @__PURE__ */new Set());
25325
- }
25326
- };
25327
-
25328
- var FlowScopeHandler = class extends ScopeHandler {
25329
- createScope(flags) {
25330
- return new FlowScope(flags);
25331
- }
25332
-
25333
- declareName(name, bindingType, loc) {
25334
- const scope2 = this.currentScope();
25335
-
25336
- if (bindingType & 2048) {
25337
- this.checkRedeclarationInScope(scope2, name, bindingType, loc);
25338
- this.maybeExportDefined(scope2, name);
25339
- scope2.declareFunctions.add(name);
25340
- return;
25341
- }
25342
-
25343
- super.declareName(name, bindingType, loc);
25344
- }
25345
-
25346
- isRedeclaredInScope(scope2, name, bindingType) {
25347
- if (super.isRedeclaredInScope(scope2, name, bindingType))
25348
- return true;
25349
-
25350
- if (bindingType & 2048 && !scope2.declareFunctions.has(name)) {
25351
- const type = scope2.names.get(name);
25352
- return (type & 4) > 0 || (type & 2) > 0;
25353
- }
25354
-
25355
- return false;
25356
- }
25357
-
25358
- checkLocalExport(id) {
25359
- if (!this.scopeStack[0].declareFunctions.has(id.name)) {
25360
- super.checkLocalExport(id);
25361
- }
25362
- }
25363
- };
25364
-
25365
- var reservedTypes = /* @__PURE__ */new Set([
25366
- '_',
25367
- 'any',
25368
- 'bool',
25369
- 'boolean',
25370
- 'empty',
25371
- 'extends',
25372
- 'false',
25373
- 'interface',
25374
- 'mixed',
25375
- 'null',
25376
- 'number',
25377
- 'static',
25378
- 'string',
25379
- 'true',
25380
- 'typeof',
25381
- 'void',
25382
- ]);
25383
-
25384
- var FlowErrors = ParseErrorEnum`flow`({
25385
- AmbiguousConditionalArrow: 'Ambiguous expression: wrap the arrow functions in parentheses to disambiguate.',
25386
- 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.',
25387
- AssignReservedType: ({reservedType}) => `Cannot overwrite reserved type ${reservedType}.`,
25388
- DeclareClassElement: 'The `declare` modifier can only appear on class fields.',
25389
- DeclareClassFieldInitializer: 'Initializers are not allowed in fields with the `declare` modifier.',
25390
- DuplicateDeclareModuleExports: 'Duplicate `declare module.exports` statement.',
25391
- EnumBooleanMemberNotInitialized: ({memberName, enumName}) => `Boolean enum members need to be initialized. Use either \`${memberName} = true,\` or \`${memberName} = false,\` in enum \`${enumName}\`.`,
25392
- EnumDuplicateMemberName: ({memberName, enumName}) => `Enum member names need to be unique, but the name \`${memberName}\` has already been used before in enum \`${enumName}\`.`,
25393
- 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.`,
25394
- EnumInvalidExplicitType: ({invalidEnumType, enumName}) => `Enum type \`${invalidEnumType}\` is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
25395
- EnumInvalidExplicitTypeUnknownSupplied: ({enumName}) => `Supplied enum type is not valid. Use one of \`boolean\`, \`number\`, \`string\`, or \`symbol\` in enum \`${enumName}\`.`,
25396
- EnumInvalidMemberInitializerPrimaryType: ({enumName, memberName, explicitType}) => `Enum \`${enumName}\` has type \`${explicitType}\`, so the initializer of \`${memberName}\` needs to be a ${explicitType} literal.`,
25397
- EnumInvalidMemberInitializerSymbolType: ({enumName, memberName}) => `Symbol enum members cannot be initialized. Use \`${memberName},\` in enum \`${enumName}\`.`,
25398
- EnumInvalidMemberInitializerUnknownType: ({enumName, memberName}) => `The enum member initializer for \`${memberName}\` needs to be a literal (either a boolean, number, or string) in enum \`${enumName}\`.`,
25399
- EnumInvalidMemberName: ({enumName, memberName, suggestion}) => `Enum member names cannot start with lowercase 'a' through 'z'. Instead of using \`${memberName}\`, consider using \`${suggestion}\`, in enum \`${enumName}\`.`,
25400
- EnumNumberMemberNotInitialized: ({enumName, memberName}) => `Number enum members need to be initialized, e.g. \`${memberName} = 1\` in enum \`${enumName}\`.`,
25401
- EnumStringMemberInconsistentlyInitialized: ({enumName}) => `String enum members need to consistently either all use initializers, or use no initializers, in enum \`${enumName}\`.`,
25402
- GetterMayNotHaveThisParam: 'A getter cannot have a `this` parameter.',
25403
- ImportReflectionHasImportType: 'An `import module` declaration can not use `type` or `typeof` keyword.',
25404
- 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.',
25405
- InexactInsideExact: 'Explicit inexact syntax cannot appear inside an explicit exact object type.',
25406
- InexactInsideNonObject: 'Explicit inexact syntax cannot appear in class or interface definitions.',
25407
- InexactVariance: 'Explicit inexact syntax cannot have variance.',
25408
- InvalidNonTypeImportInDeclareModule: 'Imports within a `declare module` body must always be `import type` or `import typeof`.',
25409
- MissingTypeParamDefault: 'Type parameter declaration needs a default, since a preceding type parameter declaration has a default.',
25410
- NestedDeclareModule: '`declare module` cannot be used inside another `declare module`.',
25411
- NestedFlowComment: 'Cannot have a flow comment inside another flow comment.',
25412
- PatternIsOptional: Object.assign({
25413
- message: 'A binding pattern parameter cannot be optional in an implementation signature.',
25414
- }, {}),
25415
- SetterMayNotHaveThisParam: 'A setter cannot have a `this` parameter.',
25416
- SpreadVariance: 'Spread properties cannot have variance.',
25417
- ThisParamAnnotationRequired: 'A type annotation is required for the `this` parameter.',
25418
- ThisParamBannedInConstructor: 'Constructors cannot have a `this` parameter; constructors don\'t bind `this` like other functions.',
25419
- ThisParamMayNotBeOptional: 'The `this` parameter cannot be optional.',
25420
- ThisParamMustBeFirst: 'The `this` parameter must be the first function parameter.',
25421
- ThisParamNoDefault: 'The `this` parameter may not have a default value.',
25422
- TypeBeforeInitializer: 'Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`.',
25423
- TypeCastInPattern: 'The type cast expression is expected to be wrapped with parenthesis.',
25424
- UnexpectedExplicitInexactInObject: 'Explicit inexact syntax must appear at the end of an inexact object.',
25425
- UnexpectedReservedType: ({reservedType}) => `Unexpected reserved type ${reservedType}.`,
25426
- UnexpectedReservedUnderscore: '`_` is only allowed as a type argument to call or new.',
25427
- UnexpectedSpaceBetweenModuloChecks: 'Spaces between `%` and `checks` are not allowed here.',
25428
- UnexpectedSpreadType: 'Spread operator cannot appear in class or interface definitions.',
25429
- UnexpectedSubtractionOperand: 'Unexpected token, expected "number" or "bigint".',
25430
- UnexpectedTokenAfterTypeParameter: 'Expected an arrow function after this type parameter declaration.',
25431
- UnexpectedTypeParameterBeforeAsyncArrowFunction: 'Type parameters must come after the async keyword, e.g. instead of `<T> async () => {}`, use `async <T>() => {}`.',
25432
- UnsupportedDeclareExportKind: ({unsupportedExportKind, suggestion}) => `\`declare export ${unsupportedExportKind}\` is not supported. Use \`${suggestion}\` instead.`,
25433
- UnsupportedStatementInDeclareModule: 'Only declares and type imports are allowed inside declare module.',
25434
- UnterminatedFlowComment: 'Unterminated flow-comment.',
25435
- });
25436
-
25437
- function isEsModuleType(bodyElement) {
25438
- return bodyElement.type === 'DeclareExportAllDeclaration'
25439
- || bodyElement.type === 'DeclareExportDeclaration'
25440
- && (!bodyElement.declaration
25441
- || bodyElement.declaration.type !== 'TypeAlias'
25442
- && bodyElement.declaration.type !== 'InterfaceDeclaration');
25443
- }
25444
-
25445
- function hasTypeImportKind(node) {
25446
- return node.importKind === 'type' || node.importKind === 'typeof';
25447
- }
25448
-
25449
- var exportSuggestions = {
25450
- const: 'declare export var',
25451
- let: 'declare export var',
25452
- type: 'export type',
25453
- interface: 'export interface',
25454
- };
25455
-
25456
- function partition(list, test) {
25457
- const list1 = [];
25458
- const list2 = [];
25459
-
25460
- for (let i = 0; i < list.length; i++) {
25461
- (test(list[i], i, list) ? list1 : list2).push(list[i]);
25462
- }
25463
-
25464
- return [list1, list2];
25465
- }
25466
-
25467
- var FLOW_PRAGMA_REGEX = /\*?\s*@((?:no)?flow)\b/;
25468
-
25469
- var flow = (superClass) => class FlowParserMixin extends superClass {
25470
- constructor() {
25471
- super(...arguments);
25472
- __publicField(this, 'flowPragma');
25473
- }
25474
-
25475
- getScopeHandler() {
25476
- return FlowScopeHandler;
25477
- }
25478
-
25479
- shouldParseTypes() {
25480
- return this.getPluginOption('flow', 'all') || this.flowPragma === 'flow';
25481
- }
25482
-
25483
- finishToken(type, val) {
25484
- if (type !== 134 && type !== 13 && type !== 28) {
25485
- if (this.flowPragma === void 0) {
25486
- this.flowPragma = null;
25487
- }
25488
- }
25489
-
25490
- super.finishToken(type, val);
25491
- }
25492
-
25493
- addComment(comment) {
25494
- if (this.flowPragma === void 0) {
25495
- const matches = FLOW_PRAGMA_REGEX.exec(comment.value);
25496
-
25497
- if (!matches);
25498
- else if (matches[1] === 'flow') {
25499
- this.flowPragma = 'flow';
25500
- } else if (matches[1] === 'noflow') {
25501
- this.flowPragma = 'noflow';
25502
- } else {
25503
- throw new Error('Unexpected flow pragma');
25504
- }
25505
-
25506
- }
25507
-
25508
- super.addComment(comment);
25509
- }
25510
-
25511
- flowParseTypeInitialiser(tok) {
25512
- const oldInType = this.state.inType;
25513
-
25514
- this.state.inType = true;
25515
- this.expect(tok || 14);
25516
- const type = this.flowParseType();
25517
-
25518
- this.state.inType = oldInType;
25519
- return type;
25520
- }
25521
-
25522
- flowParsePredicate() {
25523
- const node = this.startNode();
25524
- const moduloLoc = this.state.startLoc;
25525
- this.next();
25526
- this.expectContextual(110);
25527
-
25528
- if (this.state.lastTokStartLoc.index > moduloLoc.index + 1) {
25529
- this.raise(FlowErrors.UnexpectedSpaceBetweenModuloChecks, moduloLoc);
25530
- }
25531
-
25532
- if (this.eat(10)) {
25533
- node.value = super.parseExpression();
25534
- this.expect(11);
25535
- return this.finishNode(node, 'DeclaredPredicate');
25536
- } else {
25537
- return this.finishNode(node, 'InferredPredicate');
25538
- }
25539
- }
25540
-
25541
- flowParseTypeAndPredicateInitialiser() {
25542
- const oldInType = this.state.inType;
25543
-
25544
- this.state.inType = true;
25545
- this.expect(14);
25546
- let type = null;
25547
- let predicate = null;
25548
-
25549
- if (this.match(54)) {
25550
- this.state.inType = oldInType;
25551
- predicate = this.flowParsePredicate();
25552
- } else {
25553
- type = this.flowParseType();
25554
- this.state.inType = oldInType;
25555
-
25556
- if (this.match(54)) {
25557
- predicate = this.flowParsePredicate();
25558
- }
25559
- }
25560
-
25561
- return [type, predicate];
25562
- }
25563
-
25564
- flowParseDeclareClass(node) {
25565
- this.next();
25566
- this.flowParseInterfaceish(node, true);
25567
- return this.finishNode(node, 'DeclareClass');
25568
- }
25569
-
25570
- flowParseDeclareFunction(node) {
25571
- this.next();
25572
- const id = node.id = this.parseIdentifier();
25573
- const typeNode = this.startNode();
25574
- const typeContainer = this.startNode();
25575
-
25576
- if (this.match(47)) {
25577
- typeNode.typeParameters = this.flowParseTypeParameterDeclaration();
25578
- } else {
25579
- typeNode.typeParameters = null;
25580
- }
25581
-
25582
- this.expect(10);
25583
- const tmp = this.flowParseFunctionTypeParams();
25584
-
25585
- typeNode.params = tmp.params;
25586
- typeNode.rest = tmp.rest;
25587
- typeNode.this = tmp._this;
25588
- this.expect(11);
25589
- [typeNode.returnType, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
25590
- typeContainer.typeAnnotation = this.finishNode(typeNode, 'FunctionTypeAnnotation');
25591
- id.typeAnnotation = this.finishNode(typeContainer, 'TypeAnnotation');
25592
- this.resetEndLocation(id);
25593
- this.semicolon();
25594
- this.scope.declareName(node.id.name, 2048, node.id.loc.start);
25595
- return this.finishNode(node, 'DeclareFunction');
25596
- }
25597
-
25598
- flowParseDeclare(node, insideModule) {
25599
- if (this.match(80)) {
25600
- return this.flowParseDeclareClass(node);
25601
- } else if (this.match(68)) {
25602
- return this.flowParseDeclareFunction(node);
25603
- } else if (this.match(74)) {
25604
- return this.flowParseDeclareVariable(node);
25605
- } else if (this.eatContextual(127)) {
25606
- if (this.match(16)) {
25607
- return this.flowParseDeclareModuleExports(node);
25608
- } else {
25609
- if (insideModule) {
25610
- this.raise(FlowErrors.NestedDeclareModule, this.state.lastTokStartLoc);
25611
- }
25612
-
25613
- return this.flowParseDeclareModule(node);
25614
- }
25615
- } else if (this.isContextual(130)) {
25616
- return this.flowParseDeclareTypeAlias(node);
25617
- } else if (this.isContextual(131)) {
25618
- return this.flowParseDeclareOpaqueType(node);
25619
- } else if (this.isContextual(129)) {
25620
- return this.flowParseDeclareInterface(node);
25621
- } else if (this.match(82)) {
25622
- return this.flowParseDeclareExportDeclaration(node, insideModule);
25623
- } else {
25624
- this.unexpected();
25625
- }
25626
-
25627
-
25628
-
25629
-
25630
-
25631
-
25632
- }
25633
-
25634
- flowParseDeclareVariable(node) {
25635
- this.next();
25636
- node.id = this.flowParseTypeAnnotatableIdentifier(true);
25637
- this.scope.declareName(node.id.name, 5, node.id.loc.start);
25638
- this.semicolon();
25639
- return this.finishNode(node, 'DeclareVariable');
25640
- }
25641
-
25642
- flowParseDeclareModule(node) {
25643
- this.scope.enter(0);
25644
-
25645
- if (this.match(134)) {
25646
- node.id = super.parseExprAtom();
25647
- } else {
25648
- node.id = this.parseIdentifier();
25649
- }
25650
-
25651
- const bodyNode = node.body = this.startNode();
25652
- const body = bodyNode.body = [];
25653
-
25654
- this.expect(5);
25655
- while (!this.match(8)) {
25656
- let bodyNode2 = this.startNode();
25657
-
25658
- if (this.match(83)) {
25659
- this.next();
25660
-
25661
- if (!this.isContextual(130) && !this.match(87)) {
25662
- this.raise(FlowErrors.InvalidNonTypeImportInDeclareModule, this.state.lastTokStartLoc);
25663
- }
25664
-
25665
- super.parseImport(bodyNode2);
25666
- } else {
25667
- this.expectContextual(125, FlowErrors.UnsupportedStatementInDeclareModule);
25668
- bodyNode2 = this.flowParseDeclare(bodyNode2, true);
25669
- }
25670
-
25671
- body.push(bodyNode2);
25672
- }
25673
-
25674
- this.scope.exit();
25675
- this.expect(8);
25676
- this.finishNode(bodyNode, 'BlockStatement');
25677
- let kind = null;
25678
- let hasModuleExport = false;
25679
-
25680
- body.forEach((bodyElement) => {
25681
- if (isEsModuleType(bodyElement)) {
25682
- if (kind === 'CommonJS') {
25683
- this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
25684
- }
25685
-
25686
- kind = 'ES';
25687
- } else if (bodyElement.type === 'DeclareModuleExports') {
25688
- if (hasModuleExport) {
25689
- this.raise(FlowErrors.DuplicateDeclareModuleExports, bodyElement);
25690
- }
25691
-
25692
- if (kind === 'ES') {
25693
- this.raise(FlowErrors.AmbiguousDeclareModuleKind, bodyElement);
25694
- }
25695
-
25696
- kind = 'CommonJS';
25697
- hasModuleExport = true;
25698
- }
25699
- });
25700
- node.kind = kind || 'CommonJS';
25701
- return this.finishNode(node, 'DeclareModule');
25702
- }
25703
-
25704
- flowParseDeclareExportDeclaration(node, insideModule) {
25705
- this.expect(82);
25706
-
25707
- if (this.eat(65)) {
25708
- if (this.match(68) || this.match(80)) {
25709
- node.declaration = this.flowParseDeclare(this.startNode());
25710
- } else {
25711
- node.declaration = this.flowParseType();
25712
- this.semicolon();
25713
- }
25714
-
25715
- node.default = true;
25716
- return this.finishNode(node, 'DeclareExportDeclaration');
25717
- } else {
25718
- if (this.match(75) || this.isLet() || (this.isContextual(130) || this.isContextual(129)) && !insideModule) {
25719
- const label = this.state.value;
25720
-
25721
- throw this.raise(FlowErrors.UnsupportedDeclareExportKind, this.state.startLoc, {
25722
- unsupportedExportKind: label,
25723
- suggestion: exportSuggestions[label],
25724
- });
25725
- }
25726
-
25727
- if (this.match(74) || this.match(68) || this.match(80) || this.isContextual(131)) {
25728
- node.declaration = this.flowParseDeclare(this.startNode());
25729
- node.default = false;
25730
- return this.finishNode(node, 'DeclareExportDeclaration');
25731
- } else if (this.match(55) || this.match(5) || this.isContextual(129) || this.isContextual(130) || this.isContextual(131)) {
25732
- node = this.parseExport(node, null);
25733
-
25734
- if (node.type === 'ExportNamedDeclaration') {
25735
- node.default = false;
25736
- delete node.exportKind;
25737
- return this.castNodeTo(node, 'DeclareExportDeclaration');
25738
- } else {
25739
- return this.castNodeTo(node, 'DeclareExportAllDeclaration');
25740
- }
25741
- }
25742
- }
25743
-
25744
- this.unexpected();
25745
- }
25746
-
25747
- flowParseDeclareModuleExports(node) {
25748
- this.next();
25749
- this.expectContextual(111);
25750
- node.typeAnnotation = this.flowParseTypeAnnotation();
25751
- this.semicolon();
25752
- return this.finishNode(node, 'DeclareModuleExports');
25753
- }
25754
-
25755
- flowParseDeclareTypeAlias(node) {
25756
- this.next();
25757
- const finished = this.flowParseTypeAlias(node);
25758
- this.castNodeTo(finished, 'DeclareTypeAlias');
25759
- return finished;
25760
- }
25761
-
25762
- flowParseDeclareOpaqueType(node) {
25763
- this.next();
25764
- const finished = this.flowParseOpaqueType(node, true);
25765
- this.castNodeTo(finished, 'DeclareOpaqueType');
25766
- return finished;
25767
- }
25768
-
25769
- flowParseDeclareInterface(node) {
25770
- this.next();
25771
- this.flowParseInterfaceish(node, false);
25772
- return this.finishNode(node, 'DeclareInterface');
25773
- }
25774
-
25775
- flowParseInterfaceish(node, isClass3) {
25776
- node.id = this.flowParseRestrictedIdentifier(!isClass3, true);
25777
- this.scope.declareName(node.id.name, isClass3 ? 17 : 8201, node.id.loc.start);
25778
-
25779
- if (this.match(47)) {
25780
- node.typeParameters = this.flowParseTypeParameterDeclaration();
25781
- } else {
25782
- node.typeParameters = null;
25783
- }
25784
-
25785
- node.extends = [];
25786
-
25787
- if (this.eat(81)) {
25788
- do {
25789
- node.extends.push(this.flowParseInterfaceExtends());
25790
- } while (!isClass3 && this.eat(12))
25791
- }
25792
-
25793
- if (isClass3) {
25794
- node.implements = [];
25795
- node.mixins = [];
25796
-
25797
- if (this.eatContextual(117)) {
25798
- do {
25799
- node.mixins.push(this.flowParseInterfaceExtends());
25800
- } while (this.eat(12))
25801
- }
25802
-
25803
- if (this.eatContextual(113)) {
25804
- do {
25805
- node.implements.push(this.flowParseInterfaceExtends());
25806
- } while (this.eat(12))
25807
- }
25808
- }
25809
-
25810
- node.body = this.flowParseObjectType({
25811
- allowStatic: isClass3,
25812
- allowExact: false,
25813
- allowSpread: false,
25814
- allowProto: isClass3,
25815
- allowInexact: false,
25816
- });
25817
- }
25818
-
25819
- flowParseInterfaceExtends() {
25820
- const node = this.startNode();
25821
-
25822
- node.id = this.flowParseQualifiedTypeIdentifier();
25823
-
25824
- if (this.match(47)) {
25825
- node.typeParameters = this.flowParseTypeParameterInstantiation();
25826
- } else {
25827
- node.typeParameters = null;
25828
- }
25829
-
25830
- return this.finishNode(node, 'InterfaceExtends');
25831
- }
25832
-
25833
- flowParseInterface(node) {
25834
- this.flowParseInterfaceish(node, false);
25835
- return this.finishNode(node, 'InterfaceDeclaration');
25836
- }
25837
-
25838
- checkNotUnderscore(word) {
25839
- if (word === '_') {
25840
- this.raise(FlowErrors.UnexpectedReservedUnderscore, this.state.startLoc);
25841
- }
25842
- }
25843
-
25844
- checkReservedType(word, startLoc, declaration) {
25845
- if (!reservedTypes.has(word))
25846
- return;
25847
-
25848
- this.raise(declaration ? FlowErrors.AssignReservedType : FlowErrors.UnexpectedReservedType, startLoc, {
25849
- reservedType: word,
25850
- });
25851
- }
25852
-
25853
- flowParseRestrictedIdentifier(liberal, declaration) {
25854
- this.checkReservedType(this.state.value, this.state.startLoc, declaration);
25855
- return this.parseIdentifier(liberal);
25856
- }
25857
-
25858
- flowParseTypeAlias(node) {
25859
- node.id = this.flowParseRestrictedIdentifier(false, true);
25860
- this.scope.declareName(node.id.name, 8201, node.id.loc.start);
25861
-
25862
- if (this.match(47)) {
25863
- node.typeParameters = this.flowParseTypeParameterDeclaration();
25864
- } else {
25865
- node.typeParameters = null;
25866
- }
25867
-
25868
- node.right = this.flowParseTypeInitialiser(29);
25869
- this.semicolon();
25870
- return this.finishNode(node, 'TypeAlias');
25871
- }
25872
-
25873
- flowParseOpaqueType(node, declare) {
25874
- this.expectContextual(130);
25875
- node.id = this.flowParseRestrictedIdentifier(true, true);
25876
- this.scope.declareName(node.id.name, 8201, node.id.loc.start);
25877
-
25878
- if (this.match(47)) {
25879
- node.typeParameters = this.flowParseTypeParameterDeclaration();
25880
- } else {
25881
- node.typeParameters = null;
25882
- }
25883
-
25884
- node.supertype = null;
25885
-
25886
- if (this.match(14)) {
25887
- node.supertype = this.flowParseTypeInitialiser(14);
25888
- }
25889
-
25890
- node.impltype = null;
25891
-
25892
- if (!declare) {
25893
- node.impltype = this.flowParseTypeInitialiser(29);
25894
- }
25895
-
25896
- this.semicolon();
25897
- return this.finishNode(node, 'OpaqueType');
25898
- }
25899
-
25900
- flowParseTypeParameter(requireDefault = false) {
25901
- const nodeStartLoc = this.state.startLoc;
25902
- const node = this.startNode();
25903
- const variance2 = this.flowParseVariance();
25904
- const ident = this.flowParseTypeAnnotatableIdentifier();
25905
-
25906
- node.name = ident.name;
25907
- node.variance = variance2;
25908
- node.bound = ident.typeAnnotation;
25909
-
25910
- if (this.match(29)) {
25911
- this.eat(29);
25912
- node.default = this.flowParseType();
25913
- } else {
25914
- if (requireDefault) {
25915
- this.raise(FlowErrors.MissingTypeParamDefault, nodeStartLoc);
25916
- }
25917
- }
25918
-
25919
- return this.finishNode(node, 'TypeParameter');
25920
- }
25921
-
25922
- flowParseTypeParameterDeclaration() {
25923
- const oldInType = this.state.inType;
25924
- const node = this.startNode();
25925
-
25926
- node.params = [];
25927
- this.state.inType = true;
25928
-
25929
- if (this.match(47) || this.match(143)) {
25930
- this.next();
25931
- } else {
25932
- this.unexpected();
25933
- }
25934
-
25935
- let defaultRequired = false;
25936
-
25937
- do {
25938
- const typeParameter2 = this.flowParseTypeParameter(defaultRequired);
25939
- node.params.push(typeParameter2);
25940
-
25941
- if (typeParameter2.default) {
25942
- defaultRequired = true;
25943
- }
25944
-
25945
- if (!this.match(48)) {
25946
- this.expect(12);
25947
- }
25948
- } while (!this.match(48))
25949
- this.expect(48);
25950
- this.state.inType = oldInType;
25951
- return this.finishNode(node, 'TypeParameterDeclaration');
25952
- }
25953
-
25954
- flowInTopLevelContext(cb) {
25955
- if (this.curContext() !== types$17.brace) {
25956
- const oldContext = this.state.context;
25957
-
25958
- this.state.context = [oldContext[0]];
25959
- try {
25960
- return cb();
25961
- } finally {
25962
- this.state.context = oldContext;
25963
- }
25964
- } else {
25965
- return cb();
25966
- }
25967
- }
25968
-
25969
- flowParseTypeParameterInstantiationInExpression() {
25970
- if (this.reScan_lt() !== 47)
25971
- return;
25972
-
25973
- return this.flowParseTypeParameterInstantiation();
25974
- }
25975
-
25976
- flowParseTypeParameterInstantiation() {
25977
- const node = this.startNode();
25978
- const oldInType = this.state.inType;
25979
-
25980
- this.state.inType = true;
25981
- node.params = [];
25982
- this.flowInTopLevelContext(() => {
25983
- this.expect(47);
25984
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
25985
-
25986
- this.state.noAnonFunctionType = false;
25987
- while (!this.match(48)) {
25988
- node.params.push(this.flowParseType());
25989
-
25990
- if (!this.match(48)) {
25991
- this.expect(12);
25992
- }
25993
- }
25994
-
25995
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
25996
- });
25997
- this.state.inType = oldInType;
25998
-
25999
- if (!this.state.inType && this.curContext() === types$17.brace) {
26000
- this.reScan_lt_gt();
26001
- }
26002
-
26003
- this.expect(48);
26004
- return this.finishNode(node, 'TypeParameterInstantiation');
26005
- }
26006
-
26007
- flowParseTypeParameterInstantiationCallOrNew() {
26008
- if (this.reScan_lt() !== 47)
26009
- return;
26010
-
26011
- const node = this.startNode();
26012
- const oldInType = this.state.inType;
26013
-
26014
- node.params = [];
26015
- this.state.inType = true;
26016
- this.expect(47);
26017
- while (!this.match(48)) {
26018
- node.params.push(this.flowParseTypeOrImplicitInstantiation());
26019
-
26020
- if (!this.match(48)) {
26021
- this.expect(12);
26022
- }
26023
- }
26024
-
26025
- this.expect(48);
26026
- this.state.inType = oldInType;
26027
- return this.finishNode(node, 'TypeParameterInstantiation');
26028
- }
26029
-
26030
- flowParseInterfaceType() {
26031
- const node = this.startNode();
26032
- this.expectContextual(129);
26033
- node.extends = [];
26034
-
26035
- if (this.eat(81)) {
26036
- do {
26037
- node.extends.push(this.flowParseInterfaceExtends());
26038
- } while (this.eat(12))
26039
- }
26040
-
26041
- node.body = this.flowParseObjectType({
26042
- allowStatic: false,
26043
- allowExact: false,
26044
- allowSpread: false,
26045
- allowProto: false,
26046
- allowInexact: false,
26047
- });
26048
- return this.finishNode(node, 'InterfaceTypeAnnotation');
26049
- }
26050
-
26051
- flowParseObjectPropertyKey() {
26052
- return this.match(135) || this.match(134) ? super.parseExprAtom() : this.parseIdentifier(true);
26053
- }
26054
-
26055
- flowParseObjectTypeIndexer(node, isStatic2, variance2) {
26056
- node.static = isStatic2;
26057
-
26058
- if (this.lookahead().type === 14) {
26059
- node.id = this.flowParseObjectPropertyKey();
26060
- node.key = this.flowParseTypeInitialiser();
26061
- } else {
26062
- node.id = null;
26063
- node.key = this.flowParseType();
26064
- }
26065
-
26066
- this.expect(3);
26067
- node.value = this.flowParseTypeInitialiser();
26068
- node.variance = variance2;
26069
- return this.finishNode(node, 'ObjectTypeIndexer');
26070
- }
26071
-
26072
- flowParseObjectTypeInternalSlot(node, isStatic2) {
26073
- node.static = isStatic2;
26074
- node.id = this.flowParseObjectPropertyKey();
26075
- this.expect(3);
26076
- this.expect(3);
26077
-
26078
- if (this.match(47) || this.match(10)) {
26079
- node.method = true;
26080
- node.optional = false;
26081
- node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
26082
- } else {
26083
- node.method = false;
26084
-
26085
- if (this.eat(17)) {
26086
- node.optional = true;
26087
- }
26088
-
26089
- node.value = this.flowParseTypeInitialiser();
26090
- }
26091
-
26092
- return this.finishNode(node, 'ObjectTypeInternalSlot');
26093
- }
26094
-
26095
- flowParseObjectTypeMethodish(node) {
26096
- node.params = [];
26097
- node.rest = null;
26098
- node.typeParameters = null;
26099
- node.this = null;
26100
-
26101
- if (this.match(47)) {
26102
- node.typeParameters = this.flowParseTypeParameterDeclaration();
26103
- }
26104
-
26105
- this.expect(10);
26106
-
26107
- if (this.match(78)) {
26108
- node.this = this.flowParseFunctionTypeParam(true);
26109
- node.this.name = null;
26110
-
26111
- if (!this.match(11)) {
26112
- this.expect(12);
26113
- }
26114
- }
26115
-
26116
- while (!this.match(11) && !this.match(21)) {
26117
- node.params.push(this.flowParseFunctionTypeParam(false));
26118
-
26119
- if (!this.match(11)) {
26120
- this.expect(12);
26121
- }
26122
- }
26123
-
26124
- if (this.eat(21)) {
26125
- node.rest = this.flowParseFunctionTypeParam(false);
26126
- }
26127
-
26128
- this.expect(11);
26129
- node.returnType = this.flowParseTypeInitialiser();
26130
- return this.finishNode(node, 'FunctionTypeAnnotation');
26131
- }
26132
-
26133
- flowParseObjectTypeCallProperty(node, isStatic2) {
26134
- const valueNode = this.startNode();
26135
-
26136
- node.static = isStatic2;
26137
- node.value = this.flowParseObjectTypeMethodish(valueNode);
26138
- return this.finishNode(node, 'ObjectTypeCallProperty');
26139
- }
26140
-
26141
- flowParseObjectType({allowStatic, allowExact, allowSpread, allowProto, allowInexact}) {
26142
- const oldInType = this.state.inType;
26143
-
26144
- this.state.inType = true;
26145
- const nodeStart = this.startNode();
26146
-
26147
- nodeStart.callProperties = [];
26148
- nodeStart.properties = [];
26149
- nodeStart.indexers = [];
26150
- nodeStart.internalSlots = [];
26151
- let endDelim;
26152
- let exact;
26153
- let inexact = false;
26154
-
26155
- if (allowExact && this.match(6)) {
26156
- this.expect(6);
26157
- endDelim = 9;
26158
- exact = true;
26159
- } else {
26160
- this.expect(5);
26161
- endDelim = 8;
26162
- exact = false;
26163
- }
26164
-
26165
- nodeStart.exact = exact;
26166
- while (!this.match(endDelim)) {
26167
- let isStatic2 = false;
26168
- let protoStartLoc = null;
26169
- let inexactStartLoc = null;
26170
- const node = this.startNode();
26171
-
26172
- if (allowProto && this.isContextual(118)) {
26173
- const lookahead = this.lookahead();
26174
-
26175
- if (lookahead.type !== 14 && lookahead.type !== 17) {
26176
- this.next();
26177
- protoStartLoc = this.state.startLoc;
26178
- allowStatic = false;
26179
- }
26180
- }
26181
-
26182
- if (allowStatic && this.isContextual(106)) {
26183
- const lookahead = this.lookahead();
26184
-
26185
- if (lookahead.type !== 14 && lookahead.type !== 17) {
26186
- this.next();
26187
- isStatic2 = true;
26188
- }
26189
- }
26190
-
26191
- const variance2 = this.flowParseVariance();
26192
-
26193
- if (this.eat(0)) {
26194
- if (protoStartLoc != null) {
26195
- this.unexpected(protoStartLoc);
26196
- }
26197
-
26198
- if (this.eat(0)) {
26199
- if (variance2) {
26200
- this.unexpected(variance2.loc.start);
26201
- }
26202
-
26203
- nodeStart.internalSlots.push(this.flowParseObjectTypeInternalSlot(node, isStatic2));
26204
- } else {
26205
- nodeStart.indexers.push(this.flowParseObjectTypeIndexer(node, isStatic2, variance2));
26206
- }
26207
- } else if (this.match(10) || this.match(47)) {
26208
- if (protoStartLoc != null) {
26209
- this.unexpected(protoStartLoc);
26210
- }
26211
-
26212
- if (variance2) {
26213
- this.unexpected(variance2.loc.start);
26214
- }
26215
-
26216
- nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, isStatic2));
26217
- } else {
26218
- let kind = 'init';
26219
-
26220
- if (this.isContextual(99) || this.isContextual(104)) {
26221
- const lookahead = this.lookahead();
26222
-
26223
- if (tokenIsLiteralPropertyName(lookahead.type)) {
26224
- kind = this.state.value;
26225
- this.next();
26226
- }
26227
- }
26228
-
26229
- const propOrInexact = this.flowParseObjectTypeProperty(node, isStatic2, protoStartLoc, variance2, kind, allowSpread, allowInexact ?? !exact);
26230
-
26231
- if (propOrInexact === null) {
26232
- inexact = true;
26233
- inexactStartLoc = this.state.lastTokStartLoc;
26234
- } else {
26235
- nodeStart.properties.push(propOrInexact);
26236
- }
26237
- }
26238
-
26239
- this.flowObjectTypeSemicolon();
26240
-
26241
- if (inexactStartLoc && !this.match(8) && !this.match(9)) {
26242
- this.raise(FlowErrors.UnexpectedExplicitInexactInObject, inexactStartLoc);
26243
- }
26244
- }
26245
-
26246
- this.expect(endDelim);
26247
-
26248
- if (allowSpread) {
26249
- nodeStart.inexact = inexact;
26250
- }
26251
-
26252
- const out = this.finishNode(nodeStart, 'ObjectTypeAnnotation');
26253
-
26254
- this.state.inType = oldInType;
26255
- return out;
26256
- }
26257
-
26258
- flowParseObjectTypeProperty(node, isStatic2, protoStartLoc, variance2, kind, allowSpread, allowInexact) {
26259
- if (this.eat(21)) {
26260
- const isInexactToken = this.match(12)
26261
- || this.match(13)
26262
- || this.match(8)
26263
- || this.match(9);
26264
-
26265
- if (isInexactToken) {
26266
- if (!allowSpread) {
26267
- this.raise(FlowErrors.InexactInsideNonObject, this.state.lastTokStartLoc);
26268
- } else if (!allowInexact) {
26269
- this.raise(FlowErrors.InexactInsideExact, this.state.lastTokStartLoc);
26270
- }
26271
-
26272
- if (variance2) {
26273
- this.raise(FlowErrors.InexactVariance, variance2);
26274
- }
26275
-
26276
- return null;
26277
- }
26278
-
26279
- if (!allowSpread) {
26280
- this.raise(FlowErrors.UnexpectedSpreadType, this.state.lastTokStartLoc);
26281
- }
26282
-
26283
- if (protoStartLoc != null) {
26284
- this.unexpected(protoStartLoc);
26285
- }
26286
-
26287
- if (variance2) {
26288
- this.raise(FlowErrors.SpreadVariance, variance2);
26289
- }
26290
-
26291
- node.argument = this.flowParseType();
26292
- return this.finishNode(node, 'ObjectTypeSpreadProperty');
26293
- } else {
26294
- node.key = this.flowParseObjectPropertyKey();
26295
- node.static = isStatic2;
26296
- node.proto = protoStartLoc != null;
26297
- node.kind = kind;
26298
- let optional = false;
26299
-
26300
- if (this.match(47) || this.match(10)) {
26301
- node.method = true;
26302
-
26303
- if (protoStartLoc != null) {
26304
- this.unexpected(protoStartLoc);
26305
- }
26306
-
26307
- if (variance2) {
26308
- this.unexpected(variance2.loc.start);
26309
- }
26310
-
26311
- node.value = this.flowParseObjectTypeMethodish(this.startNodeAt(node.loc.start));
26312
-
26313
- if (kind === 'get' || kind === 'set') {
26314
- this.flowCheckGetterSetterParams(node);
26315
- }
26316
-
26317
- if (!allowSpread && node.key.name === 'constructor' && node.value.this) {
26318
- this.raise(FlowErrors.ThisParamBannedInConstructor, node.value.this);
26319
- }
26320
- } else {
26321
- if (kind !== 'init')
26322
- this.unexpected();
26323
-
26324
- node.method = false;
26325
-
26326
- if (this.eat(17)) {
26327
- optional = true;
26328
- }
26329
-
26330
- node.value = this.flowParseTypeInitialiser();
26331
- node.variance = variance2;
26332
- }
26333
-
26334
- node.optional = optional;
26335
- return this.finishNode(node, 'ObjectTypeProperty');
26336
- }
26337
- }
26338
-
26339
- flowCheckGetterSetterParams(property) {
26340
- const paramCount = property.kind === 'get' ? 0 : 1;
26341
- const length = property.value.params.length + (property.value.rest ? 1 : 0);
26342
-
26343
- if (property.value.this) {
26344
- this.raise(property.kind === 'get' ? FlowErrors.GetterMayNotHaveThisParam : FlowErrors.SetterMayNotHaveThisParam, property.value.this);
26345
- }
26346
-
26347
- if (length !== paramCount) {
26348
- this.raise(property.kind === 'get' ? Errors.BadGetterArity : Errors.BadSetterArity, property);
26349
- }
26350
-
26351
- if (property.kind === 'set' && property.value.rest) {
26352
- this.raise(Errors.BadSetterRestParameter, property);
26353
- }
26354
- }
26355
-
26356
- flowObjectTypeSemicolon() {
26357
- if (!this.eat(13) && !this.eat(12) && !this.match(8) && !this.match(9)) {
26358
- this.unexpected();
26359
- }
26360
- }
26361
-
26362
- flowParseQualifiedTypeIdentifier(startLoc, id) {
26363
- startLoc ?? (startLoc = this.state.startLoc);
26364
- let node = id || this.flowParseRestrictedIdentifier(true);
26365
-
26366
- while (this.eat(16)) {
26367
- const node2 = this.startNodeAt(startLoc);
26368
-
26369
- node2.qualification = node;
26370
- node2.id = this.flowParseRestrictedIdentifier(true);
26371
- node = this.finishNode(node2, 'QualifiedTypeIdentifier');
26372
- }
26373
-
26374
- return node;
26375
- }
26376
-
26377
- flowParseGenericType(startLoc, id) {
26378
- const node = this.startNodeAt(startLoc);
26379
-
26380
- node.typeParameters = null;
26381
- node.id = this.flowParseQualifiedTypeIdentifier(startLoc, id);
26382
-
26383
- if (this.match(47)) {
26384
- node.typeParameters = this.flowParseTypeParameterInstantiation();
26385
- }
26386
-
26387
- return this.finishNode(node, 'GenericTypeAnnotation');
26388
- }
26389
-
26390
- flowParseTypeofType() {
26391
- const node = this.startNode();
26392
- this.expect(87);
26393
- node.argument = this.flowParsePrimaryType();
26394
- return this.finishNode(node, 'TypeofTypeAnnotation');
26395
- }
26396
-
26397
- flowParseTupleType() {
26398
- const node = this.startNode();
26399
-
26400
- node.types = [];
26401
- this.expect(0);
26402
- while (this.state.pos < this.length && !this.match(3)) {
26403
- node.types.push(this.flowParseType());
26404
-
26405
- if (this.match(3))
26406
- break;
26407
-
26408
- this.expect(12);
26409
- }
26410
-
26411
- this.expect(3);
26412
- return this.finishNode(node, 'TupleTypeAnnotation');
26413
- }
26414
-
26415
- flowParseFunctionTypeParam(first) {
26416
- let name = null;
26417
- let optional = false;
26418
- let typeAnnotation2 = null;
26419
- const node = this.startNode();
26420
- const lh = this.lookahead();
26421
- const isThis = this.state.type === 78;
26422
-
26423
- if (lh.type === 14 || lh.type === 17) {
26424
- if (isThis && !first) {
26425
- this.raise(FlowErrors.ThisParamMustBeFirst, node);
26426
- }
26427
-
26428
- name = this.parseIdentifier(isThis);
26429
-
26430
- if (this.eat(17)) {
26431
- optional = true;
26432
-
26433
- if (isThis) {
26434
- this.raise(FlowErrors.ThisParamMayNotBeOptional, node);
26435
- }
26436
- }
26437
-
26438
- typeAnnotation2 = this.flowParseTypeInitialiser();
26439
- } else {
26440
- typeAnnotation2 = this.flowParseType();
26441
- }
26442
-
26443
- node.name = name;
26444
- node.optional = optional;
26445
- node.typeAnnotation = typeAnnotation2;
26446
- return this.finishNode(node, 'FunctionTypeParam');
26447
- }
26448
-
26449
- reinterpretTypeAsFunctionTypeParam(type) {
26450
- const node = this.startNodeAt(type.loc.start);
26451
-
26452
- node.name = null;
26453
- node.optional = false;
26454
- node.typeAnnotation = type;
26455
- return this.finishNode(node, 'FunctionTypeParam');
26456
- }
26457
-
26458
- flowParseFunctionTypeParams(params = []) {
26459
- let rest = null;
26460
- let _this = null;
26461
-
26462
- if (this.match(78)) {
26463
- _this = this.flowParseFunctionTypeParam(true);
26464
- _this.name = null;
26465
-
26466
- if (!this.match(11)) {
26467
- this.expect(12);
26468
- }
26469
- }
26470
-
26471
- while (!this.match(11) && !this.match(21)) {
26472
- params.push(this.flowParseFunctionTypeParam(false));
26473
-
26474
- if (!this.match(11)) {
26475
- this.expect(12);
26476
- }
26477
- }
26478
-
26479
- if (this.eat(21)) {
26480
- rest = this.flowParseFunctionTypeParam(false);
26481
- }
26482
-
26483
- return {
26484
- params,
26485
- rest,
26486
- _this,
26487
- };
26488
- }
26489
-
26490
- flowIdentToTypeAnnotation(startLoc, node, id) {
26491
- switch(id.name) {
26492
- case 'any':
26493
- return this.finishNode(node, 'AnyTypeAnnotation');
26494
-
26495
- case 'bool':
26496
- case 'boolean':
26497
- return this.finishNode(node, 'BooleanTypeAnnotation');
26498
-
26499
- case 'mixed':
26500
- return this.finishNode(node, 'MixedTypeAnnotation');
26501
-
26502
- case 'empty':
26503
- return this.finishNode(node, 'EmptyTypeAnnotation');
26504
-
26505
- case 'number':
26506
- return this.finishNode(node, 'NumberTypeAnnotation');
26507
-
26508
- case 'string':
26509
- return this.finishNode(node, 'StringTypeAnnotation');
26510
-
26511
- case 'symbol':
26512
- return this.finishNode(node, 'SymbolTypeAnnotation');
26513
-
26514
- default:
26515
- this.checkNotUnderscore(id.name);
26516
- return this.flowParseGenericType(startLoc, id);
26517
- }
26518
- }
26519
-
26520
- flowParsePrimaryType() {
26521
- const startLoc = this.state.startLoc;
26522
- const node = this.startNode();
26523
- let tmp;
26524
- let type;
26525
- let isGroupedType = false;
26526
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
26527
-
26528
- switch(this.state.type) {
26529
- case 5:
26530
- return this.flowParseObjectType({
26531
- allowStatic: false,
26532
- allowExact: false,
26533
- allowSpread: true,
26534
- allowProto: false,
26535
- allowInexact: true,
26536
- });
26537
-
26538
- case 6:
26539
- return this.flowParseObjectType({
26540
- allowStatic: false,
26541
- allowExact: true,
26542
- allowSpread: true,
26543
- allowProto: false,
26544
- allowInexact: false,
26545
- });
26546
-
26547
- case 0:
26548
- this.state.noAnonFunctionType = false;
26549
- type = this.flowParseTupleType();
26550
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
26551
- return type;
26552
-
26553
- case 47: {
26554
- const node2 = this.startNode();
26555
-
26556
- node2.typeParameters = this.flowParseTypeParameterDeclaration();
26557
- this.expect(10);
26558
- tmp = this.flowParseFunctionTypeParams();
26559
- node2.params = tmp.params;
26560
- node2.rest = tmp.rest;
26561
- node2.this = tmp._this;
26562
- this.expect(11);
26563
- this.expect(19);
26564
- node2.returnType = this.flowParseType();
26565
- return this.finishNode(node2, 'FunctionTypeAnnotation');
26566
- }
26567
-
26568
- case 10: {
26569
- const node2 = this.startNode();
26570
- this.next();
26571
-
26572
- if (!this.match(11) && !this.match(21)) {
26573
- if (tokenIsIdentifier(this.state.type) || this.match(78)) {
26574
- const token = this.lookahead().type;
26575
- isGroupedType = token !== 17 && token !== 14;
26576
- } else {
26577
- isGroupedType = true;
26578
- }
26579
- }
26580
-
26581
- if (isGroupedType) {
26582
- this.state.noAnonFunctionType = false;
26583
- type = this.flowParseType();
26584
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
26585
-
26586
- if (this.state.noAnonFunctionType || !(this.match(12) || this.match(11) && this.lookahead().type === 19)) {
26587
- this.expect(11);
26588
- return type;
26589
- } else {
26590
- this.eat(12);
26591
- }
26592
- }
26593
-
26594
- if (type) {
26595
- tmp = this.flowParseFunctionTypeParams([this.reinterpretTypeAsFunctionTypeParam(type)]);
26596
- } else {
26597
- tmp = this.flowParseFunctionTypeParams();
26598
- }
26599
-
26600
- node2.params = tmp.params;
26601
- node2.rest = tmp.rest;
26602
- node2.this = tmp._this;
26603
- this.expect(11);
26604
- this.expect(19);
26605
- node2.returnType = this.flowParseType();
26606
- node2.typeParameters = null;
26607
- return this.finishNode(node2, 'FunctionTypeAnnotation');
26608
- }
26609
-
26610
- case 134:
26611
- return this.parseLiteral(this.state.value, 'StringLiteralTypeAnnotation');
26612
-
26613
- case 85:
26614
- case 86:
26615
- node.value = this.match(85);
26616
- this.next();
26617
- return this.finishNode(node, 'BooleanLiteralTypeAnnotation');
26618
-
26619
- case 53:
26620
- if (this.state.value === '-') {
26621
- this.next();
26622
-
26623
- if (this.match(135)) {
26624
- return this.parseLiteralAtNode(-this.state.value, 'NumberLiteralTypeAnnotation', node);
26625
- }
26626
-
26627
- if (this.match(136)) {
26628
- return this.parseLiteralAtNode(-this.state.value, 'BigIntLiteralTypeAnnotation', node);
26629
- }
26630
-
26631
- throw this.raise(FlowErrors.UnexpectedSubtractionOperand, this.state.startLoc);
26632
- }
26633
-
26634
- this.unexpected();
26635
- return;
26636
-
26637
- case 135:
26638
- return this.parseLiteral(this.state.value, 'NumberLiteralTypeAnnotation');
26639
-
26640
- case 136:
26641
- return this.parseLiteral(this.state.value, 'BigIntLiteralTypeAnnotation');
26642
-
26643
- case 88:
26644
- this.next();
26645
- return this.finishNode(node, 'VoidTypeAnnotation');
26646
-
26647
- case 84:
26648
- this.next();
26649
- return this.finishNode(node, 'NullLiteralTypeAnnotation');
26650
-
26651
- case 78:
26652
- this.next();
26653
- return this.finishNode(node, 'ThisTypeAnnotation');
26654
-
26655
- case 55:
26656
- this.next();
26657
- return this.finishNode(node, 'ExistsTypeAnnotation');
26658
-
26659
- case 87:
26660
- return this.flowParseTypeofType();
26661
-
26662
- default:
26663
- if (tokenIsKeyword(this.state.type)) {
26664
- const label = tokenLabelName(this.state.type);
26665
- this.next();
26666
- return super.createIdentifier(node, label);
26667
- } else if (tokenIsIdentifier(this.state.type)) {
26668
- if (this.isContextual(129)) {
26669
- return this.flowParseInterfaceType();
26670
- }
26671
-
26672
- return this.flowIdentToTypeAnnotation(startLoc, node, this.parseIdentifier());
26673
- }
26674
- }
26675
-
26676
- this.unexpected();
26677
- }
26678
-
26679
- flowParsePostfixType() {
26680
- const startLoc = this.state.startLoc;
26681
- let type = this.flowParsePrimaryType();
26682
- let seenOptionalIndexedAccess = false;
26683
-
26684
- while ((this.match(0) || this.match(18)) && !this.canInsertSemicolon()) {
26685
- const node = this.startNodeAt(startLoc);
26686
- const optional = this.eat(18);
26687
-
26688
- seenOptionalIndexedAccess = seenOptionalIndexedAccess || optional;
26689
- this.expect(0);
26690
-
26691
- if (!optional && this.match(3)) {
26692
- node.elementType = type;
26693
- this.next();
26694
- type = this.finishNode(node, 'ArrayTypeAnnotation');
26695
- } else {
26696
- node.objectType = type;
26697
- node.indexType = this.flowParseType();
26698
- this.expect(3);
26699
-
26700
- if (seenOptionalIndexedAccess) {
26701
- node.optional = optional;
26702
- type = this.finishNode(node, 'OptionalIndexedAccessType');
26703
- } else {
26704
- type = this.finishNode(node, 'IndexedAccessType');
26705
- }
26706
- }
26707
- }
26708
-
26709
- return type;
26710
- }
26711
-
26712
- flowParsePrefixType() {
26713
- const node = this.startNode();
26714
-
26715
- if (this.eat(17)) {
26716
- node.typeAnnotation = this.flowParsePrefixType();
26717
- return this.finishNode(node, 'NullableTypeAnnotation');
26718
- } else {
26719
- return this.flowParsePostfixType();
26720
- }
26721
- }
26722
-
26723
- flowParseAnonFunctionWithoutParens() {
26724
- const param = this.flowParsePrefixType();
26725
-
26726
- if (!this.state.noAnonFunctionType && this.eat(19)) {
26727
- const node = this.startNodeAt(param.loc.start);
26728
-
26729
- node.params = [
26730
- this.reinterpretTypeAsFunctionTypeParam(param),
26731
- ];
26732
- node.rest = null;
26733
- node.this = null;
26734
- node.returnType = this.flowParseType();
26735
- node.typeParameters = null;
26736
- return this.finishNode(node, 'FunctionTypeAnnotation');
26737
- }
26738
-
26739
- return param;
26740
- }
26741
-
26742
- flowParseIntersectionType() {
26743
- const node = this.startNode();
26744
- this.eat(45);
26745
- const type = this.flowParseAnonFunctionWithoutParens();
26746
-
26747
- node.types = [type];
26748
- while (this.eat(45)) {
26749
- node.types.push(this.flowParseAnonFunctionWithoutParens());
26750
- }
26751
-
26752
- return node.types.length === 1 ? type : this.finishNode(node, 'IntersectionTypeAnnotation');
26753
- }
26754
-
26755
- flowParseUnionType() {
26756
- const node = this.startNode();
26757
- this.eat(43);
26758
- const type = this.flowParseIntersectionType();
26759
-
26760
- node.types = [type];
26761
- while (this.eat(43)) {
26762
- node.types.push(this.flowParseIntersectionType());
26763
- }
26764
-
26765
- return node.types.length === 1 ? type : this.finishNode(node, 'UnionTypeAnnotation');
26766
- }
26767
-
26768
- flowParseType() {
26769
- const oldInType = this.state.inType;
26770
-
26771
- this.state.inType = true;
26772
- const type = this.flowParseUnionType();
26773
-
26774
- this.state.inType = oldInType;
26775
- return type;
26776
- }
26777
-
26778
- flowParseTypeOrImplicitInstantiation() {
26779
- if (this.state.type === 132 && this.state.value === '_') {
26780
- const startLoc = this.state.startLoc;
26781
- const node = this.parseIdentifier();
26782
-
26783
- return this.flowParseGenericType(startLoc, node);
26784
- } else {
26785
- return this.flowParseType();
26786
- }
26787
- }
26788
-
26789
- flowParseTypeAnnotation() {
26790
- const node = this.startNode();
26791
-
26792
- node.typeAnnotation = this.flowParseTypeInitialiser();
26793
- return this.finishNode(node, 'TypeAnnotation');
26794
- }
26795
-
26796
- flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride) {
26797
- const ident = allowPrimitiveOverride ? this.parseIdentifier() : this.flowParseRestrictedIdentifier();
26798
-
26799
- if (this.match(14)) {
26800
- ident.typeAnnotation = this.flowParseTypeAnnotation();
26801
- this.resetEndLocation(ident);
26802
- }
26803
-
26804
- return ident;
26805
- }
26806
-
26807
- typeCastToParameter(node) {
26808
- node.expression.typeAnnotation = node.typeAnnotation;
26809
- this.resetEndLocation(node.expression, node.typeAnnotation.loc.end);
26810
- return node.expression;
26811
- }
26812
-
26813
- flowParseVariance() {
26814
- let variance2 = null;
26815
-
26816
- if (this.match(53)) {
26817
- variance2 = this.startNode();
26818
-
26819
- if (this.state.value === '+') {
26820
- variance2.kind = 'plus';
26821
- } else {
26822
- variance2.kind = 'minus';
26823
- }
26824
-
26825
- this.next();
26826
- return this.finishNode(variance2, 'Variance');
26827
- }
26828
-
26829
- return variance2;
26830
- }
26831
-
26832
- parseFunctionBody(node, allowExpressionBody, isMethod3 = false) {
26833
- if (allowExpressionBody) {
26834
- this.forwardNoArrowParamsConversionAt(node, () => super.parseFunctionBody(node, true, isMethod3));
26835
- return;
26836
- }
26837
-
26838
- super.parseFunctionBody(node, false, isMethod3);
26839
- }
26840
-
26841
- parseFunctionBodyAndFinish(node, type, isMethod3 = false) {
26842
- if (this.match(14)) {
26843
- const typeNode = this.startNode();
26844
-
26845
- [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
26846
- node.returnType = typeNode.typeAnnotation ? this.finishNode(typeNode, 'TypeAnnotation') : null;
26847
- }
26848
-
26849
- return super.parseFunctionBodyAndFinish(node, type, isMethod3);
26850
- }
26851
-
26852
- parseStatementLike(flags) {
26853
- if (this.state.strict && this.isContextual(129)) {
26854
- const lookahead = this.lookahead();
26855
-
26856
- if (tokenIsKeywordOrIdentifier(lookahead.type)) {
26857
- const node = this.startNode();
26858
- this.next();
26859
- return this.flowParseInterface(node);
26860
- }
26861
- } else if (this.isContextual(126)) {
26862
- const node = this.startNode();
26863
- this.next();
26864
- return this.flowParseEnumDeclaration(node);
26865
- }
26866
-
26867
- const stmt = super.parseStatementLike(flags);
26868
-
26869
- if (this.flowPragma === void 0 && !this.isValidDirective(stmt)) {
26870
- this.flowPragma = null;
26871
- }
26872
-
26873
- return stmt;
26874
- }
26875
-
26876
- parseExpressionStatement(node, expr, decorators) {
26877
- if (expr.type === 'Identifier') {
26878
- if (expr.name === 'declare') {
26879
- if (this.match(80) || tokenIsIdentifier(this.state.type) || this.match(68) || this.match(74) || this.match(82)) {
26880
- return this.flowParseDeclare(node);
26881
- }
26882
- } else if (tokenIsIdentifier(this.state.type)) {
26883
- if (expr.name === 'interface') {
26884
- return this.flowParseInterface(node);
26885
- } else if (expr.name === 'type') {
26886
- return this.flowParseTypeAlias(node);
26887
- } else if (expr.name === 'opaque') {
26888
- return this.flowParseOpaqueType(node, false);
26889
- }
26890
-
26891
- }
26892
- }
26893
-
26894
- return super.parseExpressionStatement(node, expr, decorators);
26895
- }
26896
-
26897
- shouldParseExportDeclaration() {
26898
- const {type} = this.state;
26899
-
26900
- if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
26901
- return !this.state.containsEsc;
26902
- }
26903
-
26904
- return super.shouldParseExportDeclaration();
26905
- }
26906
-
26907
- isExportDefaultSpecifier() {
26908
- const {type} = this.state;
26909
-
26910
- if (type === 126 || tokenIsFlowInterfaceOrTypeOrOpaque(type)) {
26911
- return this.state.containsEsc;
26912
- }
26913
-
26914
- return super.isExportDefaultSpecifier();
26915
- }
26916
-
26917
- parseExportDefaultExpression() {
26918
- if (this.isContextual(126)) {
26919
- const node = this.startNode();
26920
- this.next();
26921
- return this.flowParseEnumDeclaration(node);
26922
- }
26923
-
26924
- return super.parseExportDefaultExpression();
26925
- }
26926
-
26927
- parseConditional(expr, startLoc, refExpressionErrors) {
26928
- if (!this.match(17))
26929
- return expr;
26930
-
26931
- if (this.state.maybeInArrowParameters) {
26932
- const nextCh = this.lookaheadCharCode();
26933
-
26934
- if (nextCh === 44 || nextCh === 61 || nextCh === 58 || nextCh === 41) {
26935
- this.setOptionalParametersError(refExpressionErrors);
26936
- return expr;
26937
- }
26938
- }
26939
-
26940
- this.expect(17);
26941
- const state = this.state.clone();
26942
- const originalNoArrowAt = this.state.noArrowAt;
26943
- const node = this.startNodeAt(startLoc);
26944
-
26945
- let {consequent, failed} = this.tryParseConditionalConsequent();
26946
-
26947
- let [valid, invalid] = this.getArrowLikeExpressions(consequent);
26948
-
26949
- if (failed || invalid.length > 0) {
26950
- const noArrowAt = [...originalNoArrowAt];
26951
-
26952
- if (invalid.length > 0) {
26953
- this.state = state;
26954
- this.state.noArrowAt = noArrowAt;
26955
- for (let i = 0; i < invalid.length; i++) {
26956
- noArrowAt.push(invalid[i].start);
26957
- }
26958
-
26959
- ({
26960
- consequent,
26961
- failed,
26962
- } = this.tryParseConditionalConsequent());
26963
- [valid, invalid] = this.getArrowLikeExpressions(consequent);
26964
- }
26965
-
26966
- if (failed && valid.length > 1) {
26967
- this.raise(FlowErrors.AmbiguousConditionalArrow, state.startLoc);
26968
- }
26969
-
26970
- if (failed && valid.length === 1) {
26971
- this.state = state;
26972
- noArrowAt.push(valid[0].start);
26973
- this.state.noArrowAt = noArrowAt;
26974
- ({
26975
- consequent,
26976
- failed,
26977
- } = this.tryParseConditionalConsequent());
26978
- }
26979
- }
26980
-
26981
- this.getArrowLikeExpressions(consequent, true);
26982
- this.state.noArrowAt = originalNoArrowAt;
26983
- this.expect(14);
26984
- node.test = expr;
26985
- node.consequent = consequent;
26986
- node.alternate = this.forwardNoArrowParamsConversionAt(node, () => this.parseMaybeAssign(void 0, void 0));
26987
-
26988
- return this.finishNode(node, 'ConditionalExpression');
26989
- }
26990
-
26991
- tryParseConditionalConsequent() {
26992
- this.state.noArrowParamsConversionAt.push(this.state.start);
26993
- const consequent = this.parseMaybeAssignAllowIn();
26994
- const failed = !this.match(14);
26995
-
26996
- this.state.noArrowParamsConversionAt.pop();
26997
- return {
26998
- consequent,
26999
- failed,
27000
- };
27001
- }
27002
-
27003
- getArrowLikeExpressions(node, disallowInvalid) {
27004
- const stack = [node];
27005
- const arrows = [];
27006
-
27007
- while (stack.length !== 0) {
27008
- const node2 = stack.pop();
27009
-
27010
- if (node2.type === 'ArrowFunctionExpression' && node2.body.type !== 'BlockStatement') {
27011
- if (node2.typeParameters || !node2.returnType) {
27012
- this.finishArrowValidation(node2);
27013
- } else {
27014
- arrows.push(node2);
27015
- }
27016
-
27017
- stack.push(node2.body);
27018
- } else if (node2.type === 'ConditionalExpression') {
27019
- stack.push(node2.consequent);
27020
- stack.push(node2.alternate);
27021
- }
27022
- }
27023
-
27024
- if (disallowInvalid) {
27025
- arrows.forEach((node2) => this.finishArrowValidation(node2));
27026
- return [
27027
- arrows,
27028
- [],
27029
- ];
27030
- }
27031
-
27032
- return partition(arrows, (node2) => node2.params.every((param) => this.isAssignable(param, true)));
27033
- }
27034
-
27035
- finishArrowValidation(node) {
27036
- this.toAssignableList(node.params, node.extra?.trailingCommaLoc, false);
27037
- this.scope.enter(514 | 4);
27038
- super.checkParams(node, false, true);
27039
- this.scope.exit();
27040
- }
27041
-
27042
- forwardNoArrowParamsConversionAt(node, parse3) {
27043
- let result;
27044
-
27045
- if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
27046
- this.state.noArrowParamsConversionAt.push(this.state.start);
27047
- result = parse3();
27048
- this.state.noArrowParamsConversionAt.pop();
27049
- } else {
27050
- result = parse3();
27051
- }
27052
-
27053
- return result;
27054
- }
27055
-
27056
- parseParenItem(node, startLoc) {
27057
- const newNode = super.parseParenItem(node, startLoc);
27058
-
27059
- if (this.eat(17)) {
27060
- newNode.optional = true;
27061
- this.resetEndLocation(node);
27062
- }
27063
-
27064
- if (this.match(14)) {
27065
- const typeCastNode = this.startNodeAt(startLoc);
27066
-
27067
- typeCastNode.expression = newNode;
27068
- typeCastNode.typeAnnotation = this.flowParseTypeAnnotation();
27069
- return this.finishNode(typeCastNode, 'TypeCastExpression');
27070
- }
27071
-
27072
- return newNode;
27073
- }
27074
-
27075
- assertModuleNodeAllowed(node) {
27076
- if (node.type === 'ImportDeclaration' && (node.importKind === 'type' || node.importKind === 'typeof') || node.type === 'ExportNamedDeclaration' && node.exportKind === 'type' || node.type === 'ExportAllDeclaration' && node.exportKind === 'type') {
27077
- return;
27078
- }
27079
-
27080
- super.assertModuleNodeAllowed(node);
27081
- }
27082
-
27083
- parseExportDeclaration(node) {
27084
- if (this.isContextual(130)) {
27085
- node.exportKind = 'type';
27086
- const declarationNode = this.startNode();
27087
- this.next();
27088
-
27089
- if (this.match(5)) {
27090
- node.specifiers = this.parseExportSpecifiers(true);
27091
- super.parseExportFrom(node);
27092
- return null;
27093
- } else {
27094
- return this.flowParseTypeAlias(declarationNode);
27095
- }
27096
- } else if (this.isContextual(131)) {
27097
- node.exportKind = 'type';
27098
- const declarationNode = this.startNode();
27099
- this.next();
27100
- return this.flowParseOpaqueType(declarationNode, false);
27101
- } else if (this.isContextual(129)) {
27102
- node.exportKind = 'type';
27103
- const declarationNode = this.startNode();
27104
- this.next();
27105
- return this.flowParseInterface(declarationNode);
27106
- } else if (this.isContextual(126)) {
27107
- node.exportKind = 'value';
27108
- const declarationNode = this.startNode();
27109
- this.next();
27110
- return this.flowParseEnumDeclaration(declarationNode);
27111
- } else {
27112
- return super.parseExportDeclaration(node);
27113
- }
27114
-
27115
-
27116
- }
27117
-
27118
- eatExportStar(node) {
27119
- if (super.eatExportStar(node))
27120
- return true;
27121
-
27122
- if (this.isContextual(130) && this.lookahead().type === 55) {
27123
- node.exportKind = 'type';
27124
- this.next();
27125
- this.next();
27126
- return true;
27127
- }
27128
-
27129
- return false;
27130
- }
27131
-
27132
- maybeParseExportNamespaceSpecifier(node) {
27133
- const {startLoc} = this.state;
27134
-
27135
- const hasNamespace = super.maybeParseExportNamespaceSpecifier(node);
27136
-
27137
- if (hasNamespace && node.exportKind === 'type') {
27138
- this.unexpected(startLoc);
27139
- }
27140
-
27141
- return hasNamespace;
27142
- }
27143
-
27144
- parseClassId(node, isStatement5, optionalId) {
27145
- super.parseClassId(node, isStatement5, optionalId);
27146
-
27147
- if (this.match(47)) {
27148
- node.typeParameters = this.flowParseTypeParameterDeclaration();
27149
- }
27150
- }
27151
-
27152
- parseClassMember(classBody2, member, state) {
27153
- const {startLoc} = this.state;
27154
-
27155
- if (this.isContextual(125)) {
27156
- if (super.parseClassMemberFromModifier(classBody2, member)) {
27157
- return;
27158
- }
27159
-
27160
- member.declare = true;
27161
- }
27162
-
27163
- super.parseClassMember(classBody2, member, state);
27164
-
27165
- if (member.declare) {
27166
- if (member.type !== 'ClassProperty' && member.type !== 'ClassPrivateProperty' && member.type !== 'PropertyDefinition') {
27167
- this.raise(FlowErrors.DeclareClassElement, startLoc);
27168
- } else if (member.value) {
27169
- this.raise(FlowErrors.DeclareClassFieldInitializer, member.value);
27170
- }
27171
- }
27172
- }
27173
-
27174
- isIterator(word) {
27175
- return word === 'iterator' || word === 'asyncIterator';
27176
- }
27177
-
27178
- readIterator() {
27179
- const word = super.readWord1();
27180
- const fullWord = '@@' + word;
27181
-
27182
- if (!this.isIterator(word) || !this.state.inType) {
27183
- this.raise(Errors.InvalidIdentifier, this.state.curPosition(), {
27184
- identifierName: fullWord,
27185
- });
27186
- }
27187
-
27188
- this.finishToken(132, fullWord);
27189
- }
27190
-
27191
- getTokenFromCode(code2) {
27192
- const next = this.input.charCodeAt(this.state.pos + 1);
27193
-
27194
- if (code2 === 123 && next === 124) {
27195
- this.finishOp(6, 2);
27196
- } else if (this.state.inType && (code2 === 62 || code2 === 60)) {
27197
- this.finishOp(code2 === 62 ? 48 : 47, 1);
27198
- } else if (this.state.inType && code2 === 63) {
27199
- if (next === 46) {
27200
- this.finishOp(18, 2);
27201
- } else {
27202
- this.finishOp(17, 1);
27203
- }
27204
- } else if (isIteratorStart(code2, next, this.input.charCodeAt(this.state.pos + 2))) {
27205
- this.state.pos += 2;
27206
- this.readIterator();
27207
- } else {
27208
- super.getTokenFromCode(code2);
27209
- }
27210
-
27211
-
27212
- }
27213
-
27214
- isAssignable(node, isBinding3) {
27215
- if (node.type === 'TypeCastExpression') {
27216
- return this.isAssignable(node.expression, isBinding3);
27217
- } else {
27218
- return super.isAssignable(node, isBinding3);
27219
- }
27220
- }
27221
-
27222
- toAssignable(node, isLHS = false) {
27223
- if (!isLHS && node.type === 'AssignmentExpression' && node.left.type === 'TypeCastExpression') {
27224
- node.left = this.typeCastToParameter(node.left);
27225
- }
27226
-
27227
- super.toAssignable(node, isLHS);
27228
- }
27229
-
27230
- toAssignableList(exprList, trailingCommaLoc, isLHS) {
27231
- for (let i = 0; i < exprList.length; i++) {
27232
- const expr = exprList[i];
27233
-
27234
- if (expr?.type === 'TypeCastExpression') {
27235
- exprList[i] = this.typeCastToParameter(expr);
27236
- }
27237
- }
27238
-
27239
- super.toAssignableList(exprList, trailingCommaLoc, isLHS);
27240
- }
27241
-
27242
- toReferencedList(exprList, isParenthesizedExpr) {
27243
- for (let i = 0; i < exprList.length; i++) {
27244
- const expr = exprList[i];
27245
-
27246
- if (expr && expr.type === 'TypeCastExpression' && !expr.extra?.parenthesized && (exprList.length > 1 || !isParenthesizedExpr)) {
27247
- this.raise(FlowErrors.TypeCastInPattern, expr.typeAnnotation);
27248
- }
27249
- }
27250
-
27251
- return exprList;
27252
- }
27253
-
27254
- parseArrayLike(close, canBePattern, isTuple, refExpressionErrors) {
27255
- const node = super.parseArrayLike(close, canBePattern, isTuple, refExpressionErrors);
27256
-
27257
- if (canBePattern && !this.state.maybeInArrowParameters) {
27258
- this.toReferencedList(node.elements);
27259
- }
27260
-
27261
- return node;
27262
- }
27263
-
27264
- isValidLVal(type, isParenthesized, binding) {
27265
- return type === 'TypeCastExpression' || super.isValidLVal(type, isParenthesized, binding);
27266
- }
27267
-
27268
- parseClassProperty(node) {
27269
- if (this.match(14)) {
27270
- node.typeAnnotation = this.flowParseTypeAnnotation();
27271
- }
27272
-
27273
- return super.parseClassProperty(node);
27274
- }
27275
-
27276
- parseClassPrivateProperty(node) {
27277
- if (this.match(14)) {
27278
- node.typeAnnotation = this.flowParseTypeAnnotation();
27279
- }
27280
-
27281
- return super.parseClassPrivateProperty(node);
27282
- }
27283
-
27284
- isClassMethod() {
27285
- return this.match(47) || super.isClassMethod();
27286
- }
27287
-
27288
- isClassProperty() {
27289
- return this.match(14) || super.isClassProperty();
27290
- }
27291
-
27292
- isNonstaticConstructor(method) {
27293
- return !this.match(14) && super.isNonstaticConstructor(method);
27294
- }
27295
-
27296
- pushClassMethod(classBody2, method, isGenerator, isAsync, isConstructor, allowsDirectSuper) {
27297
- if (method.variance) {
27298
- this.unexpected(method.variance.loc.start);
27299
- }
27300
-
27301
- delete method.variance;
27302
-
27303
- if (this.match(47)) {
27304
- method.typeParameters = this.flowParseTypeParameterDeclaration();
27305
- }
27306
-
27307
- super.pushClassMethod(classBody2, method, isGenerator, isAsync, isConstructor, allowsDirectSuper);
27308
-
27309
- if (method.params && isConstructor) {
27310
- const params = method.params;
27311
-
27312
- if (params.length > 0 && this.isThisParam(params[0])) {
27313
- this.raise(FlowErrors.ThisParamBannedInConstructor, method);
27314
- }
27315
- } else if (method.type === 'MethodDefinition' && isConstructor && method.value.params) {
27316
- const params = method.value.params;
27317
-
27318
- if (params.length > 0 && this.isThisParam(params[0])) {
27319
- this.raise(FlowErrors.ThisParamBannedInConstructor, method);
27320
- }
27321
- }
27322
- }
27323
-
27324
- pushClassPrivateMethod(classBody2, method, isGenerator, isAsync) {
27325
- if (method.variance) {
27326
- this.unexpected(method.variance.loc.start);
27327
- }
27328
-
27329
- delete method.variance;
27330
-
27331
- if (this.match(47)) {
27332
- method.typeParameters = this.flowParseTypeParameterDeclaration();
27333
- }
27334
-
27335
- super.pushClassPrivateMethod(classBody2, method, isGenerator, isAsync);
27336
- }
27337
-
27338
- parseClassSuper(node) {
27339
- super.parseClassSuper(node);
27340
-
27341
- if (node.superClass && (this.match(47) || this.match(51))) {
27342
- {
27343
- node.superTypeArguments = this.flowParseTypeParameterInstantiationInExpression();
27344
- }
27345
- }
27346
-
27347
- if (this.isContextual(113)) {
27348
- this.next();
27349
- const implemented = node.implements = [];
27350
-
27351
- do {
27352
- const node2 = this.startNode();
27353
-
27354
- node2.id = this.flowParseRestrictedIdentifier(true);
27355
-
27356
- if (this.match(47)) {
27357
- node2.typeParameters = this.flowParseTypeParameterInstantiation();
27358
- } else {
27359
- node2.typeParameters = null;
27360
- }
27361
-
27362
- implemented.push(this.finishNode(node2, 'ClassImplements'));
27363
- } while (this.eat(12))
27364
- }
27365
- }
27366
-
27367
- checkGetterSetterParams(method) {
27368
- super.checkGetterSetterParams(method);
27369
- const params = this.getObjectOrClassMethodParams(method);
27370
-
27371
- if (params.length > 0) {
27372
- const param = params[0];
27373
-
27374
- if (this.isThisParam(param) && method.kind === 'get') {
27375
- this.raise(FlowErrors.GetterMayNotHaveThisParam, param);
27376
- } else if (this.isThisParam(param)) {
27377
- this.raise(FlowErrors.SetterMayNotHaveThisParam, param);
27378
- }
27379
- }
27380
- }
27381
-
27382
- parsePropertyNamePrefixOperator(node) {
27383
- node.variance = this.flowParseVariance();
27384
- }
27385
-
27386
- parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern3, isAccessor2, refExpressionErrors) {
27387
- if (prop.variance) {
27388
- this.unexpected(prop.variance.loc.start);
27389
- }
27390
-
27391
- delete prop.variance;
27392
- let typeParameters;
27393
-
27394
- if (this.match(47) && !isAccessor2) {
27395
- typeParameters = this.flowParseTypeParameterDeclaration();
27396
-
27397
- if (!this.match(10))
27398
- this.unexpected();
27399
- }
27400
-
27401
- const result = super.parseObjPropValue(prop, startLoc, isGenerator, isAsync, isPattern3, isAccessor2, refExpressionErrors);
27402
-
27403
- if (typeParameters) {
27404
- (result.value || result).typeParameters = typeParameters;
27405
- }
27406
-
27407
- return result;
27408
- }
27409
-
27410
- parseFunctionParamType(param) {
27411
- if (this.eat(17)) {
27412
- if (param.type !== 'Identifier') {
27413
- this.raise(FlowErrors.PatternIsOptional, param);
27414
- }
27415
-
27416
- if (this.isThisParam(param)) {
27417
- this.raise(FlowErrors.ThisParamMayNotBeOptional, param);
27418
- }
27419
-
27420
- param.optional = true;
27421
- }
27422
-
27423
- if (this.match(14)) {
27424
- param.typeAnnotation = this.flowParseTypeAnnotation();
27425
- } else if (this.isThisParam(param)) {
27426
- this.raise(FlowErrors.ThisParamAnnotationRequired, param);
27427
- }
27428
-
27429
- if (this.match(29) && this.isThisParam(param)) {
27430
- this.raise(FlowErrors.ThisParamNoDefault, param);
27431
- }
27432
-
27433
- this.resetEndLocation(param);
27434
- return param;
27435
- }
27436
-
27437
- parseMaybeDefault(startLoc, left) {
27438
- const node = super.parseMaybeDefault(startLoc, left);
27439
-
27440
- if (node.type === 'AssignmentPattern' && node.typeAnnotation && node.right.start < node.typeAnnotation.start) {
27441
- this.raise(FlowErrors.TypeBeforeInitializer, node.typeAnnotation);
27442
- }
27443
-
27444
- return node;
27445
- }
27446
-
27447
- checkImportReflection(node) {
27448
- super.checkImportReflection(node);
27449
-
27450
- if (node.module && node.importKind !== 'value') {
27451
- this.raise(FlowErrors.ImportReflectionHasImportType, node.specifiers[0].loc.start);
27452
- }
27453
- }
27454
-
27455
- parseImportSpecifierLocal(node, specifier, type) {
27456
- specifier.local = hasTypeImportKind(node) ? this.flowParseRestrictedIdentifier(true, true) : this.parseIdentifier();
27457
- node.specifiers.push(this.finishImportSpecifier(specifier, type));
27458
- }
27459
-
27460
- isPotentialImportPhase(isExport) {
27461
- if (super.isPotentialImportPhase(isExport))
27462
- return true;
27463
-
27464
- if (this.isContextual(130)) {
27465
- if (!isExport)
27466
- return true;
27467
-
27468
- const ch = this.lookaheadCharCode();
27469
-
27470
- return ch === 123 || ch === 42;
27471
- }
27472
-
27473
- return !isExport && this.isContextual(87);
27474
- }
27475
-
27476
- applyImportPhase(node, isExport, phase, loc) {
27477
- super.applyImportPhase(node, isExport, phase, loc);
27478
-
27479
- if (isExport) {
27480
- if (!phase && this.match(65)) {
27481
- return;
27482
- }
27483
-
27484
- node.exportKind = phase === 'type' ? phase : 'value';
27485
- } else {
27486
- if (phase === 'type' && this.match(55))
27487
- this.unexpected();
27488
-
27489
- node.importKind = phase === 'type' || phase === 'typeof' ? phase : 'value';
27490
- }
27491
- }
27492
-
27493
- parseImportSpecifier(specifier, importedIsString, isInTypeOnlyImport, isMaybeTypeOnly, bindingType) {
27494
- const firstIdent = specifier.imported;
27495
- let specifierTypeKind = null;
27496
-
27497
- if (firstIdent.type === 'Identifier') {
27498
- if (firstIdent.name === 'type') {
27499
- specifierTypeKind = 'type';
27500
- } else if (firstIdent.name === 'typeof') {
27501
- specifierTypeKind = 'typeof';
27502
- }
27503
- }
27504
-
27505
- let isBinding3 = false;
27506
-
27507
- if (this.isContextual(93) && !this.isLookaheadContextual('as')) {
27508
- const as_ident = this.parseIdentifier(true);
27509
-
27510
- if (specifierTypeKind !== null && !tokenIsKeywordOrIdentifier(this.state.type)) {
27511
- specifier.imported = as_ident;
27512
- specifier.importKind = specifierTypeKind;
27513
- specifier.local = this.cloneIdentifier(as_ident);
27514
- } else {
27515
- specifier.imported = firstIdent;
27516
- specifier.importKind = null;
27517
- specifier.local = this.parseIdentifier();
27518
- }
27519
- } else {
27520
- if (specifierTypeKind !== null && tokenIsKeywordOrIdentifier(this.state.type)) {
27521
- specifier.imported = this.parseIdentifier(true);
27522
- specifier.importKind = specifierTypeKind;
27523
- } else {
27524
- if (importedIsString) {
27525
- throw this.raise(Errors.ImportBindingIsString, specifier, {
27526
- importName: firstIdent.value,
27527
- });
27528
- }
27529
-
27530
- specifier.imported = firstIdent;
27531
- specifier.importKind = null;
27532
- }
27533
-
27534
- if (this.eatContextual(93)) {
27535
- specifier.local = this.parseIdentifier();
27536
- } else {
27537
- isBinding3 = true;
27538
- specifier.local = this.cloneIdentifier(specifier.imported);
27539
- }
27540
- }
27541
-
27542
- const specifierIsTypeImport = hasTypeImportKind(specifier);
27543
-
27544
- if (isInTypeOnlyImport && specifierIsTypeImport) {
27545
- this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport, specifier);
27546
- }
27547
-
27548
- if (isInTypeOnlyImport || specifierIsTypeImport) {
27549
- this.checkReservedType(specifier.local.name, specifier.local.loc.start, true);
27550
- }
27551
-
27552
- if (isBinding3 && !isInTypeOnlyImport && !specifierIsTypeImport) {
27553
- this.checkReservedWord(specifier.local.name, specifier.loc.start, true, true);
27554
- }
27555
-
27556
- return this.finishImportSpecifier(specifier, 'ImportSpecifier');
27557
- }
27558
-
27559
- parseBindingAtom() {
27560
- switch(this.state.type) {
27561
- case 78:
27562
- return this.parseIdentifier(true);
27563
-
27564
- default:
27565
- return super.parseBindingAtom();
27566
- }
27567
- }
27568
-
27569
- parseFunctionParams(node, isConstructor) {
27570
- const kind = node.kind;
27571
-
27572
- if (kind !== 'get' && kind !== 'set' && this.match(47)) {
27573
- node.typeParameters = this.flowParseTypeParameterDeclaration();
27574
- }
27575
-
27576
- super.parseFunctionParams(node, isConstructor);
27577
- }
27578
-
27579
- parseVarId(decl, kind) {
27580
- super.parseVarId(decl, kind);
27581
-
27582
- if (this.match(14)) {
27583
- decl.id.typeAnnotation = this.flowParseTypeAnnotation();
27584
- this.resetEndLocation(decl.id);
27585
- }
27586
- }
27587
-
27588
- parseAsyncArrowFromCallExpression(node, call2) {
27589
- if (this.match(14)) {
27590
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
27591
-
27592
- this.state.noAnonFunctionType = true;
27593
- node.returnType = this.flowParseTypeAnnotation();
27594
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
27595
- }
27596
-
27597
- return super.parseAsyncArrowFromCallExpression(node, call2);
27598
- }
27599
-
27600
- shouldParseAsyncArrow() {
27601
- return this.match(14) || super.shouldParseAsyncArrow();
27602
- }
27603
-
27604
- parseMaybeAssign(refExpressionErrors, afterLeftParse) {
27605
- let state = null;
27606
- let jsx2;
27607
-
27608
- if (this.hasPlugin('jsx') && (this.match(143) || this.match(47))) {
27609
- state = this.state.clone();
27610
- jsx2 = this.tryParse(() => super.parseMaybeAssign(refExpressionErrors, afterLeftParse), state);
27611
-
27612
- if (!jsx2.error)
27613
- return jsx2.node;
27614
-
27615
- const {context} = this.state;
27616
-
27617
- const currentContext = context[context.length - 1];
27618
-
27619
- if (currentContext === types$17.j_oTag || currentContext === types$17.j_expr) {
27620
- context.pop();
27621
- }
27622
- }
27623
-
27624
- if (jsx2?.error || this.match(47)) {
27625
- state = state || this.state.clone();
27626
- let typeParameters;
27627
- const arrow = this.tryParse((abort) => {
27628
- typeParameters = this.flowParseTypeParameterDeclaration();
27629
- const arrowExpression2 = this.forwardNoArrowParamsConversionAt(typeParameters, () => {
27630
- const result = super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
27631
- this.resetStartLocationFromNode(result, typeParameters);
27632
- return result;
27633
- });
27634
-
27635
- if (arrowExpression2.extra?.parenthesized)
27636
- abort();
27637
-
27638
- const expr = this.maybeUnwrapTypeCastExpression(arrowExpression2);
27639
-
27640
- if (expr.type !== 'ArrowFunctionExpression')
27641
- abort();
27642
-
27643
- expr.typeParameters = typeParameters;
27644
- this.resetStartLocationFromNode(expr, typeParameters);
27645
- return arrowExpression2;
27646
- }, state);
27647
-
27648
- let arrowExpression = null;
27649
-
27650
- if (arrow.node && this.maybeUnwrapTypeCastExpression(arrow.node).type === 'ArrowFunctionExpression') {
27651
- if (!arrow.error && !arrow.aborted) {
27652
- if (arrow.node.async) {
27653
- this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction, typeParameters);
27654
- }
27655
-
27656
- return arrow.node;
27657
- }
27658
-
27659
- arrowExpression = arrow.node;
27660
- }
27661
-
27662
- if (jsx2?.node) {
27663
- this.state = jsx2.failState;
27664
- return jsx2.node;
27665
- }
27666
-
27667
- if (arrowExpression) {
27668
- this.state = arrow.failState;
27669
- return arrowExpression;
27670
- }
27671
-
27672
- if (jsx2?.thrown)
27673
- throw jsx2.error;
27674
-
27675
- if (arrow.thrown)
27676
- throw arrow.error;
27677
-
27678
- throw this.raise(FlowErrors.UnexpectedTokenAfterTypeParameter, typeParameters);
27679
- }
27680
-
27681
- return super.parseMaybeAssign(refExpressionErrors, afterLeftParse);
27682
- }
27683
-
27684
- parseArrow(node) {
27685
- if (this.match(14)) {
27686
- const result = this.tryParse(() => {
27687
- const oldNoAnonFunctionType = this.state.noAnonFunctionType;
27688
-
27689
- this.state.noAnonFunctionType = true;
27690
- const typeNode = this.startNode();
27691
-
27692
- [typeNode.typeAnnotation, node.predicate] = this.flowParseTypeAndPredicateInitialiser();
27693
- this.state.noAnonFunctionType = oldNoAnonFunctionType;
27694
-
27695
- if (this.canInsertSemicolon())
27696
- this.unexpected();
27697
-
27698
- if (!this.match(19))
27699
- this.unexpected();
27700
-
27701
- return typeNode;
27702
- });
27703
-
27704
- if (result.thrown)
27705
- return null;
27706
-
27707
- if (result.error)
27708
- this.state = result.failState;
27709
-
27710
- node.returnType = result.node.typeAnnotation ? this.finishNode(result.node, 'TypeAnnotation') : null;
27711
- }
27712
-
27713
- return super.parseArrow(node);
27714
- }
27715
-
27716
- shouldParseArrow(params) {
27717
- return this.match(14) || super.shouldParseArrow(params);
27718
- }
27719
-
27720
- setArrowFunctionParameters(node, params) {
27721
- if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
27722
- node.params = params;
27723
- } else {
27724
- super.setArrowFunctionParameters(node, params);
27725
- }
27726
- }
27727
-
27728
- checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged = true) {
27729
- if (isArrowFunction && this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
27730
- return;
27731
- }
27732
-
27733
- for (let i = 0; i < node.params.length; i++) {
27734
- if (this.isThisParam(node.params[i]) && i > 0) {
27735
- this.raise(FlowErrors.ThisParamMustBeFirst, node.params[i]);
27736
- }
27737
- }
27738
-
27739
- super.checkParams(node, allowDuplicates, isArrowFunction, strictModeChanged);
27740
- }
27741
-
27742
- parseParenAndDistinguishExpression(canBeArrow) {
27743
- return super.parseParenAndDistinguishExpression(canBeArrow && !this.state.noArrowAt.includes(this.sourceToOffsetPos(this.state.start)));
27744
- }
27745
-
27746
- parseSubscripts(base, startLoc, noCalls) {
27747
- if (base.type === 'Identifier' && base.name === 'async' && this.state.noArrowAt.includes(startLoc.index)) {
27748
- this.next();
27749
- const node = this.startNodeAt(startLoc);
27750
-
27751
- node.callee = base;
27752
- node.arguments = super.parseCallExpressionArguments();
27753
- base = this.finishNode(node, 'CallExpression');
27754
- } else if (base.type === 'Identifier' && base.name === 'async' && this.match(47)) {
27755
- const state = this.state.clone();
27756
- const arrow = this.tryParse((abort) => this.parseAsyncArrowWithTypeParameters(startLoc) || abort(), state);
27757
-
27758
- if (!arrow.error && !arrow.aborted)
27759
- return arrow.node;
27760
-
27761
- const result = this.tryParse(() => super.parseSubscripts(base, startLoc, noCalls), state);
27762
-
27763
- if (result.node && !result.error)
27764
- return result.node;
27765
-
27766
- if (arrow.node) {
27767
- this.state = arrow.failState;
27768
- return arrow.node;
27769
- }
27770
-
27771
- if (result.node) {
27772
- this.state = result.failState;
27773
- return result.node;
27774
- }
27775
-
27776
- throw arrow.error || result.error;
27777
- }
27778
-
27779
- return super.parseSubscripts(base, startLoc, noCalls);
27780
- }
27781
-
27782
- parseSubscript(base, startLoc, noCalls, subscriptState) {
27783
- if (this.match(18) && this.isLookaheadToken_lt()) {
27784
- subscriptState.optionalChainMember = true;
27785
-
27786
- if (noCalls) {
27787
- subscriptState.stop = true;
27788
- return base;
27789
- }
27790
-
27791
- this.next();
27792
- const node = this.startNodeAt(startLoc);
27793
-
27794
- node.callee = base;
27795
- node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
27796
- this.expect(10);
27797
- node.arguments = this.parseCallExpressionArguments();
27798
- node.optional = true;
27799
- return this.finishCallExpression(node, true);
27800
- } else if (!noCalls && this.shouldParseTypes() && (this.match(47) || this.match(51))) {
27801
- const node = this.startNodeAt(startLoc);
27802
-
27803
- node.callee = base;
27804
- const result = this.tryParse(() => {
27805
- node.typeArguments = this.flowParseTypeParameterInstantiationCallOrNew();
27806
- this.expect(10);
27807
- node.arguments = super.parseCallExpressionArguments();
27808
-
27809
- if (subscriptState.optionalChainMember) {
27810
- node.optional = false;
27811
- }
27812
-
27813
- return this.finishCallExpression(node, subscriptState.optionalChainMember);
27814
- });
27815
-
27816
- if (result.node) {
27817
- if (result.error)
27818
- this.state = result.failState;
27819
-
27820
- return result.node;
27821
- }
27822
- }
27823
-
27824
- return super.parseSubscript(base, startLoc, noCalls, subscriptState);
27825
- }
27826
-
27827
- parseNewCallee(node) {
27828
- super.parseNewCallee(node);
27829
- let targs = null;
27830
-
27831
- if (this.shouldParseTypes() && this.match(47)) {
27832
- targs = this.tryParse(() => this.flowParseTypeParameterInstantiationCallOrNew()).node;
27833
- }
27834
-
27835
- node.typeArguments = targs;
24961
+
24962
+ get allowSuper() {
24963
+ return (this.currentThisScopeFlags() & 16) > 0;
27836
24964
  }
27837
24965
 
27838
- parseAsyncArrowWithTypeParameters(startLoc) {
27839
- const node = this.startNodeAt(startLoc);
27840
- this.parseFunctionParams(node, false);
27841
-
27842
- if (!this.parseArrow(node))
27843
- return;
27844
-
27845
- return super.parseArrowExpression(node, void 0, true);
24966
+ get allowDirectSuper() {
24967
+ return (this.currentThisScopeFlags() & 32) > 0;
27846
24968
  }
27847
24969
 
27848
- readToken_mult_modulo(code2) {
27849
- const next = this.input.charCodeAt(this.state.pos + 1);
27850
-
27851
- if (code2 === 42 && next === 47 && this.state.hasFlowComment) {
27852
- this.state.hasFlowComment = false;
27853
- this.state.pos += 2;
27854
- this.nextToken();
27855
- return;
27856
- }
27857
-
27858
- super.readToken_mult_modulo(code2);
24970
+ get allowNewTarget() {
24971
+ return (this.currentThisScopeFlags() & 512) > 0;
27859
24972
  }
27860
24973
 
27861
- readToken_pipe_amp(code2) {
27862
- const next = this.input.charCodeAt(this.state.pos + 1);
27863
-
27864
- if (code2 === 124 && next === 125) {
27865
- this.finishOp(9, 2);
27866
- return;
27867
- }
27868
-
27869
- super.readToken_pipe_amp(code2);
24974
+ get inClass() {
24975
+ return (this.currentThisScopeFlags() & 64) > 0;
27870
24976
  }
27871
24977
 
27872
- parseTopLevel(file2, program3) {
27873
- const fileNode = super.parseTopLevel(file2, program3);
27874
-
27875
- if (this.state.hasFlowComment) {
27876
- this.raise(FlowErrors.UnterminatedFlowComment, this.state.curPosition());
27877
- }
27878
-
27879
- return fileNode;
24978
+ get inClassAndNotInNonArrowFunction() {
24979
+ const flags = this.currentThisScopeFlags();
24980
+ return (flags & 64) > 0 && (flags & 2) === 0;
27880
24981
  }
27881
24982
 
27882
- skipBlockComment() {
27883
- if (this.hasPlugin('flowComments') && this.skipFlowComment()) {
27884
- if (this.state.hasFlowComment) {
27885
- throw this.raise(FlowErrors.NestedFlowComment, this.state.startLoc);
27886
- }
27887
-
27888
- this.hasFlowCommentCompletion();
27889
- const commentSkip = this.skipFlowComment();
24983
+ get inStaticBlock() {
24984
+ for (let i = this.scopeStack.length - 1;; i--) {
24985
+ const {flags} = this.scopeStack[i];
27890
24986
 
27891
- if (commentSkip) {
27892
- this.state.pos += commentSkip;
27893
- this.state.hasFlowComment = true;
24987
+ if (flags & 128) {
24988
+ return true;
27894
24989
  }
27895
24990
 
27896
- return;
27897
- }
27898
-
27899
- return super.skipBlockComment(this.state.hasFlowComment ? '*-/' : '*/');
27900
- }
27901
-
27902
- skipFlowComment() {
27903
- const {pos} = this.state;
27904
-
27905
- let shiftToFirstNonWhiteSpace = 2;
27906
-
27907
- while ([32, 9].includes(this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace))) {
27908
- shiftToFirstNonWhiteSpace++;
27909
- }
27910
-
27911
- const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
27912
- const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
27913
-
27914
- if (ch2 === 58 && ch3 === 58) {
27915
- return shiftToFirstNonWhiteSpace + 2;
27916
- }
27917
-
27918
- if (this.input.slice(shiftToFirstNonWhiteSpace + pos, shiftToFirstNonWhiteSpace + pos + 12) === 'flow-include') {
27919
- return shiftToFirstNonWhiteSpace + 12;
27920
- }
27921
-
27922
- if (ch2 === 58 && ch3 !== 58) {
27923
- return shiftToFirstNonWhiteSpace;
27924
- }
27925
-
27926
- return false;
27927
- }
27928
-
27929
- hasFlowCommentCompletion() {
27930
- const end = this.input.indexOf('*/', this.state.pos);
27931
-
27932
- if (end === -1) {
27933
- throw this.raise(Errors.UnterminatedComment, this.state.curPosition());
24991
+ if (flags & (1667 | 64)) {
24992
+ return false;
24993
+ }
27934
24994
  }
27935
24995
  }
27936
24996
 
27937
- flowEnumErrorBooleanMemberNotInitialized(loc, {enumName, memberName}) {
27938
- this.raise(FlowErrors.EnumBooleanMemberNotInitialized, loc, {
27939
- memberName,
27940
- enumName,
27941
- });
24997
+ get inNonArrowFunction() {
24998
+ return (this.currentThisScopeFlags() & 2) > 0;
27942
24999
  }
27943
25000
 
27944
- flowEnumErrorInvalidMemberInitializer(loc, enumContext) {
27945
- return this.raise(!enumContext.explicitType ? FlowErrors.EnumInvalidMemberInitializerUnknownType : enumContext.explicitType === 'symbol' ? FlowErrors.EnumInvalidMemberInitializerSymbolType : FlowErrors.EnumInvalidMemberInitializerPrimaryType, loc, enumContext);
25001
+ get inBareCaseStatement() {
25002
+ return (this.currentScope().flags & 256) > 0;
27946
25003
  }
27947
25004
 
27948
- flowEnumErrorNumberMemberNotInitialized(loc, details) {
27949
- this.raise(FlowErrors.EnumNumberMemberNotInitialized, loc, details);
25005
+ get treatFunctionsAsVar() {
25006
+ return this.treatFunctionsAsVarInScope(this.currentScope());
27950
25007
  }
27951
25008
 
27952
- flowEnumErrorStringMemberInconsistentlyInitialized(node, details) {
27953
- this.raise(FlowErrors.EnumStringMemberInconsistentlyInitialized, node, details);
25009
+ createScope(flags) {
25010
+ return new Scope(flags);
27954
25011
  }
27955
25012
 
27956
- flowEnumMemberInit() {
27957
- const startLoc = this.state.startLoc;
27958
- const endOfInit = () => this.match(12) || this.match(8);
27959
-
27960
- switch(this.state.type) {
27961
- case 135: {
27962
- const literal = this.parseNumericLiteral(this.state.value);
27963
-
27964
- if (endOfInit()) {
27965
- return {
27966
- type: 'number',
27967
- loc: literal.loc.start,
27968
- value: literal,
27969
- };
27970
- }
27971
-
27972
- return {
27973
- type: 'invalid',
27974
- loc: startLoc,
27975
- };
27976
- }
27977
-
27978
- case 134: {
27979
- const literal = this.parseStringLiteral(this.state.value);
27980
-
27981
- if (endOfInit()) {
27982
- return {
27983
- type: 'string',
27984
- loc: literal.loc.start,
27985
- value: literal,
27986
- };
27987
- }
27988
-
27989
- return {
27990
- type: 'invalid',
27991
- loc: startLoc,
27992
- };
27993
- }
27994
-
27995
- case 85:
27996
- case 86: {
27997
- const literal = this.parseBooleanLiteral(this.match(85));
27998
-
27999
- if (endOfInit()) {
28000
- return {
28001
- type: 'boolean',
28002
- loc: literal.loc.start,
28003
- value: literal,
28004
- };
28005
- }
28006
-
28007
- return {
28008
- type: 'invalid',
28009
- loc: startLoc,
28010
- };
28011
- }
28012
-
28013
- default:
28014
- return {
28015
- type: 'invalid',
28016
- loc: startLoc,
28017
- };
28018
- }
25013
+ enter(flags) {
25014
+ this.scopeStack.push(this.createScope(flags));
28019
25015
  }
28020
25016
 
28021
- flowEnumMemberRaw() {
28022
- const loc = this.state.startLoc;
28023
- const id = this.parseIdentifier(true);
28024
- const init = this.eat(29) ? this.flowEnumMemberInit() : {
28025
- type: 'none',
28026
- loc,
28027
- };
28028
-
28029
- return {
28030
- id,
28031
- init,
28032
- };
25017
+ exit() {
25018
+ const scope2 = this.scopeStack.pop();
25019
+ return scope2.flags;
28033
25020
  }
28034
25021
 
28035
- flowEnumCheckExplicitTypeMismatch(loc, context, expectedType) {
28036
- const {explicitType} = context;
28037
-
28038
- if (explicitType === null) {
28039
- return;
28040
- }
28041
-
28042
- if (explicitType !== expectedType) {
28043
- this.flowEnumErrorInvalidMemberInitializer(loc, context);
28044
- }
25022
+ treatFunctionsAsVarInScope(scope2) {
25023
+ return !!(scope2.flags & (2 | 128) || !this.parser.inModule && scope2.flags & 1);
28045
25024
  }
28046
25025
 
28047
- flowEnumMembers({enumName, explicitType}) {
28048
- const seenNames = /* @__PURE__ */new Set();
28049
- const members = {
28050
- booleanMembers: [],
28051
- numberMembers: [],
28052
- stringMembers: [],
28053
- defaultedMembers: [],
28054
- };
28055
-
28056
- let hasUnknownMembers = false;
25026
+ declareName(name, bindingType, loc) {
25027
+ let scope2 = this.currentScope();
28057
25028
 
28058
- while (!this.match(8)) {
28059
- if (this.eat(21)) {
28060
- hasUnknownMembers = true;
28061
- break;
28062
- }
28063
-
28064
- const memberNode = this.startNode();
28065
- const {id, init} = this.flowEnumMemberRaw();
28066
-
28067
- const memberName = id.name;
28068
-
28069
- if (memberName === '') {
28070
- continue;
28071
- }
28072
-
28073
- if (/^[a-z]/.test(memberName)) {
28074
- this.raise(FlowErrors.EnumInvalidMemberName, id, {
28075
- memberName,
28076
- suggestion: memberName[0].toUpperCase() + memberName.slice(1),
28077
- enumName,
28078
- });
28079
- }
28080
-
28081
- if (seenNames.has(memberName)) {
28082
- this.raise(FlowErrors.EnumDuplicateMemberName, id, {
28083
- memberName,
28084
- enumName,
28085
- });
28086
- }
28087
-
28088
- seenNames.add(memberName);
28089
- const context = {
28090
- enumName,
28091
- explicitType,
28092
- memberName,
28093
- };
28094
-
28095
- memberNode.id = id;
28096
- switch(init.type) {
28097
- case 'boolean': {
28098
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'boolean');
28099
- memberNode.init = init.value;
28100
- members.booleanMembers.push(this.finishNode(memberNode, 'EnumBooleanMember'));
28101
- break;
28102
- }
25029
+ if (bindingType & 8 || bindingType & 16) {
25030
+ this.checkRedeclarationInScope(scope2, name, bindingType, loc);
25031
+ let type = scope2.names.get(name) || 0;
28103
25032
 
28104
- case 'number': {
28105
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'number');
28106
- memberNode.init = init.value;
28107
- members.numberMembers.push(this.finishNode(memberNode, 'EnumNumberMember'));
28108
- break;
25033
+ if (bindingType & 16) {
25034
+ type = type | 4;
25035
+ } else {
25036
+ if (!scope2.firstLexicalName) {
25037
+ scope2.firstLexicalName = name;
25038
+ }
25039
+
25040
+ type = type | 2;
28109
25041
  }
28110
25042
 
28111
- case 'string': {
28112
- this.flowEnumCheckExplicitTypeMismatch(init.loc, context, 'string');
28113
- memberNode.init = init.value;
28114
- members.stringMembers.push(this.finishNode(memberNode, 'EnumStringMember'));
28115
- break;
28116
- }
25043
+ scope2.names.set(name, type);
28117
25044
 
28118
- case 'invalid': {
28119
- throw this.flowEnumErrorInvalidMemberInitializer(init.loc, context);
25045
+ if (bindingType & 8) {
25046
+ this.maybeExportDefined(scope2, name);
28120
25047
  }
28121
-
28122
- case 'none': {
28123
- switch(explicitType) {
28124
- case 'boolean':
28125
- this.flowEnumErrorBooleanMemberNotInitialized(init.loc, context);
28126
- break;
25048
+ } else if (bindingType & 4) {
25049
+ for (let i = this.scopeStack.length - 1; i >= 0; --i) {
25050
+ scope2 = this.scopeStack[i];
25051
+ this.checkRedeclarationInScope(scope2, name, bindingType, loc);
25052
+ scope2.names.set(name, (scope2.names.get(name) || 0) | 1);
25053
+ this.maybeExportDefined(scope2, name);
28127
25054
 
28128
- case 'number':
28129
- this.flowEnumErrorNumberMemberNotInitialized(init.loc, context);
25055
+ if (scope2.flags & 1667)
28130
25056
  break;
28131
-
28132
- default:
28133
- members.defaultedMembers.push(this.finishNode(memberNode, 'EnumDefaultedMember'));
28134
- }
28135
- }
28136
- }
28137
-
28138
- if (!this.match(8)) {
28139
- this.expect(12);
28140
25057
  }
28141
25058
  }
28142
25059
 
28143
- return {
28144
- members,
28145
- hasUnknownMembers,
28146
- };
25060
+ if (this.parser.inModule && scope2.flags & 1) {
25061
+ this.undefinedExports.delete(name);
25062
+ }
28147
25063
  }
28148
25064
 
28149
- flowEnumStringMembers(initializedMembers, defaultedMembers, {enumName}) {
28150
- if (initializedMembers.length === 0) {
28151
- return defaultedMembers;
28152
- } else if (defaultedMembers.length === 0) {
28153
- return initializedMembers;
28154
- } else if (defaultedMembers.length > initializedMembers.length) {
28155
- for (const member of initializedMembers) {
28156
- this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
28157
- enumName,
28158
- });
28159
- }
28160
-
28161
- return defaultedMembers;
28162
- } else {
28163
- for (const member of defaultedMembers) {
28164
- this.flowEnumErrorStringMemberInconsistentlyInitialized(member, {
28165
- enumName,
28166
- });
28167
- }
28168
-
28169
- return initializedMembers;
25065
+ maybeExportDefined(scope2, name) {
25066
+ if (this.parser.inModule && scope2.flags & 1) {
25067
+ this.undefinedExports.delete(name);
28170
25068
  }
28171
-
28172
25069
  }
28173
25070
 
28174
- flowEnumParseExplicitType({enumName}) {
28175
- if (!this.eatContextual(102))
28176
- return null;
28177
-
28178
- if (!tokenIsIdentifier(this.state.type)) {
28179
- throw this.raise(FlowErrors.EnumInvalidExplicitTypeUnknownSupplied, this.state.startLoc, {
28180
- enumName,
28181
- });
28182
- }
28183
-
28184
- const {value} = this.state;
28185
-
28186
- this.next();
28187
-
28188
- if (value !== 'boolean' && value !== 'number' && value !== 'string' && value !== 'symbol') {
28189
- this.raise(FlowErrors.EnumInvalidExplicitType, this.state.startLoc, {
28190
- enumName,
28191
- invalidEnumType: value,
25071
+ checkRedeclarationInScope(scope2, name, bindingType, loc) {
25072
+ if (this.isRedeclaredInScope(scope2, name, bindingType)) {
25073
+ this.parser.raise(Errors.VarRedeclaration, loc, {
25074
+ identifierName: name,
28192
25075
  });
28193
25076
  }
28194
-
28195
- return value;
28196
25077
  }
28197
25078
 
28198
- flowEnumBody(node, id) {
28199
- const enumName = id.name;
28200
- const nameLoc = id.loc.start;
28201
- const explicitType = this.flowEnumParseExplicitType({
28202
- enumName,
28203
- });
28204
-
28205
- this.expect(5);
28206
- const {
28207
- members,
28208
- hasUnknownMembers,
28209
- } = this.flowEnumMembers({
28210
- enumName,
28211
- explicitType,
28212
- });
28213
-
28214
- node.hasUnknownMembers = hasUnknownMembers;
28215
- switch(explicitType) {
28216
- case 'boolean':
28217
- node.explicitType = true;
28218
- node.members = members.booleanMembers;
28219
- this.expect(8);
28220
- return this.finishNode(node, 'EnumBooleanBody');
28221
-
28222
- case 'number':
28223
- node.explicitType = true;
28224
- node.members = members.numberMembers;
28225
- this.expect(8);
28226
- return this.finishNode(node, 'EnumNumberBody');
25079
+ isRedeclaredInScope(scope2, name, bindingType) {
25080
+ if (!(bindingType & 1))
25081
+ return false;
28227
25082
 
28228
- case 'string':
28229
- node.explicitType = true;
28230
- node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
28231
- enumName,
28232
- });
28233
- this.expect(8);
28234
- return this.finishNode(node, 'EnumStringBody');
25083
+ if (bindingType & 8) {
25084
+ return scope2.names.has(name);
25085
+ }
28235
25086
 
28236
- case 'symbol':
28237
- node.members = members.defaultedMembers;
28238
- this.expect(8);
28239
- return this.finishNode(node, 'EnumSymbolBody');
25087
+ const type = scope2.names.get(name);
28240
25088
 
28241
- default: {
28242
- const empty = () => {
28243
- node.members = [];
28244
- this.expect(8);
28245
- return this.finishNode(node, 'EnumStringBody');
28246
- };
28247
-
28248
- node.explicitType = false;
28249
- const boolsLen = members.booleanMembers.length;
28250
- const numsLen = members.numberMembers.length;
28251
- const strsLen = members.stringMembers.length;
28252
- const defaultedLen = members.defaultedMembers.length;
28253
-
28254
- if (!boolsLen && !numsLen && !strsLen && !defaultedLen) {
28255
- return empty();
28256
- } else if (!boolsLen && !numsLen) {
28257
- node.members = this.flowEnumStringMembers(members.stringMembers, members.defaultedMembers, {
28258
- enumName,
28259
- });
28260
- this.expect(8);
28261
- return this.finishNode(node, 'EnumStringBody');
28262
- } else if (!numsLen && !strsLen && boolsLen >= defaultedLen) {
28263
- for (const member of members.defaultedMembers) {
28264
- this.flowEnumErrorBooleanMemberNotInitialized(member.loc.start, {
28265
- enumName,
28266
- memberName: member.id.name,
28267
- });
28268
- }
28269
-
28270
- node.members = members.booleanMembers;
28271
- this.expect(8);
28272
-
28273
- return this.finishNode(node, 'EnumBooleanBody');
28274
- } else if (!boolsLen && !strsLen && numsLen >= defaultedLen) {
28275
- for (const member of members.defaultedMembers) {
28276
- this.flowEnumErrorNumberMemberNotInitialized(member.loc.start, {
28277
- enumName,
28278
- memberName: member.id.name,
28279
- });
28280
- }
28281
-
28282
- node.members = members.numberMembers;
28283
- this.expect(8);
28284
-
28285
- return this.finishNode(node, 'EnumNumberBody');
28286
- } else {
28287
- this.raise(FlowErrors.EnumInconsistentMemberValues, nameLoc, {
28288
- enumName,
28289
- });
28290
- return empty();
28291
- }
28292
-
28293
-
28294
- }
25089
+ if (bindingType & 16) {
25090
+ return (type & 2) > 0 || !this.treatFunctionsAsVarInScope(scope2) && (type & 1) > 0;
28295
25091
  }
28296
- }
28297
-
28298
- flowParseEnumDeclaration(node) {
28299
- const id = this.parseIdentifier();
28300
25092
 
28301
- node.id = id;
28302
- node.body = this.flowEnumBody(this.startNode(), id);
28303
- return this.finishNode(node, 'EnumDeclaration');
25093
+ return (type & 2) > 0 && !(scope2.flags & 8 && scope2.firstLexicalName === name)
25094
+ || !this.treatFunctionsAsVarInScope(scope2) && (type & 4) > 0;
28304
25095
  }
28305
25096
 
28306
- jsxParseOpeningElementAfterName(node) {
28307
- if (this.shouldParseTypes()) {
28308
- if (this.match(47) || this.match(51)) {
28309
- node.typeArguments = this.flowParseTypeParameterInstantiationInExpression();
28310
- }
28311
- }
25097
+ checkLocalExport(id) {
25098
+ const {name} = id;
28312
25099
 
28313
- return super.jsxParseOpeningElementAfterName(node);
28314
- }
28315
-
28316
- isLookaheadToken_lt() {
28317
- const next = this.nextTokenStart();
25100
+ const topLevelScope = this.scopeStack[0];
28318
25101
 
28319
- if (this.input.charCodeAt(next) === 60) {
28320
- const afterNext = this.input.charCodeAt(next + 1);
28321
- return afterNext !== 60 && afterNext !== 61;
25102
+ if (!topLevelScope.names.has(name)) {
25103
+ this.undefinedExports.set(name, id.loc.start);
28322
25104
  }
28323
-
28324
- return false;
28325
25105
  }
28326
25106
 
28327
- reScan_lt_gt() {
28328
- const {type} = this.state;
28329
-
28330
- if (type === 47) {
28331
- this.state.pos -= 1;
28332
- this.readToken_lt();
28333
- } else if (type === 48) {
28334
- this.state.pos -= 1;
28335
- this.readToken_gt();
28336
- }
25107
+ currentScope() {
25108
+ return this.scopeStack[this.scopeStack.length - 1];
28337
25109
  }
28338
25110
 
28339
- reScan_lt() {
28340
- const {type} = this.state;
28341
-
28342
- if (type === 51) {
28343
- this.state.pos -= 2;
28344
- this.finishOp(47, 1);
28345
- return 47;
25111
+ currentVarScopeFlags() {
25112
+ for (let i = this.scopeStack.length - 1;; i--) {
25113
+ const {flags} = this.scopeStack[i];
25114
+
25115
+ if (flags & 1667) {
25116
+ return flags;
25117
+ }
28346
25118
  }
28347
-
28348
- return type;
28349
25119
  }
28350
25120
 
28351
- maybeUnwrapTypeCastExpression(node) {
28352
- return node.type === 'TypeCastExpression' ? node.expression : node;
25121
+ currentThisScopeFlags() {
25122
+ for (let i = this.scopeStack.length - 1;; i--) {
25123
+ const {flags} = this.scopeStack[i];
25124
+
25125
+ if (flags & (1667 | 64) && !(flags & 4)) {
25126
+ return flags;
25127
+ }
25128
+ }
28353
25129
  }
28354
25130
  };
28355
25131
 
@@ -36646,7 +33422,6 @@ function validatePlugins(pluginsMap) {
36646
33422
  var mixinPlugins = {
36647
33423
  estree,
36648
33424
  jsx: jsx$3,
36649
- flow,
36650
33425
  typescript: typescript$3,
36651
33426
  v8intrinsic,
36652
33427
  placeholders,
@@ -66216,356 +62991,11 @@ var esprima$2 = /*#__PURE__*/Object.freeze({
66216
62991
 
66217
62992
  var require$$1$1 = /*@__PURE__*/getAugmentedNamespace(esprima$2);
66218
62993
 
66219
- var acornPrivateClassElements;
66220
- var hasRequiredAcornPrivateClassElements;
66221
-
66222
- function requireAcornPrivateClassElements () {
66223
- if (hasRequiredAcornPrivateClassElements) return acornPrivateClassElements;
66224
- hasRequiredAcornPrivateClassElements = 1;
66225
-
66226
- const getPrototype = Object.getPrototypeOf || (o => o.__proto__);
66227
-
66228
- const getAcorn = Parser => {
66229
- if (Parser.acorn) return Parser.acorn
66230
-
66231
- const acorn = require$$1$1;
66232
-
66233
- if (acorn.version.indexOf("6.") != 0 && acorn.version.indexOf("6.0.") == 0 && acorn.version.indexOf("7.") != 0) {
66234
- throw new Error(`acorn-private-class-elements requires acorn@^6.1.0 or acorn@7.0.0, not ${acorn.version}`)
66235
- }
66236
-
66237
- // Make sure `Parser` comes from the same acorn as we `require`d,
66238
- // otherwise the comparisons fail.
66239
- for (let cur = Parser; cur && cur !== acorn.Parser; cur = getPrototype(cur)) {
66240
- if (cur !== acorn.Parser) {
66241
- throw new Error("acorn-private-class-elements does not support mixing different acorn copies")
66242
- }
66243
- }
66244
- return acorn
66245
- };
66246
-
66247
- acornPrivateClassElements = function(Parser) {
66248
- // Only load this plugin once.
66249
- if (Parser.prototype.parsePrivateName) {
66250
- return Parser
66251
- }
66252
-
66253
- const acorn = getAcorn(Parser);
66254
-
66255
- Parser = class extends Parser {
66256
- _branch() {
66257
- this.__branch = this.__branch || new Parser({ecmaVersion: this.options.ecmaVersion}, this.input);
66258
- this.__branch.end = this.end;
66259
- this.__branch.pos = this.pos;
66260
- this.__branch.type = this.type;
66261
- this.__branch.value = this.value;
66262
- this.__branch.containsEsc = this.containsEsc;
66263
- return this.__branch
66264
- }
66265
-
66266
- parsePrivateClassElementName(element) {
66267
- element.computed = false;
66268
- element.key = this.parsePrivateName();
66269
- if (element.key.name == "constructor") this.raise(element.key.start, "Classes may not have a private element named constructor");
66270
- const accept = {get: "set", set: "get"}[element.kind];
66271
- const privateBoundNames = this._privateBoundNames;
66272
- if (Object.prototype.hasOwnProperty.call(privateBoundNames, element.key.name) && privateBoundNames[element.key.name] !== accept) {
66273
- this.raise(element.start, "Duplicate private element");
66274
- }
66275
- privateBoundNames[element.key.name] = element.kind || true;
66276
- delete this._unresolvedPrivateNames[element.key.name];
66277
- return element.key
66278
- }
66279
-
66280
- parsePrivateName() {
66281
- const node = this.startNode();
66282
- node.name = this.value;
66283
- this.next();
66284
- this.finishNode(node, "PrivateName");
66285
- if (this.options.allowReserved == "never") this.checkUnreserved(node);
66286
- return node
66287
- }
66288
-
66289
- // Parse # token
66290
- getTokenFromCode(code) {
66291
- if (code === 35) {
66292
- ++this.pos;
66293
- const word = this.readWord1();
66294
- return this.finishToken(this.privateNameToken, word)
66295
- }
66296
- return super.getTokenFromCode(code)
66297
- }
66298
-
66299
- // Manage stacks and check for undeclared private names
66300
- parseClass(node, isStatement) {
66301
- const oldOuterPrivateBoundNames = this._outerPrivateBoundNames;
66302
- this._outerPrivateBoundNames = this._privateBoundNames;
66303
- this._privateBoundNames = Object.create(this._privateBoundNames || null);
66304
- const oldOuterUnresolvedPrivateNames = this._outerUnresolvedPrivateNames;
66305
- this._outerUnresolvedPrivateNames = this._unresolvedPrivateNames;
66306
- this._unresolvedPrivateNames = Object.create(null);
66307
-
66308
- const _return = super.parseClass(node, isStatement);
66309
-
66310
- const unresolvedPrivateNames = this._unresolvedPrivateNames;
66311
- this._privateBoundNames = this._outerPrivateBoundNames;
66312
- this._outerPrivateBoundNames = oldOuterPrivateBoundNames;
66313
- this._unresolvedPrivateNames = this._outerUnresolvedPrivateNames;
66314
- this._outerUnresolvedPrivateNames = oldOuterUnresolvedPrivateNames;
66315
- if (!this._unresolvedPrivateNames) {
66316
- const names = Object.keys(unresolvedPrivateNames);
66317
- if (names.length) {
66318
- names.sort((n1, n2) => unresolvedPrivateNames[n1] - unresolvedPrivateNames[n2]);
66319
- this.raise(unresolvedPrivateNames[names[0]], "Usage of undeclared private name");
66320
- }
66321
- } else Object.assign(this._unresolvedPrivateNames, unresolvedPrivateNames);
66322
- return _return
66323
- }
66324
-
66325
- // Class heritage is evaluated with outer private environment
66326
- parseClassSuper(node) {
66327
- const privateBoundNames = this._privateBoundNames;
66328
- this._privateBoundNames = this._outerPrivateBoundNames;
66329
- const unresolvedPrivateNames = this._unresolvedPrivateNames;
66330
- this._unresolvedPrivateNames = this._outerUnresolvedPrivateNames;
66331
- const _return = super.parseClassSuper(node);
66332
- this._privateBoundNames = privateBoundNames;
66333
- this._unresolvedPrivateNames = unresolvedPrivateNames;
66334
- return _return
66335
- }
66336
-
66337
- // Parse private element access
66338
- parseSubscript(base, startPos, startLoc, _noCalls, _maybeAsyncArrow, _optionalChained) {
66339
- const optionalSupported = this.options.ecmaVersion >= 11 && acorn.tokTypes.questionDot;
66340
- const branch = this._branch();
66341
- if (!(
66342
- (branch.eat(acorn.tokTypes.dot) || (optionalSupported && branch.eat(acorn.tokTypes.questionDot))) &&
66343
- branch.type == this.privateNameToken
66344
- )) {
66345
- return super.parseSubscript.apply(this, arguments)
66346
- }
66347
- let optional = false;
66348
- if (!this.eat(acorn.tokTypes.dot)) {
66349
- this.expect(acorn.tokTypes.questionDot);
66350
- optional = true;
66351
- }
66352
- let node = this.startNodeAt(startPos, startLoc);
66353
- node.object = base;
66354
- node.computed = false;
66355
- if (optionalSupported) {
66356
- node.optional = optional;
66357
- }
66358
- if (this.type == this.privateNameToken) {
66359
- if (base.type == "Super") {
66360
- this.raise(this.start, "Cannot access private element on super");
66361
- }
66362
- node.property = this.parsePrivateName();
66363
- if (!this._privateBoundNames || !this._privateBoundNames[node.property.name]) {
66364
- if (!this._unresolvedPrivateNames) {
66365
- this.raise(node.property.start, "Usage of undeclared private name");
66366
- }
66367
- this._unresolvedPrivateNames[node.property.name] = node.property.start;
66368
- }
66369
- } else {
66370
- node.property = this.parseIdent(true);
66371
- }
66372
- return this.finishNode(node, "MemberExpression")
66373
- }
66374
-
66375
- // Prohibit delete of private class elements
66376
- parseMaybeUnary(refDestructuringErrors, sawUnary) {
66377
- const _return = super.parseMaybeUnary(refDestructuringErrors, sawUnary);
66378
- if (_return.operator == "delete") {
66379
- if (_return.argument.type == "MemberExpression" && _return.argument.property.type == "PrivateName") {
66380
- this.raise(_return.start, "Private elements may not be deleted");
66381
- }
66382
- }
66383
- return _return
66384
- }
66385
- };
66386
- Parser.prototype.privateNameToken = new acorn.TokenType("privateName");
66387
- return Parser
66388
- };
66389
- return acornPrivateClassElements;
66390
- }
66391
-
66392
- var acornClassFields;
66393
- var hasRequiredAcornClassFields;
66394
-
66395
- function requireAcornClassFields () {
66396
- if (hasRequiredAcornClassFields) return acornClassFields;
66397
- hasRequiredAcornClassFields = 1;
66398
-
66399
- const privateClassElements = requireAcornPrivateClassElements();
66400
-
66401
- acornClassFields = function(Parser) {
66402
- const acorn = Parser.acorn || require$$1$1;
66403
- const tt = acorn.tokTypes;
66404
-
66405
- Parser = privateClassElements(Parser);
66406
- return class extends Parser {
66407
- _maybeParseFieldValue(field) {
66408
- if (this.eat(tt.eq)) {
66409
- const oldInFieldValue = this._inFieldValue;
66410
- this._inFieldValue = true;
66411
- if (this.type === tt.name && this.value === "await" && (this.inAsync || this.options.allowAwaitOutsideFunction)) {
66412
- field.value = this.parseAwait();
66413
- } else field.value = this.parseExpression();
66414
- this._inFieldValue = oldInFieldValue;
66415
- } else field.value = null;
66416
- }
66417
-
66418
- // Parse fields
66419
- parseClassElement(_constructorAllowsSuper) {
66420
- if (this.options.ecmaVersion >= 8 && (this.type == tt.name || this.type.keyword || this.type == this.privateNameToken || this.type == tt.bracketL || this.type == tt.string || this.type == tt.num)) {
66421
- const branch = this._branch();
66422
- if (branch.type == tt.bracketL) {
66423
- let count = 0;
66424
- do {
66425
- if (branch.eat(tt.bracketL)) ++count;
66426
- else if (branch.eat(tt.bracketR)) --count;
66427
- else branch.next();
66428
- } while (count > 0)
66429
- } else branch.next(true);
66430
- let isField = branch.type == tt.eq || branch.type == tt.semi;
66431
- if (!isField && branch.canInsertSemicolon()) {
66432
- isField = branch.type != tt.parenL;
66433
- }
66434
- if (isField) {
66435
- const node = this.startNode();
66436
- if (this.type == this.privateNameToken) {
66437
- this.parsePrivateClassElementName(node);
66438
- } else {
66439
- this.parsePropertyName(node);
66440
- }
66441
- if ((node.key.type === "Identifier" && node.key.name === "constructor") ||
66442
- (node.key.type === "Literal" && node.key.value === "constructor")) {
66443
- this.raise(node.key.start, "Classes may not have a field called constructor");
66444
- }
66445
- this.enterScope(64 | 2 | 1); // See acorn's scopeflags.js
66446
- this._maybeParseFieldValue(node);
66447
- this.exitScope();
66448
- this.finishNode(node, "FieldDefinition");
66449
- this.semicolon();
66450
- return node
66451
- }
66452
- }
66453
-
66454
- return super.parseClassElement.apply(this, arguments)
66455
- }
66456
-
66457
- // Prohibit arguments in class field initializers
66458
- parseIdent(liberal, isBinding) {
66459
- const ident = super.parseIdent(liberal, isBinding);
66460
- if (this._inFieldValue && ident.name == "arguments") this.raise(ident.start, "A class field initializer may not contain arguments");
66461
- return ident
66462
- }
66463
- }
66464
- };
66465
- return acornClassFields;
66466
- }
66467
-
66468
- var acornStaticClassFeatures;
66469
- var hasRequiredAcornStaticClassFeatures;
66470
-
66471
- function requireAcornStaticClassFeatures () {
66472
- if (hasRequiredAcornStaticClassFeatures) return acornStaticClassFeatures;
66473
- hasRequiredAcornStaticClassFeatures = 1;
66474
-
66475
- const privateClassElements = requireAcornPrivateClassElements();
66476
-
66477
- acornStaticClassFeatures = function(Parser) {
66478
- const ExtendedParser = privateClassElements(Parser);
66479
-
66480
- const acorn = Parser.acorn || require$$1$1;
66481
- const tt = acorn.tokTypes;
66482
-
66483
- return class extends ExtendedParser {
66484
- _maybeParseFieldValue(field) {
66485
- if (this.eat(tt.eq)) {
66486
- const oldInFieldValue = this._inStaticFieldScope;
66487
- this._inStaticFieldScope = this.currentThisScope();
66488
- field.value = this.parseExpression();
66489
- this._inStaticFieldScope = oldInFieldValue;
66490
- } else field.value = null;
66491
- }
66492
-
66493
- // Parse fields
66494
- parseClassElement(_constructorAllowsSuper) {
66495
- if (this.options.ecmaVersion < 8 || !this.isContextual("static")) {
66496
- return super.parseClassElement.apply(this, arguments)
66497
- }
66498
-
66499
- const branch = this._branch();
66500
- branch.next();
66501
- if ([tt.name, tt.bracketL, tt.string, tt.num, this.privateNameToken].indexOf(branch.type) == -1 && !branch.type.keyword) {
66502
- return super.parseClassElement.apply(this, arguments)
66503
- }
66504
- if (branch.type == tt.bracketL) {
66505
- let count = 0;
66506
- do {
66507
- if (branch.eat(tt.bracketL)) ++count;
66508
- else if (branch.eat(tt.bracketR)) --count;
66509
- else branch.next();
66510
- } while (count > 0)
66511
- } else branch.next();
66512
- if (branch.type != tt.eq && !branch.canInsertSemicolon() && branch.type != tt.semi) {
66513
- return super.parseClassElement.apply(this, arguments)
66514
- }
66515
-
66516
- const node = this.startNode();
66517
- node.static = this.eatContextual("static");
66518
- if (this.type == this.privateNameToken) {
66519
- this.parsePrivateClassElementName(node);
66520
- } else {
66521
- this.parsePropertyName(node);
66522
- }
66523
- if ((node.key.type === "Identifier" && node.key.name === "constructor") ||
66524
- (node.key.type === "Literal" && !node.computed && node.key.value === "constructor")) {
66525
- this.raise(node.key.start, "Classes may not have a field called constructor");
66526
- }
66527
- if ((node.key.name || node.key.value) === "prototype" && !node.computed) {
66528
- this.raise(node.key.start, "Classes may not have a static property named prototype");
66529
- }
66530
-
66531
- this.enterScope(64 | 2 | 1); // See acorn's scopeflags.js
66532
- this._maybeParseFieldValue(node);
66533
- this.exitScope();
66534
- this.finishNode(node, "FieldDefinition");
66535
- this.semicolon();
66536
- return node
66537
- }
66538
-
66539
- // Parse private static methods
66540
- parsePropertyName(prop) {
66541
- if (prop.static && this.type == this.privateNameToken) {
66542
- this.parsePrivateClassElementName(prop);
66543
- } else {
66544
- super.parsePropertyName(prop);
66545
- }
66546
- }
66547
-
66548
- // Prohibit arguments in class field initializers
66549
- parseIdent(liberal, isBinding) {
66550
- const ident = super.parseIdent(liberal, isBinding);
66551
- if (this._inStaticFieldScope && this.currentThisScope() === this._inStaticFieldScope && ident.name == "arguments") {
66552
- this.raise(ident.start, "A static class field initializer may not contain arguments");
66553
- }
66554
- return ident
66555
- }
66556
- }
66557
- };
66558
- return acornStaticClassFeatures;
66559
- }
66560
-
66561
- var acornPrivateClassElementsExports = requireAcornPrivateClassElements();
66562
- var privateClassElements = acornPrivateClassElementsExports.default;
66563
-
66564
62994
  // eslint-disable-next-line node/no-unsupported-features/es-syntax
66565
62995
 
66566
62996
  // eslint-disable-next-line node/no-unsupported-features/es-syntax
66567
62997
  function privateMethods(Parser) {
66568
- const ExtendedParser = privateClassElements(Parser);
62998
+ const ExtendedParser = noop$3();
66569
62999
 
66570
63000
  return class extends ExtendedParser {
66571
63001
  // Parse private methods
@@ -66602,8 +63032,8 @@ function requireAcornStage3 () {
66602
63032
 
66603
63033
  acornStage3 = function(Parser) {
66604
63034
  return Parser.extend(
66605
- requireAcornClassFields(),
66606
- requireAcornStaticClassFeatures(),
63035
+ require$$1$1,
63036
+ require$$1$1,
66607
63037
  require$$2
66608
63038
  )
66609
63039
  };
@@ -70689,7 +67119,7 @@ compare$5.compareAll = (path, templateNodes, options) => {
70689
67119
 
70690
67120
  // @babel/template creates empty array directives
70691
67121
  // extra duplicate value
70692
- const ignore$3 = [
67122
+ const ignore$2 = [
70693
67123
  'loc',
70694
67124
  'start',
70695
67125
  'end',
@@ -70722,7 +67152,7 @@ function superCompareIterate(node, template) {
70722
67152
  return false;
70723
67153
 
70724
67154
  for (const key of keys$2(template)) {
70725
- if (ignore$3.includes(key))
67155
+ if (ignore$2.includes(key))
70726
67156
  continue;
70727
67157
 
70728
67158
  const nodeValue = extractExpression(node[key]);
@@ -80934,788 +77364,8 @@ keyword.isTSKeyword = (name) => {
80934
77364
 
80935
77365
  var matchFiles = {};
80936
77366
 
80937
- var ignore$2 = {exports: {}};
80938
-
80939
- (function (module) {
80940
- // A simple implementation of make-array
80941
- function makeArray (subject) {
80942
- return Array.isArray(subject)
80943
- ? subject
80944
- : [subject]
80945
- }
80946
-
80947
- const UNDEFINED = undefined;
80948
- const EMPTY = '';
80949
- const SPACE = ' ';
80950
- const ESCAPE = '\\';
80951
- const REGEX_TEST_BLANK_LINE = /^\s+$/;
80952
- const REGEX_INVALID_TRAILING_BACKSLASH = /(?:[^\\]|^)\\$/;
80953
- const REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION = /^\\!/;
80954
- const REGEX_REPLACE_LEADING_EXCAPED_HASH = /^\\#/;
80955
- const REGEX_SPLITALL_CRLF = /\r?\n/g;
80956
-
80957
- // Invalid:
80958
- // - /foo,
80959
- // - ./foo,
80960
- // - ../foo,
80961
- // - .
80962
- // - ..
80963
- // Valid:
80964
- // - .foo
80965
- const REGEX_TEST_INVALID_PATH = /^\.{0,2}\/|^\.{1,2}$/;
80966
-
80967
- const REGEX_TEST_TRAILING_SLASH = /\/$/;
80968
-
80969
- const SLASH = '/';
80970
-
80971
- // Do not use ternary expression here, since "istanbul ignore next" is buggy
80972
- let TMP_KEY_IGNORE = 'node-ignore';
80973
- /* istanbul ignore else */
80974
- if (typeof Symbol !== 'undefined') {
80975
- TMP_KEY_IGNORE = Symbol.for('node-ignore');
80976
- }
80977
- const KEY_IGNORE = TMP_KEY_IGNORE;
80978
-
80979
- const define = (object, key, value) => {
80980
- Object.defineProperty(object, key, {value});
80981
- return value
80982
- };
80983
-
80984
- const REGEX_REGEXP_RANGE = /([0-z])-([0-z])/g;
80985
-
80986
- const RETURN_FALSE = () => false;
80987
-
80988
- // Sanitize the range of a regular expression
80989
- // The cases are complicated, see test cases for details
80990
- const sanitizeRange = range => range.replace(
80991
- REGEX_REGEXP_RANGE,
80992
- (match, from, to) => from.charCodeAt(0) <= to.charCodeAt(0)
80993
- ? match
80994
- // Invalid range (out of order) which is ok for gitignore rules but
80995
- // fatal for JavaScript regular expression, so eliminate it.
80996
- : EMPTY
80997
- );
80998
-
80999
- // See fixtures #59
81000
- const cleanRangeBackSlash = slashes => {
81001
- const {length} = slashes;
81002
- return slashes.slice(0, length - length % 2)
81003
- };
81004
-
81005
- // > If the pattern ends with a slash,
81006
- // > it is removed for the purpose of the following description,
81007
- // > but it would only find a match with a directory.
81008
- // > In other words, foo/ will match a directory foo and paths underneath it,
81009
- // > but will not match a regular file or a symbolic link foo
81010
- // > (this is consistent with the way how pathspec works in general in Git).
81011
- // '`foo/`' will not match regular file '`foo`' or symbolic link '`foo`'
81012
- // -> ignore-rules will not deal with it, because it costs extra `fs.stat` call
81013
- // you could use option `mark: true` with `glob`
81014
-
81015
- // '`foo/`' should not continue with the '`..`'
81016
- const REPLACERS = [
81017
-
81018
- [
81019
- // Remove BOM
81020
- // TODO:
81021
- // Other similar zero-width characters?
81022
- /^\uFEFF/,
81023
- () => EMPTY
81024
- ],
81025
-
81026
- // > Trailing spaces are ignored unless they are quoted with backslash ("\")
81027
- [
81028
- // (a\ ) -> (a )
81029
- // (a ) -> (a)
81030
- // (a ) -> (a)
81031
- // (a \ ) -> (a )
81032
- /((?:\\\\)*?)(\\?\s+)$/,
81033
- (_, m1, m2) => m1 + (
81034
- m2.indexOf('\\') === 0
81035
- ? SPACE
81036
- : EMPTY
81037
- )
81038
- ],
81039
-
81040
- // Replace (\ ) with ' '
81041
- // (\ ) -> ' '
81042
- // (\\ ) -> '\\ '
81043
- // (\\\ ) -> '\\ '
81044
- [
81045
- /(\\+?)\s/g,
81046
- (_, m1) => {
81047
- const {length} = m1;
81048
- return m1.slice(0, length - length % 2) + SPACE
81049
- }
81050
- ],
81051
-
81052
- // Escape metacharacters
81053
- // which is written down by users but means special for regular expressions.
81054
-
81055
- // > There are 12 characters with special meanings:
81056
- // > - the backslash \,
81057
- // > - the caret ^,
81058
- // > - the dollar sign $,
81059
- // > - the period or dot .,
81060
- // > - the vertical bar or pipe symbol |,
81061
- // > - the question mark ?,
81062
- // > - the asterisk or star *,
81063
- // > - the plus sign +,
81064
- // > - the opening parenthesis (,
81065
- // > - the closing parenthesis ),
81066
- // > - and the opening square bracket [,
81067
- // > - the opening curly brace {,
81068
- // > These special characters are often called "metacharacters".
81069
- [
81070
- /[\\$.|*+(){^]/g,
81071
- match => `\\${match}`
81072
- ],
81073
-
81074
- [
81075
- // > a question mark (?) matches a single character
81076
- /(?!\\)\?/g,
81077
- () => '[^/]'
81078
- ],
81079
-
81080
- // leading slash
81081
- [
81082
-
81083
- // > A leading slash matches the beginning of the pathname.
81084
- // > For example, "/*.c" matches "cat-file.c" but not "mozilla-sha1/sha1.c".
81085
- // A leading slash matches the beginning of the pathname
81086
- /^\//,
81087
- () => '^'
81088
- ],
81089
-
81090
- // replace special metacharacter slash after the leading slash
81091
- [
81092
- /\//g,
81093
- () => '\\/'
81094
- ],
81095
-
81096
- [
81097
- // > A leading "**" followed by a slash means match in all directories.
81098
- // > For example, "**/foo" matches file or directory "foo" anywhere,
81099
- // > the same as pattern "foo".
81100
- // > "**/foo/bar" matches file or directory "bar" anywhere that is directly
81101
- // > under directory "foo".
81102
- // Notice that the '*'s have been replaced as '\\*'
81103
- /^\^*\\\*\\\*\\\//,
81104
-
81105
- // '**/foo' <-> 'foo'
81106
- () => '^(?:.*\\/)?'
81107
- ],
81108
-
81109
- // starting
81110
- [
81111
- // there will be no leading '/'
81112
- // (which has been replaced by section "leading slash")
81113
- // If starts with '**', adding a '^' to the regular expression also works
81114
- /^(?=[^^])/,
81115
- function startingReplacer () {
81116
- // If has a slash `/` at the beginning or middle
81117
- return !/\/(?!$)/.test(this)
81118
- // > Prior to 2.22.1
81119
- // > If the pattern does not contain a slash /,
81120
- // > Git treats it as a shell glob pattern
81121
- // Actually, if there is only a trailing slash,
81122
- // git also treats it as a shell glob pattern
81123
-
81124
- // After 2.22.1 (compatible but clearer)
81125
- // > If there is a separator at the beginning or middle (or both)
81126
- // > of the pattern, then the pattern is relative to the directory
81127
- // > level of the particular .gitignore file itself.
81128
- // > Otherwise the pattern may also match at any level below
81129
- // > the .gitignore level.
81130
- ? '(?:^|\\/)'
81131
-
81132
- // > Otherwise, Git treats the pattern as a shell glob suitable for
81133
- // > consumption by fnmatch(3)
81134
- : '^'
81135
- }
81136
- ],
81137
-
81138
- // two globstars
81139
- [
81140
- // Use lookahead assertions so that we could match more than one `'/**'`
81141
- /\\\/\\\*\\\*(?=\\\/|$)/g,
81142
-
81143
- // Zero, one or several directories
81144
- // should not use '*', or it will be replaced by the next replacer
81145
-
81146
- // Check if it is not the last `'/**'`
81147
- (_, index, str) => index + 6 < str.length
81148
-
81149
- // case: /**/
81150
- // > A slash followed by two consecutive asterisks then a slash matches
81151
- // > zero or more directories.
81152
- // > For example, "a/**/b" matches "a/b", "a/x/b", "a/x/y/b" and so on.
81153
- // '/**/'
81154
- ? '(?:\\/[^\\/]+)*'
81155
-
81156
- // case: /**
81157
- // > A trailing `"/**"` matches everything inside.
81158
-
81159
- // #21: everything inside but it should not include the current folder
81160
- : '\\/.+'
81161
- ],
81162
-
81163
- // normal intermediate wildcards
81164
- [
81165
- // Never replace escaped '*'
81166
- // ignore rule '\*' will match the path '*'
81167
-
81168
- // 'abc.*/' -> go
81169
- // 'abc.*' -> skip this rule,
81170
- // coz trailing single wildcard will be handed by [trailing wildcard]
81171
- /(^|[^\\]+)(\\\*)+(?=.+)/g,
81172
-
81173
- // '*.js' matches '.js'
81174
- // '*.js' doesn't match 'abc'
81175
- (_, p1, p2) => {
81176
- // 1.
81177
- // > An asterisk "*" matches anything except a slash.
81178
- // 2.
81179
- // > Other consecutive asterisks are considered regular asterisks
81180
- // > and will match according to the previous rules.
81181
- const unescaped = p2.replace(/\\\*/g, '[^\\/]*');
81182
- return p1 + unescaped
81183
- }
81184
- ],
81185
-
81186
- [
81187
- // unescape, revert step 3 except for back slash
81188
- // For example, if a user escape a '\\*',
81189
- // after step 3, the result will be '\\\\\\*'
81190
- /\\\\\\(?=[$.|*+(){^])/g,
81191
- () => ESCAPE
81192
- ],
81193
-
81194
- [
81195
- // '\\\\' -> '\\'
81196
- /\\\\/g,
81197
- () => ESCAPE
81198
- ],
81199
-
81200
- [
81201
- // > The range notation, e.g. [a-zA-Z],
81202
- // > can be used to match one of the characters in a range.
81203
-
81204
- // `\` is escaped by step 3
81205
- /(\\)?\[([^\]/]*?)(\\*)($|\])/g,
81206
- (match, leadEscape, range, endEscape, close) => leadEscape === ESCAPE
81207
- // '\\[bar]' -> '\\\\[bar\\]'
81208
- ? `\\[${range}${cleanRangeBackSlash(endEscape)}${close}`
81209
- : close === ']'
81210
- ? endEscape.length % 2 === 0
81211
- // A normal case, and it is a range notation
81212
- // '[bar]'
81213
- // '[bar\\\\]'
81214
- ? `[${sanitizeRange(range)}${endEscape}]`
81215
- // Invalid range notaton
81216
- // '[bar\\]' -> '[bar\\\\]'
81217
- : '[]'
81218
- : '[]'
81219
- ],
81220
-
81221
- // ending
81222
- [
81223
- // 'js' will not match 'js.'
81224
- // 'ab' will not match 'abc'
81225
- /(?:[^*])$/,
81226
-
81227
- // WTF!
81228
- // https://git-scm.com/docs/gitignore
81229
- // changes in [2.22.1](https://git-scm.com/docs/gitignore/2.22.1)
81230
- // which re-fixes #24, #38
81231
-
81232
- // > If there is a separator at the end of the pattern then the pattern
81233
- // > will only match directories, otherwise the pattern can match both
81234
- // > files and directories.
81235
-
81236
- // 'js*' will not match 'a.js'
81237
- // 'js/' will not match 'a.js'
81238
- // 'js' will match 'a.js' and 'a.js/'
81239
- match => /\/$/.test(match)
81240
- // foo/ will not match 'foo'
81241
- ? `${match}$`
81242
- // foo matches 'foo' and 'foo/'
81243
- : `${match}(?=$|\\/$)`
81244
- ]
81245
- ];
81246
-
81247
- const REGEX_REPLACE_TRAILING_WILDCARD = /(^|\\\/)?\\\*$/;
81248
- const MODE_IGNORE = 'regex';
81249
- const MODE_CHECK_IGNORE = 'checkRegex';
81250
- const UNDERSCORE = '_';
81251
-
81252
- const TRAILING_WILD_CARD_REPLACERS = {
81253
- [MODE_IGNORE] (_, p1) {
81254
- const prefix = p1
81255
- // '\^':
81256
- // '/*' does not match EMPTY
81257
- // '/*' does not match everything
81258
-
81259
- // '\\\/':
81260
- // 'abc/*' does not match 'abc/'
81261
- ? `${p1}[^/]+`
81262
-
81263
- // 'a*' matches 'a'
81264
- // 'a*' matches 'aa'
81265
- : '[^/]*';
81266
-
81267
- return `${prefix}(?=$|\\/$)`
81268
- },
81269
-
81270
- [MODE_CHECK_IGNORE] (_, p1) {
81271
- // When doing `git check-ignore`
81272
- const prefix = p1
81273
- // '\\\/':
81274
- // 'abc/*' DOES match 'abc/' !
81275
- ? `${p1}[^/]*`
81276
-
81277
- // 'a*' matches 'a'
81278
- // 'a*' matches 'aa'
81279
- : '[^/]*';
81280
-
81281
- return `${prefix}(?=$|\\/$)`
81282
- }
81283
- };
81284
-
81285
- // @param {pattern}
81286
- const makeRegexPrefix = pattern => REPLACERS.reduce(
81287
- (prev, [matcher, replacer]) =>
81288
- prev.replace(matcher, replacer.bind(pattern)),
81289
- pattern
81290
- );
81291
-
81292
- const isString = subject => typeof subject === 'string';
81293
-
81294
- // > A blank line matches no files, so it can serve as a separator for readability.
81295
- const checkPattern = pattern => pattern
81296
- && isString(pattern)
81297
- && !REGEX_TEST_BLANK_LINE.test(pattern)
81298
- && !REGEX_INVALID_TRAILING_BACKSLASH.test(pattern)
81299
-
81300
- // > A line starting with # serves as a comment.
81301
- && pattern.indexOf('#') !== 0;
81302
-
81303
- const splitPattern = pattern => pattern
81304
- .split(REGEX_SPLITALL_CRLF)
81305
- .filter(Boolean);
81306
-
81307
- class IgnoreRule {
81308
- constructor (
81309
- pattern,
81310
- mark,
81311
- body,
81312
- ignoreCase,
81313
- negative,
81314
- prefix
81315
- ) {
81316
- this.pattern = pattern;
81317
- this.mark = mark;
81318
- this.negative = negative;
81319
-
81320
- define(this, 'body', body);
81321
- define(this, 'ignoreCase', ignoreCase);
81322
- define(this, 'regexPrefix', prefix);
81323
- }
81324
-
81325
- get regex () {
81326
- const key = UNDERSCORE + MODE_IGNORE;
81327
-
81328
- if (this[key]) {
81329
- return this[key]
81330
- }
81331
-
81332
- return this._make(MODE_IGNORE, key)
81333
- }
81334
-
81335
- get checkRegex () {
81336
- const key = UNDERSCORE + MODE_CHECK_IGNORE;
81337
-
81338
- if (this[key]) {
81339
- return this[key]
81340
- }
81341
-
81342
- return this._make(MODE_CHECK_IGNORE, key)
81343
- }
81344
-
81345
- _make (mode, key) {
81346
- const str = this.regexPrefix.replace(
81347
- REGEX_REPLACE_TRAILING_WILDCARD,
81348
-
81349
- // It does not need to bind pattern
81350
- TRAILING_WILD_CARD_REPLACERS[mode]
81351
- );
81352
-
81353
- const regex = this.ignoreCase
81354
- ? new RegExp(str, 'i')
81355
- : new RegExp(str);
81356
-
81357
- return define(this, key, regex)
81358
- }
81359
- }
81360
-
81361
- const createRule = ({
81362
- pattern,
81363
- mark
81364
- }, ignoreCase) => {
81365
- let negative = false;
81366
- let body = pattern;
81367
-
81368
- // > An optional prefix "!" which negates the pattern;
81369
- if (body.indexOf('!') === 0) {
81370
- negative = true;
81371
- body = body.substr(1);
81372
- }
81373
-
81374
- body = body
81375
- // > Put a backslash ("\") in front of the first "!" for patterns that
81376
- // > begin with a literal "!", for example, `"\!important!.txt"`.
81377
- .replace(REGEX_REPLACE_LEADING_EXCAPED_EXCLAMATION, '!')
81378
- // > Put a backslash ("\") in front of the first hash for patterns that
81379
- // > begin with a hash.
81380
- .replace(REGEX_REPLACE_LEADING_EXCAPED_HASH, '#');
81381
-
81382
- const regexPrefix = makeRegexPrefix(body);
81383
-
81384
- return new IgnoreRule(
81385
- pattern,
81386
- mark,
81387
- body,
81388
- ignoreCase,
81389
- negative,
81390
- regexPrefix
81391
- )
81392
- };
81393
-
81394
- class RuleManager {
81395
- constructor (ignoreCase) {
81396
- this._ignoreCase = ignoreCase;
81397
- this._rules = [];
81398
- }
81399
-
81400
- _add (pattern) {
81401
- // #32
81402
- if (pattern && pattern[KEY_IGNORE]) {
81403
- this._rules = this._rules.concat(pattern._rules._rules);
81404
- this._added = true;
81405
- return
81406
- }
81407
-
81408
- if (isString(pattern)) {
81409
- pattern = {
81410
- pattern
81411
- };
81412
- }
81413
-
81414
- if (checkPattern(pattern.pattern)) {
81415
- const rule = createRule(pattern, this._ignoreCase);
81416
- this._added = true;
81417
- this._rules.push(rule);
81418
- }
81419
- }
81420
-
81421
- // @param {Array<string> | string | Ignore} pattern
81422
- add (pattern) {
81423
- this._added = false;
81424
-
81425
- makeArray(
81426
- isString(pattern)
81427
- ? splitPattern(pattern)
81428
- : pattern
81429
- ).forEach(this._add, this);
81430
-
81431
- return this._added
81432
- }
81433
-
81434
- // Test one single path without recursively checking parent directories
81435
- //
81436
- // - checkUnignored `boolean` whether should check if the path is unignored,
81437
- // setting `checkUnignored` to `false` could reduce additional
81438
- // path matching.
81439
- // - check `string` either `MODE_IGNORE` or `MODE_CHECK_IGNORE`
81440
-
81441
- // @returns {TestResult} true if a file is ignored
81442
- test (path, checkUnignored, mode) {
81443
- let ignored = false;
81444
- let unignored = false;
81445
- let matchedRule;
81446
-
81447
- this._rules.forEach(rule => {
81448
- const {negative} = rule;
81449
-
81450
- // | ignored : unignored
81451
- // -------- | ---------------------------------------
81452
- // negative | 0:0 | 0:1 | 1:0 | 1:1
81453
- // -------- | ------- | ------- | ------- | --------
81454
- // 0 | TEST | TEST | SKIP | X
81455
- // 1 | TESTIF | SKIP | TEST | X
81456
-
81457
- // - SKIP: always skip
81458
- // - TEST: always test
81459
- // - TESTIF: only test if checkUnignored
81460
- // - X: that never happen
81461
- if (
81462
- unignored === negative && ignored !== unignored
81463
- || negative && !ignored && !unignored && !checkUnignored
81464
- ) {
81465
- return
81466
- }
81467
-
81468
- const matched = rule[mode].test(path);
81469
-
81470
- if (!matched) {
81471
- return
81472
- }
81473
-
81474
- ignored = !negative;
81475
- unignored = negative;
81476
-
81477
- matchedRule = negative
81478
- ? UNDEFINED
81479
- : rule;
81480
- });
81481
-
81482
- const ret = {
81483
- ignored,
81484
- unignored
81485
- };
81486
-
81487
- if (matchedRule) {
81488
- ret.rule = matchedRule;
81489
- }
81490
-
81491
- return ret
81492
- }
81493
- }
81494
-
81495
- const throwError = (message, Ctor) => {
81496
- throw new Ctor(message)
81497
- };
81498
-
81499
- const checkPath = (path, originalPath, doThrow) => {
81500
- if (!isString(path)) {
81501
- return doThrow(
81502
- `path must be a string, but got \`${originalPath}\``,
81503
- TypeError
81504
- )
81505
- }
81506
-
81507
- // We don't know if we should ignore EMPTY, so throw
81508
- if (!path) {
81509
- return doThrow(`path must not be empty`, TypeError)
81510
- }
81511
-
81512
- // Check if it is a relative path
81513
- if (checkPath.isNotRelative(path)) {
81514
- const r = '`path.relative()`d';
81515
- return doThrow(
81516
- `path should be a ${r} string, but got "${originalPath}"`,
81517
- RangeError
81518
- )
81519
- }
81520
-
81521
- return true
81522
- };
81523
-
81524
- const isNotRelative = path => REGEX_TEST_INVALID_PATH.test(path);
81525
-
81526
- checkPath.isNotRelative = isNotRelative;
81527
-
81528
- // On windows, the following function will be replaced
81529
- /* istanbul ignore next */
81530
- checkPath.convert = p => p;
81531
-
81532
-
81533
- class Ignore {
81534
- constructor ({
81535
- ignorecase = true,
81536
- ignoreCase = ignorecase,
81537
- allowRelativePaths = false
81538
- } = {}) {
81539
- define(this, KEY_IGNORE, true);
81540
-
81541
- this._rules = new RuleManager(ignoreCase);
81542
- this._strictPathCheck = !allowRelativePaths;
81543
- this._initCache();
81544
- }
81545
-
81546
- _initCache () {
81547
- // A cache for the result of `.ignores()`
81548
- this._ignoreCache = Object.create(null);
81549
-
81550
- // A cache for the result of `.test()`
81551
- this._testCache = Object.create(null);
81552
- }
81553
-
81554
- add (pattern) {
81555
- if (this._rules.add(pattern)) {
81556
- // Some rules have just added to the ignore,
81557
- // making the behavior changed,
81558
- // so we need to re-initialize the result cache
81559
- this._initCache();
81560
- }
81561
-
81562
- return this
81563
- }
81564
-
81565
- // legacy
81566
- addPattern (pattern) {
81567
- return this.add(pattern)
81568
- }
81569
-
81570
- // @returns {TestResult}
81571
- _test (originalPath, cache, checkUnignored, slices) {
81572
- const path = originalPath
81573
- // Supports nullable path
81574
- && checkPath.convert(originalPath);
81575
-
81576
- checkPath(
81577
- path,
81578
- originalPath,
81579
- this._strictPathCheck
81580
- ? throwError
81581
- : RETURN_FALSE
81582
- );
81583
-
81584
- return this._t(path, cache, checkUnignored, slices)
81585
- }
81586
-
81587
- checkIgnore (path) {
81588
- // If the path doest not end with a slash, `.ignores()` is much equivalent
81589
- // to `git check-ignore`
81590
- if (!REGEX_TEST_TRAILING_SLASH.test(path)) {
81591
- return this.test(path)
81592
- }
81593
-
81594
- const slices = path.split(SLASH).filter(Boolean);
81595
- slices.pop();
81596
-
81597
- if (slices.length) {
81598
- const parent = this._t(
81599
- slices.join(SLASH) + SLASH,
81600
- this._testCache,
81601
- true,
81602
- slices
81603
- );
81604
-
81605
- if (parent.ignored) {
81606
- return parent
81607
- }
81608
- }
81609
-
81610
- return this._rules.test(path, false, MODE_CHECK_IGNORE)
81611
- }
81612
-
81613
- _t (
81614
- // The path to be tested
81615
- path,
81616
-
81617
- // The cache for the result of a certain checking
81618
- cache,
81619
-
81620
- // Whether should check if the path is unignored
81621
- checkUnignored,
81622
-
81623
- // The path slices
81624
- slices
81625
- ) {
81626
- if (path in cache) {
81627
- return cache[path]
81628
- }
81629
-
81630
- if (!slices) {
81631
- // path/to/a.js
81632
- // ['path', 'to', 'a.js']
81633
- slices = path.split(SLASH).filter(Boolean);
81634
- }
81635
-
81636
- slices.pop();
81637
-
81638
- // If the path has no parent directory, just test it
81639
- if (!slices.length) {
81640
- return cache[path] = this._rules.test(path, checkUnignored, MODE_IGNORE)
81641
- }
81642
-
81643
- const parent = this._t(
81644
- slices.join(SLASH) + SLASH,
81645
- cache,
81646
- checkUnignored,
81647
- slices
81648
- );
81649
-
81650
- // If the path contains a parent directory, check the parent first
81651
- return cache[path] = parent.ignored
81652
- // > It is not possible to re-include a file if a parent directory of
81653
- // > that file is excluded.
81654
- ? parent
81655
- : this._rules.test(path, checkUnignored, MODE_IGNORE)
81656
- }
81657
-
81658
- ignores (path) {
81659
- return this._test(path, this._ignoreCache, false).ignored
81660
- }
81661
-
81662
- createFilter () {
81663
- return path => !this.ignores(path)
81664
- }
81665
-
81666
- filter (paths) {
81667
- return makeArray(paths).filter(this.createFilter())
81668
- }
81669
-
81670
- // @returns {TestResult}
81671
- test (path) {
81672
- return this._test(path, this._testCache, true)
81673
- }
81674
- }
81675
-
81676
- const factory = options => new Ignore(options);
81677
-
81678
- const isPathValid = path =>
81679
- checkPath(path && checkPath.convert(path), path, RETURN_FALSE);
81680
-
81681
- /* istanbul ignore next */
81682
- const setupWindows = () => {
81683
- /* eslint no-control-regex: "off" */
81684
- const makePosix = str => /^\\\\\?\\/.test(str)
81685
- || /["<>|\u0000-\u001F]+/u.test(str)
81686
- ? str
81687
- : str.replace(/\\/g, '/');
81688
-
81689
- checkPath.convert = makePosix;
81690
-
81691
- // 'C:\\foo' <- 'C:\\foo' has been converted to 'C:/'
81692
- // 'd:\\foo'
81693
- const REGEX_TEST_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
81694
- checkPath.isNotRelative = path =>
81695
- REGEX_TEST_WINDOWS_PATH_ABSOLUTE.test(path)
81696
- || isNotRelative(path);
81697
- };
81698
-
81699
- // COMMONJS_EXPORTS ////////////////////////////////////////////////////////////
81700
-
81701
- module.exports = factory;
81702
-
81703
- // Although it is an anti-pattern,
81704
- // it is still widely misused by a lot of libraries in github
81705
- // Ref: https://github.com/search?q=ignore.default%28%29&type=code
81706
- factory.default = factory;
81707
-
81708
- module.exports.isPathValid = isPathValid;
81709
-
81710
- // For testing purposes
81711
- define(module.exports, Symbol.for('setupWindows'), setupWindows);
81712
- } (ignore$2));
81713
-
81714
- var ignoreExports = ignore$2.exports;
81715
- ignoreExports.default;
81716
-
81717
77367
  const {relative} = require$$0$1;
81718
- const ignore$1 = ignoreExports;
77368
+ const ignore$1 = require$$1$1;
81719
77369
 
81720
77370
  const isNegative = (a) => !a.indexOf('!');
81721
77371
  const positive = (a) => a.replace(/^!/, '');