hermes-estree 0.9.0 → 0.10.1

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.
Files changed (41) hide show
  1. package/dist/HermesAST.js.flow +57 -0
  2. package/dist/HermesASTAdapter.js +186 -0
  3. package/dist/HermesASTAdapter.js.flow +183 -0
  4. package/dist/HermesParser.js +83 -0
  5. package/dist/HermesParser.js.flow +123 -0
  6. package/dist/HermesParserDecodeUTF8String.js +68 -0
  7. package/dist/HermesParserDecodeUTF8String.js.flow +65 -0
  8. package/dist/HermesParserDeserializer.js +243 -0
  9. package/dist/HermesParserDeserializer.js.flow +261 -0
  10. package/dist/HermesParserNodeDeserializers.js +2008 -0
  11. package/dist/HermesParserNodeDeserializers.js.flow +16 -0
  12. package/dist/HermesParserWASM.js +6 -0
  13. package/dist/HermesParserWASM.js.flow +75 -0
  14. package/dist/HermesToBabelAdapter.js +514 -0
  15. package/dist/HermesToBabelAdapter.js.flow +490 -0
  16. package/dist/HermesToESTreeAdapter.js +439 -0
  17. package/dist/HermesToESTreeAdapter.js.flow +422 -0
  18. package/dist/ParserOptions.js.flow +18 -0
  19. package/dist/generated/ESTreeVisitorKeys.js +180 -0
  20. package/dist/generated/ESTreeVisitorKeys.js.flow +15 -0
  21. package/dist/generated/HermesESTreeSelectorTypes.js.flow +20 -1
  22. package/dist/generated/ParserVisitorKeys.js +622 -0
  23. package/dist/generated/ParserVisitorKeys.js.flow +17 -0
  24. package/dist/generated/predicates.js +24 -12
  25. package/dist/generated/predicates.js.flow +34 -23
  26. package/dist/getModuleDocblock.js +112 -0
  27. package/dist/getModuleDocblock.js.flow +118 -0
  28. package/dist/predicates.js +13 -1
  29. package/dist/predicates.js.flow +125 -2
  30. package/dist/transform/SimpleTransform.js +92 -0
  31. package/dist/transform/SimpleTransform.js.flow +104 -0
  32. package/dist/transform/astArrayMutationHelpers.js +62 -0
  33. package/dist/transform/astArrayMutationHelpers.js.flow +71 -0
  34. package/dist/transform/astNodeMutationHelpers.js +186 -0
  35. package/dist/transform/astNodeMutationHelpers.js.flow +205 -0
  36. package/dist/traverse/SimpleTraverser.js +138 -0
  37. package/dist/traverse/SimpleTraverser.js.flow +132 -0
  38. package/dist/traverse/getVisitorKeys.js +35 -0
  39. package/dist/traverse/getVisitorKeys.js.flow +36 -0
  40. package/dist/types.js.flow +128 -30
  41. package/package.json +1 -1
@@ -38,7 +38,10 @@
38
38
 
39
39
  export type Range = [number, number];
40
40
 
41
- export interface BaseToken {
41
+ export interface ObjectWithLoc {
42
+ +loc: SourceLocation;
43
+ }
44
+ export interface BaseToken extends ObjectWithLoc {
42
45
  +loc: SourceLocation;
43
46
  +range: Range;
44
47
  }
@@ -106,7 +109,7 @@ export interface Position {
106
109
  }
107
110
 
108
111
  // note: this is only ever present on Program.interpreter, never in the body
109
- interface InterpreterDirective extends BaseNode {
112
+ export interface InterpreterDirective extends BaseNode {
110
113
  type: 'InterpreterDirective';
111
114
  value: string;
112
115
  }
@@ -226,6 +229,9 @@ export type Statement =
226
229
  | ClassDeclaration
227
230
  | ContinueStatement
228
231
  | DebuggerStatement
232
+ | DeclareClass
233
+ | DeclareVariable
234
+ | DeclareFunction
229
235
  | DeclareInterface
230
236
  | DeclareModule
231
237
  | DeclareOpaqueType
@@ -471,7 +477,7 @@ export interface ObjectPropertyWithShorthandStaticName
471
477
  // shorthand values *must* be identifiers (that look the same as the key)
472
478
  +value: Identifier;
473
479
  +kind: 'init';
474
- +method: boolean;
480
+ +method: false;
475
481
  +shorthand: true;
476
482
  }
477
483
  export interface ObjectPropertyWithComputedName extends ObjectPropertyBase {
@@ -850,7 +856,7 @@ interface BaseClass extends BaseNode {
850
856
  +body: ClassBody;
851
857
 
852
858
  +typeParameters: null | TypeParameterDeclaration;
853
- +superTypeParameters: null | TypeParameterDeclaration;
859
+ +superTypeParameters: null | TypeParameterInstantiation;
854
860
  +implements: $ReadOnlyArray<ClassImplements>;
855
861
  +decorators: $ReadOnlyArray<Decorator>;
856
862
  }
@@ -1024,13 +1030,30 @@ export type NamedDeclaration =
1024
1030
  | InterfaceDeclaration
1025
1031
  | EnumDeclaration;
1026
1032
 
1027
- export interface ExportNamedDeclaration extends BaseNode {
1033
+ interface ExportNamedDeclarationBase extends BaseNode {
1028
1034
  +type: 'ExportNamedDeclaration';
1029
1035
  +declaration?: NamedDeclaration | null;
1030
1036
  +specifiers: $ReadOnlyArray<ExportSpecifier>;
1031
- +source?: Literal | null;
1037
+ +source?: StringLiteral | null;
1032
1038
  +exportKind: 'value' | 'type';
1033
1039
  }
1040
+ export interface ExportNamedDeclarationWithSpecifiers
1041
+ extends ExportNamedDeclarationBase {
1042
+ +type: 'ExportNamedDeclaration';
1043
+ +declaration: null;
1044
+ +source: null;
1045
+ +specifiers: $ReadOnlyArray<ExportSpecifier>;
1046
+ }
1047
+ export interface ExportNamedDeclarationWithDeclaration
1048
+ extends ExportNamedDeclarationBase {
1049
+ +type: 'ExportNamedDeclaration';
1050
+ +declaration: NamedDeclaration;
1051
+ +source: null;
1052
+ +specifiers: [];
1053
+ }
1054
+ export type ExportNamedDeclaration =
1055
+ | ExportNamedDeclarationWithSpecifiers
1056
+ | ExportNamedDeclarationWithDeclaration;
1034
1057
 
1035
1058
  export interface ExportSpecifier extends BaseNode {
1036
1059
  +type: 'ExportSpecifier';
@@ -1045,7 +1068,7 @@ export interface ExportDefaultDeclaration extends BaseNode {
1045
1068
 
1046
1069
  export interface ExportAllDeclaration extends BaseNode {
1047
1070
  +type: 'ExportAllDeclaration';
1048
- +source: Literal;
1071
+ +source: StringLiteral;
1049
1072
  +exportKind: 'value' | 'type';
1050
1073
  +exported?: Identifier | null;
1051
1074
  }
@@ -1062,6 +1085,7 @@ export interface AwaitExpression extends BaseNode {
1062
1085
  export type TypeAnnotationType =
1063
1086
  | NumberTypeAnnotation
1064
1087
  | StringTypeAnnotation
1088
+ | BigIntTypeAnnotation
1065
1089
  | BooleanTypeAnnotation
1066
1090
  | NullLiteralTypeAnnotation
1067
1091
  | AnyTypeAnnotation
@@ -1125,6 +1149,9 @@ export interface NumberTypeAnnotation extends BaseNode {
1125
1149
  export interface StringTypeAnnotation extends BaseNode {
1126
1150
  +type: 'StringTypeAnnotation';
1127
1151
  }
1152
+ export interface BigIntTypeAnnotation extends BaseNode {
1153
+ +type: 'BigIntTypeAnnotation';
1154
+ }
1128
1155
  export interface BooleanTypeAnnotation extends BaseNode {
1129
1156
  +type: 'BooleanTypeAnnotation';
1130
1157
  }
@@ -1161,13 +1188,14 @@ export interface NumberLiteralTypeAnnotation extends BaseNode {
1161
1188
  }
1162
1189
  export interface BigIntLiteralTypeAnnotation extends BaseNode {
1163
1190
  +type: 'BigIntLiteralTypeAnnotation';
1164
- +value: null;
1191
+ +bigint: string;
1192
+ +value: null /* | bigint */;
1165
1193
  +raw: string;
1166
1194
  }
1167
1195
  export interface BooleanLiteralTypeAnnotation extends BaseNode {
1168
1196
  +type: 'BooleanLiteralTypeAnnotation';
1169
1197
  +value: boolean;
1170
- +raw: string;
1198
+ +raw: 'true' | 'false';
1171
1199
  }
1172
1200
  export interface ArrayTypeAnnotation extends BaseNode {
1173
1201
  +type: 'ArrayTypeAnnotation';
@@ -1196,7 +1224,7 @@ export interface TypeofTypeAnnotation extends BaseNode {
1196
1224
  }
1197
1225
  export interface TupleTypeAnnotation extends BaseNode {
1198
1226
  +type: 'TupleTypeAnnotation';
1199
- +types: TypeAnnotationType;
1227
+ +types: $ReadOnlyArray<TypeAnnotationType>;
1200
1228
  }
1201
1229
 
1202
1230
  // type T = { [[foo]]: number };
@@ -1230,7 +1258,7 @@ export interface FunctionTypeAnnotation extends BaseNode {
1230
1258
  +returnType: TypeAnnotationType;
1231
1259
  +rest: null | FunctionTypeParam;
1232
1260
  +typeParameters: null | TypeParameterDeclaration;
1233
- +this: TypeAnnotationType | null;
1261
+ +this: FunctionTypeParam | null;
1234
1262
  }
1235
1263
  export interface FunctionTypeParam extends BaseNode {
1236
1264
  +type: 'FunctionTypeParam';
@@ -1255,23 +1283,58 @@ export interface ObjectTypeAnnotation extends BaseNode {
1255
1283
  +callProperties: $ReadOnlyArray<ObjectTypeCallProperty>;
1256
1284
  +internalSlots: $ReadOnlyArray<ObjectTypeInternalSlot>;
1257
1285
  }
1258
- export interface ObjectTypeProperty extends BaseNode {
1286
+ interface ObjectTypePropertyBase extends BaseNode {
1259
1287
  +type: 'ObjectTypeProperty';
1260
- +key: Identifier;
1288
+ +key: Identifier | StringLiteral;
1261
1289
  +value: TypeAnnotationType;
1262
1290
  +method: boolean;
1263
1291
  +optional: boolean;
1264
- +static: false; // can't be static
1265
- +proto: false; // ???
1292
+ +static: boolean; // only applies to the "declare class" case
1293
+ +proto: boolean; // only applies to the "declare class" case
1294
+ +variance: Variance | null;
1295
+ +kind: 'init' | 'get' | 'set';
1296
+
1297
+ +parent: ObjectTypeAnnotation;
1298
+ }
1299
+ export interface ObjectTypeMethodSignature extends ObjectTypePropertyBase {
1300
+ +type: 'ObjectTypeProperty';
1301
+ +value: FunctionTypeAnnotation;
1302
+ +method: true;
1303
+ +optional: false;
1304
+ +variance: null;
1305
+ +kind: 'init';
1306
+
1307
+ +parent: ObjectTypeAnnotation;
1308
+ }
1309
+ export interface ObjectTypePropertySignature extends ObjectTypePropertyBase {
1310
+ +type: 'ObjectTypeProperty';
1311
+ +value: TypeAnnotationType;
1312
+ +method: false;
1313
+ +optional: boolean;
1266
1314
  +variance: Variance | null;
1267
1315
  +kind: 'init';
1268
1316
 
1269
1317
  +parent: ObjectTypeAnnotation;
1270
1318
  }
1319
+ export interface ObjectTypeAccessorSignature extends ObjectTypePropertyBase {
1320
+ +type: 'ObjectTypeProperty';
1321
+ +value: FunctionTypeAnnotation;
1322
+ +method: false;
1323
+ +optional: false;
1324
+ +variance: null;
1325
+ +kind: 'get' | 'set';
1326
+
1327
+ +parent: ObjectTypeAnnotation;
1328
+ }
1329
+ export type ObjectTypeProperty =
1330
+ | ObjectTypeMethodSignature
1331
+ | ObjectTypePropertySignature
1332
+ | ObjectTypeAccessorSignature;
1333
+
1271
1334
  export interface ObjectTypeCallProperty extends BaseNode {
1272
1335
  +type: 'ObjectTypeCallProperty';
1273
1336
  +value: FunctionTypeAnnotation;
1274
- +static: false; // can't be static
1337
+ +static: boolean; // can only be static when defined on a declare class
1275
1338
 
1276
1339
  +parent: ObjectTypeAnnotation;
1277
1340
  }
@@ -1280,7 +1343,7 @@ export interface ObjectTypeIndexer extends BaseNode {
1280
1343
  +id: null | Identifier;
1281
1344
  +key: TypeAnnotationType;
1282
1345
  +value: TypeAnnotationType;
1283
- +static: false; // can't be static
1346
+ +static: boolean; // can only be static when defined on a declare class
1284
1347
  +variance: null | Variance;
1285
1348
 
1286
1349
  +parent: ObjectTypeAnnotation;
@@ -1294,13 +1357,13 @@ export interface ObjectTypeSpreadProperty extends BaseNode {
1294
1357
 
1295
1358
  export interface IndexedAccessType extends BaseNode {
1296
1359
  +type: 'IndexedAccessType';
1297
- +objectType: TypeAnnotation;
1298
- +indexType: TypeAnnotation;
1360
+ +objectType: TypeAnnotationType;
1361
+ +indexType: TypeAnnotationType;
1299
1362
  }
1300
1363
  export interface OptionalIndexedAccessType extends BaseNode {
1301
1364
  +type: 'OptionalIndexedAccessType';
1302
- +objectType: TypeAnnotation;
1303
- +indexType: TypeAnnotation;
1365
+ +objectType: TypeAnnotationType;
1366
+ +indexType: TypeAnnotationType;
1304
1367
  +optional: boolean;
1305
1368
  }
1306
1369
 
@@ -1326,7 +1389,7 @@ export interface InterfaceDeclaration extends BaseInterfaceDeclaration {
1326
1389
  export interface InterfaceExtends extends BaseNode {
1327
1390
  +type: 'InterfaceExtends';
1328
1391
  +id: Identifier;
1329
- +typeParameters: null | TypeParameterDeclaration;
1392
+ +typeParameters: null | TypeParameterInstantiation;
1330
1393
 
1331
1394
  +parent: InterfaceDeclaration | DeclareInterface;
1332
1395
  }
@@ -1334,7 +1397,7 @@ export interface InterfaceExtends extends BaseNode {
1334
1397
  export interface ClassImplements extends BaseNode {
1335
1398
  +type: 'ClassImplements';
1336
1399
  +id: Identifier;
1337
- +typeParameters: null | TypeParameterDeclaration;
1400
+ +typeParameters: null | TypeParameterInstantiation;
1338
1401
 
1339
1402
  +parent: AClass | DeclareClass;
1340
1403
  }
@@ -1476,7 +1539,12 @@ export interface DeclareVariable extends BaseNode {
1476
1539
 
1477
1540
  export interface DeclareFunction extends BaseNode {
1478
1541
  +type: 'DeclareFunction';
1479
- +id: Identifier;
1542
+ // the function signature is stored as a type annotation on the ID
1543
+ +id: interface extends Identifier {
1544
+ +typeAnnotation: interface extends TypeAnnotation {
1545
+ +typeAnnotation: FunctionTypeAnnotation,
1546
+ },
1547
+ };
1480
1548
  +predicate: InferredPredicate | DeclaredPredicate | null;
1481
1549
  }
1482
1550
 
@@ -1505,19 +1573,49 @@ export interface DeclareExportAllDeclaration extends BaseNode {
1505
1573
  +source: StringLiteral;
1506
1574
  }
1507
1575
 
1508
- export interface DeclareExportDeclaration extends BaseNode {
1576
+ interface DeclareExportDeclarationBase extends BaseNode {
1509
1577
  +type: 'DeclareExportDeclaration';
1510
1578
  +specifiers: $ReadOnlyArray<ExportSpecifier>;
1579
+ +source: StringLiteral | null;
1580
+ +default: boolean;
1581
+ }
1582
+ export interface DeclareExportDefaultDeclaration
1583
+ extends DeclareExportDeclarationBase {
1584
+ +type: 'DeclareExportDeclaration';
1585
+ +declaration: DeclareClass | DeclareFunction | TypeAnnotationType;
1586
+ +default: true;
1587
+ // default cannot have a source
1588
+ +source: null;
1589
+ // default cannot have specifiers
1590
+ +specifiers: [];
1591
+ }
1592
+ export interface DeclareExportDeclarationNamedWithDeclaration
1593
+ extends DeclareExportDeclarationBase {
1594
+ +type: 'DeclareExportDeclaration';
1511
1595
  +declaration:
1512
- | TypeAlias
1513
1596
  | DeclareClass
1514
1597
  | DeclareFunction
1515
- | DeclareOpaqueType
1516
1598
  | DeclareInterface
1517
- | null;
1518
- +source: StringLiteral | null;
1519
- +default: boolean;
1599
+ | DeclareOpaqueType
1600
+ | DeclareVariable;
1601
+ +default: false;
1602
+ +source: null;
1603
+ // default cannot have specifiers and a declaration
1604
+ +specifiers: [];
1605
+ }
1606
+ export interface DeclareExportDeclarationNamedWithSpecifiers
1607
+ extends DeclareExportDeclarationBase {
1608
+ +type: 'DeclareExportDeclaration';
1609
+ // with a source you can't have a declaration
1610
+ +declaration: null;
1611
+ +default: false;
1612
+ +source: StringLiteral;
1613
+ +specifiers: $ReadOnlyArray<ExportSpecifier>;
1520
1614
  }
1615
+ export type DeclareExportDeclaration =
1616
+ | DeclareExportDefaultDeclaration
1617
+ | DeclareExportDeclarationNamedWithDeclaration
1618
+ | DeclareExportDeclarationNamedWithSpecifiers;
1521
1619
 
1522
1620
  export interface DeclareModuleExports extends BaseNode {
1523
1621
  +type: 'DeclareModuleExports';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-estree",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Flow types for the Flow-ESTree spec produced by the hermes parser",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",