hermes-transform 0.10.1 → 0.11.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.
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.asDetachedNode = void 0;
7
+ exports.asDetachedNodeForCodeGen = asDetachedNodeForCodeGen;
7
8
  exports.deepCloneNode = deepCloneNode;
8
9
  exports.detachedProps = detachedProps;
9
10
  exports.getOriginalNode = getOriginalNode;
@@ -35,6 +36,21 @@ function getOriginalNode(node) {
35
36
  // $FlowExpectedError[prop-missing]
36
37
  return node[ORIGINAL_NODE];
37
38
  }
39
+ /* $FlowExpectedError[unclear-type] Type safety is not needed for generated
40
+ * code, this avoids us always having to pass a generic property within codegen */
41
+
42
+
43
+ function asDetachedNodeForCodeGen(node) {
44
+ if (node == null) {
45
+ return null;
46
+ }
47
+
48
+ if (isDetachedNode(node)) {
49
+ return node;
50
+ }
51
+
52
+ return shallowCloneNode(node, {});
53
+ }
38
54
 
39
55
  const asDetachedNode = (node, {
40
56
  useDeepClone
@@ -32,6 +32,20 @@ export function getOriginalNode(node: MaybeDetachedNode<ESNode>): ?ESNode {
32
32
  return node[ORIGINAL_NODE];
33
33
  }
34
34
 
35
+ /* $FlowExpectedError[unclear-type] Type safety is not needed for generated
36
+ * code, this avoids us always having to pass a generic property within codegen */
37
+ export function asDetachedNodeForCodeGen(node: any): ?DetachedNode<any> {
38
+ if (node == null) {
39
+ return null;
40
+ }
41
+
42
+ if (isDetachedNode(node)) {
43
+ return node;
44
+ }
45
+
46
+ return shallowCloneNode<ESNode>(node, {});
47
+ }
48
+
35
49
  export const asDetachedNode: {
36
50
  <T: ESNode>(
37
51
  node: MaybeDetachedNode<T>,
@@ -46,11 +46,18 @@ import type {
46
46
  ClassDeclaration,
47
47
  ClassExpression,
48
48
  ClassImplements,
49
+ ComponentDeclaration,
50
+ ComponentParameter,
51
+ ComponentTypeAnnotation,
52
+ ComponentTypeParameter,
49
53
  ConditionalExpression,
54
+ ConditionalTypeAnnotation,
50
55
  ContinueStatement,
51
56
  DebuggerStatement,
52
57
  DeclareClass,
58
+ DeclareComponent,
53
59
  DeclaredPredicate,
60
+ DeclareEnum,
54
61
  DeclareExportAllDeclaration,
55
62
  DeclareExportDeclaration,
56
63
  DeclareFunction,
@@ -96,6 +103,7 @@ import type {
96
103
  ImportSpecifier,
97
104
  IndexedAccessType,
98
105
  InferredPredicate,
106
+ InferTypeAnnotation,
99
107
  InterfaceDeclaration,
100
108
  InterfaceExtends,
101
109
  InterfaceTypeAnnotation,
@@ -115,6 +123,7 @@ import type {
115
123
  JSXSpreadAttribute,
116
124
  JSXSpreadChild,
117
125
  JSXText,
126
+ KeyofTypeAnnotation,
118
127
  LabeledStatement,
119
128
  LogicalExpression,
120
129
  MemberExpression,
@@ -134,6 +143,7 @@ import type {
134
143
  ObjectTypeCallProperty,
135
144
  ObjectTypeIndexer,
136
145
  ObjectTypeInternalSlot,
146
+ ObjectTypeMappedTypeProperty,
137
147
  ObjectTypeProperty,
138
148
  ObjectTypeSpreadProperty,
139
149
  OpaqueType,
@@ -142,6 +152,7 @@ import type {
142
152
  Property,
143
153
  PropertyDefinition,
144
154
  QualifiedTypeIdentifier,
155
+ QualifiedTypeofIdentifier,
145
156
  RegExpLiteral,
146
157
  RestElement,
147
158
  ReturnStatement,
@@ -162,6 +173,8 @@ import type {
162
173
  ThrowStatement,
163
174
  TryStatement,
164
175
  TupleTypeAnnotation,
176
+ TupleTypeLabeledElement,
177
+ TupleTypeSpreadElement,
165
178
  TypeAlias,
166
179
  TypeAnnotation,
167
180
  TypeCastExpression,
@@ -169,6 +182,7 @@ import type {
169
182
  TypeParameter,
170
183
  TypeParameterDeclaration,
171
184
  TypeParameterInstantiation,
185
+ TypePredicate,
172
186
  UnaryExpression,
173
187
  UnionTypeAnnotation,
174
188
  UpdateExpression,
@@ -205,11 +219,18 @@ import type {
205
219
  ClassDeclarationProps,
206
220
  ClassExpressionProps,
207
221
  ClassImplementsProps,
222
+ ComponentDeclarationProps,
223
+ ComponentParameterProps,
224
+ ComponentTypeAnnotationProps,
225
+ ComponentTypeParameterProps,
208
226
  ConditionalExpressionProps,
227
+ ConditionalTypeAnnotationProps,
209
228
  ContinueStatementProps,
210
229
  DebuggerStatementProps,
211
230
  DeclareClassProps,
231
+ DeclareComponentProps,
212
232
  DeclaredPredicateProps,
233
+ DeclareEnumProps,
213
234
  DeclareExportAllDeclarationProps,
214
235
  DeclareExportDeclarationProps,
215
236
  DeclareFunctionProps,
@@ -255,6 +276,7 @@ import type {
255
276
  ImportSpecifierProps,
256
277
  IndexedAccessTypeProps,
257
278
  InferredPredicateProps,
279
+ InferTypeAnnotationProps,
258
280
  InterfaceDeclarationProps,
259
281
  InterfaceExtendsProps,
260
282
  InterfaceTypeAnnotationProps,
@@ -274,6 +296,7 @@ import type {
274
296
  JSXSpreadAttributeProps,
275
297
  JSXSpreadChildProps,
276
298
  JSXTextProps,
299
+ KeyofTypeAnnotationProps,
277
300
  LabeledStatementProps,
278
301
  LogicalExpressionProps,
279
302
  MemberExpressionProps,
@@ -293,6 +316,7 @@ import type {
293
316
  ObjectTypeCallPropertyProps,
294
317
  ObjectTypeIndexerProps,
295
318
  ObjectTypeInternalSlotProps,
319
+ ObjectTypeMappedTypePropertyProps,
296
320
  ObjectTypePropertyProps,
297
321
  ObjectTypeSpreadPropertyProps,
298
322
  OpaqueTypeProps,
@@ -301,6 +325,7 @@ import type {
301
325
  PropertyProps,
302
326
  PropertyDefinitionProps,
303
327
  QualifiedTypeIdentifierProps,
328
+ QualifiedTypeofIdentifierProps,
304
329
  RegExpLiteralProps,
305
330
  RestElementProps,
306
331
  ReturnStatementProps,
@@ -321,6 +346,8 @@ import type {
321
346
  ThrowStatementProps,
322
347
  TryStatementProps,
323
348
  TupleTypeAnnotationProps,
349
+ TupleTypeLabeledElementProps,
350
+ TupleTypeSpreadElementProps,
324
351
  TypeAliasProps,
325
352
  TypeAnnotationProps,
326
353
  TypeCastExpressionProps,
@@ -328,6 +355,7 @@ import type {
328
355
  TypeParameterProps,
329
356
  TypeParameterDeclarationProps,
330
357
  TypeParameterInstantiationProps,
358
+ TypePredicateProps,
331
359
  UnaryExpressionProps,
332
360
  UnionTypeAnnotationProps,
333
361
  UpdateExpressionProps,
@@ -533,6 +561,38 @@ type ClassImplementsCloneSignature = ((
533
561
  node: ?ClassImplements,
534
562
  newProps: Partial<ClassImplementsProps>,
535
563
  ) => DetachedNode<ClassImplements> | null);
564
+ type ComponentDeclarationCloneSignature = ((
565
+ node: ComponentDeclaration,
566
+ newProps: Partial<ComponentDeclarationProps>,
567
+ ) => DetachedNode<ComponentDeclaration>) &
568
+ ((
569
+ node: ?ComponentDeclaration,
570
+ newProps: Partial<ComponentDeclarationProps>,
571
+ ) => DetachedNode<ComponentDeclaration> | null);
572
+ type ComponentParameterCloneSignature = ((
573
+ node: ComponentParameter,
574
+ newProps: Partial<ComponentParameterProps>,
575
+ ) => DetachedNode<ComponentParameter>) &
576
+ ((
577
+ node: ?ComponentParameter,
578
+ newProps: Partial<ComponentParameterProps>,
579
+ ) => DetachedNode<ComponentParameter> | null);
580
+ type ComponentTypeAnnotationCloneSignature = ((
581
+ node: ComponentTypeAnnotation,
582
+ newProps: Partial<ComponentTypeAnnotationProps>,
583
+ ) => DetachedNode<ComponentTypeAnnotation>) &
584
+ ((
585
+ node: ?ComponentTypeAnnotation,
586
+ newProps: Partial<ComponentTypeAnnotationProps>,
587
+ ) => DetachedNode<ComponentTypeAnnotation> | null);
588
+ type ComponentTypeParameterCloneSignature = ((
589
+ node: ComponentTypeParameter,
590
+ newProps: Partial<ComponentTypeParameterProps>,
591
+ ) => DetachedNode<ComponentTypeParameter>) &
592
+ ((
593
+ node: ?ComponentTypeParameter,
594
+ newProps: Partial<ComponentTypeParameterProps>,
595
+ ) => DetachedNode<ComponentTypeParameter> | null);
536
596
  type ConditionalExpressionCloneSignature = ((
537
597
  node: ConditionalExpression,
538
598
  newProps: Partial<ConditionalExpressionProps>,
@@ -541,6 +601,14 @@ type ConditionalExpressionCloneSignature = ((
541
601
  node: ?ConditionalExpression,
542
602
  newProps: Partial<ConditionalExpressionProps>,
543
603
  ) => DetachedNode<ConditionalExpression> | null);
604
+ type ConditionalTypeAnnotationCloneSignature = ((
605
+ node: ConditionalTypeAnnotation,
606
+ newProps: Partial<ConditionalTypeAnnotationProps>,
607
+ ) => DetachedNode<ConditionalTypeAnnotation>) &
608
+ ((
609
+ node: ?ConditionalTypeAnnotation,
610
+ newProps: Partial<ConditionalTypeAnnotationProps>,
611
+ ) => DetachedNode<ConditionalTypeAnnotation> | null);
544
612
  type ContinueStatementCloneSignature = ((
545
613
  node: ContinueStatement,
546
614
  newProps: Partial<ContinueStatementProps>,
@@ -565,6 +633,14 @@ type DeclareClassCloneSignature = ((
565
633
  node: ?DeclareClass,
566
634
  newProps: Partial<DeclareClassProps>,
567
635
  ) => DetachedNode<DeclareClass> | null);
636
+ type DeclareComponentCloneSignature = ((
637
+ node: DeclareComponent,
638
+ newProps: Partial<DeclareComponentProps>,
639
+ ) => DetachedNode<DeclareComponent>) &
640
+ ((
641
+ node: ?DeclareComponent,
642
+ newProps: Partial<DeclareComponentProps>,
643
+ ) => DetachedNode<DeclareComponent> | null);
568
644
  type DeclaredPredicateCloneSignature = ((
569
645
  node: DeclaredPredicate,
570
646
  newProps: Partial<DeclaredPredicateProps>,
@@ -573,6 +649,14 @@ type DeclaredPredicateCloneSignature = ((
573
649
  node: ?DeclaredPredicate,
574
650
  newProps: Partial<DeclaredPredicateProps>,
575
651
  ) => DetachedNode<DeclaredPredicate> | null);
652
+ type DeclareEnumCloneSignature = ((
653
+ node: DeclareEnum,
654
+ newProps: Partial<DeclareEnumProps>,
655
+ ) => DetachedNode<DeclareEnum>) &
656
+ ((
657
+ node: ?DeclareEnum,
658
+ newProps: Partial<DeclareEnumProps>,
659
+ ) => DetachedNode<DeclareEnum> | null);
576
660
  type DeclareExportAllDeclarationCloneSignature = ((
577
661
  node: DeclareExportAllDeclaration,
578
662
  newProps: Partial<DeclareExportAllDeclarationProps>,
@@ -933,6 +1017,14 @@ type InferredPredicateCloneSignature = ((
933
1017
  node: ?InferredPredicate,
934
1018
  newProps: Partial<InferredPredicateProps>,
935
1019
  ) => DetachedNode<InferredPredicate> | null);
1020
+ type InferTypeAnnotationCloneSignature = ((
1021
+ node: InferTypeAnnotation,
1022
+ newProps: Partial<InferTypeAnnotationProps>,
1023
+ ) => DetachedNode<InferTypeAnnotation>) &
1024
+ ((
1025
+ node: ?InferTypeAnnotation,
1026
+ newProps: Partial<InferTypeAnnotationProps>,
1027
+ ) => DetachedNode<InferTypeAnnotation> | null);
936
1028
  type InterfaceDeclarationCloneSignature = ((
937
1029
  node: InterfaceDeclaration,
938
1030
  newProps: Partial<InterfaceDeclarationProps>,
@@ -1085,6 +1177,14 @@ type JSXTextCloneSignature = ((
1085
1177
  node: ?JSXText,
1086
1178
  newProps: Partial<JSXTextProps>,
1087
1179
  ) => DetachedNode<JSXText> | null);
1180
+ type KeyofTypeAnnotationCloneSignature = ((
1181
+ node: KeyofTypeAnnotation,
1182
+ newProps: Partial<KeyofTypeAnnotationProps>,
1183
+ ) => DetachedNode<KeyofTypeAnnotation>) &
1184
+ ((
1185
+ node: ?KeyofTypeAnnotation,
1186
+ newProps: Partial<KeyofTypeAnnotationProps>,
1187
+ ) => DetachedNode<KeyofTypeAnnotation> | null);
1088
1188
  type LabeledStatementCloneSignature = ((
1089
1189
  node: LabeledStatement,
1090
1190
  newProps: Partial<LabeledStatementProps>,
@@ -1237,6 +1337,14 @@ type ObjectTypeInternalSlotCloneSignature = ((
1237
1337
  node: ?ObjectTypeInternalSlot,
1238
1338
  newProps: Partial<ObjectTypeInternalSlotProps>,
1239
1339
  ) => DetachedNode<ObjectTypeInternalSlot> | null);
1340
+ type ObjectTypeMappedTypePropertyCloneSignature = ((
1341
+ node: ObjectTypeMappedTypeProperty,
1342
+ newProps: Partial<ObjectTypeMappedTypePropertyProps>,
1343
+ ) => DetachedNode<ObjectTypeMappedTypeProperty>) &
1344
+ ((
1345
+ node: ?ObjectTypeMappedTypeProperty,
1346
+ newProps: Partial<ObjectTypeMappedTypePropertyProps>,
1347
+ ) => DetachedNode<ObjectTypeMappedTypeProperty> | null);
1240
1348
  type ObjectTypePropertyCloneSignature = ((
1241
1349
  node: ObjectTypeProperty,
1242
1350
  newProps: Partial<ObjectTypePropertyProps>,
@@ -1301,6 +1409,14 @@ type QualifiedTypeIdentifierCloneSignature = ((
1301
1409
  node: ?QualifiedTypeIdentifier,
1302
1410
  newProps: Partial<QualifiedTypeIdentifierProps>,
1303
1411
  ) => DetachedNode<QualifiedTypeIdentifier> | null);
1412
+ type QualifiedTypeofIdentifierCloneSignature = ((
1413
+ node: QualifiedTypeofIdentifier,
1414
+ newProps: Partial<QualifiedTypeofIdentifierProps>,
1415
+ ) => DetachedNode<QualifiedTypeofIdentifier>) &
1416
+ ((
1417
+ node: ?QualifiedTypeofIdentifier,
1418
+ newProps: Partial<QualifiedTypeofIdentifierProps>,
1419
+ ) => DetachedNode<QualifiedTypeofIdentifier> | null);
1304
1420
  type RegExpLiteralCloneSignature = ((
1305
1421
  node: RegExpLiteral,
1306
1422
  newProps: Partial<RegExpLiteralProps>,
@@ -1458,6 +1574,22 @@ type TupleTypeAnnotationCloneSignature = ((
1458
1574
  node: ?TupleTypeAnnotation,
1459
1575
  newProps: Partial<TupleTypeAnnotationProps>,
1460
1576
  ) => DetachedNode<TupleTypeAnnotation> | null);
1577
+ type TupleTypeLabeledElementCloneSignature = ((
1578
+ node: TupleTypeLabeledElement,
1579
+ newProps: Partial<TupleTypeLabeledElementProps>,
1580
+ ) => DetachedNode<TupleTypeLabeledElement>) &
1581
+ ((
1582
+ node: ?TupleTypeLabeledElement,
1583
+ newProps: Partial<TupleTypeLabeledElementProps>,
1584
+ ) => DetachedNode<TupleTypeLabeledElement> | null);
1585
+ type TupleTypeSpreadElementCloneSignature = ((
1586
+ node: TupleTypeSpreadElement,
1587
+ newProps: Partial<TupleTypeSpreadElementProps>,
1588
+ ) => DetachedNode<TupleTypeSpreadElement>) &
1589
+ ((
1590
+ node: ?TupleTypeSpreadElement,
1591
+ newProps: Partial<TupleTypeSpreadElementProps>,
1592
+ ) => DetachedNode<TupleTypeSpreadElement> | null);
1461
1593
  type TypeAliasCloneSignature = ((
1462
1594
  node: TypeAlias,
1463
1595
  newProps: Partial<TypeAliasProps>,
@@ -1514,6 +1646,14 @@ type TypeParameterInstantiationCloneSignature = ((
1514
1646
  node: ?TypeParameterInstantiation,
1515
1647
  newProps: Partial<TypeParameterInstantiationProps>,
1516
1648
  ) => DetachedNode<TypeParameterInstantiation> | null);
1649
+ type TypePredicateCloneSignature = ((
1650
+ node: TypePredicate,
1651
+ newProps: Partial<TypePredicateProps>,
1652
+ ) => DetachedNode<TypePredicate>) &
1653
+ ((
1654
+ node: ?TypePredicate,
1655
+ newProps: Partial<TypePredicateProps>,
1656
+ ) => DetachedNode<TypePredicate> | null);
1517
1657
  type UnaryExpressionCloneSignature = ((
1518
1658
  node: UnaryExpression,
1519
1659
  newProps: Partial<UnaryExpressionProps>,
@@ -1618,11 +1758,18 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1618
1758
  ClassDeclarationCloneSignature &
1619
1759
  ClassExpressionCloneSignature &
1620
1760
  ClassImplementsCloneSignature &
1761
+ ComponentDeclarationCloneSignature &
1762
+ ComponentParameterCloneSignature &
1763
+ ComponentTypeAnnotationCloneSignature &
1764
+ ComponentTypeParameterCloneSignature &
1621
1765
  ConditionalExpressionCloneSignature &
1766
+ ConditionalTypeAnnotationCloneSignature &
1622
1767
  ContinueStatementCloneSignature &
1623
1768
  DebuggerStatementCloneSignature &
1624
1769
  DeclareClassCloneSignature &
1770
+ DeclareComponentCloneSignature &
1625
1771
  DeclaredPredicateCloneSignature &
1772
+ DeclareEnumCloneSignature &
1626
1773
  DeclareExportAllDeclarationCloneSignature &
1627
1774
  DeclareExportDeclarationCloneSignature &
1628
1775
  DeclareFunctionCloneSignature &
@@ -1668,6 +1815,7 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1668
1815
  ImportSpecifierCloneSignature &
1669
1816
  IndexedAccessTypeCloneSignature &
1670
1817
  InferredPredicateCloneSignature &
1818
+ InferTypeAnnotationCloneSignature &
1671
1819
  InterfaceDeclarationCloneSignature &
1672
1820
  InterfaceExtendsCloneSignature &
1673
1821
  InterfaceTypeAnnotationCloneSignature &
@@ -1687,6 +1835,7 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1687
1835
  JSXSpreadAttributeCloneSignature &
1688
1836
  JSXSpreadChildCloneSignature &
1689
1837
  JSXTextCloneSignature &
1838
+ KeyofTypeAnnotationCloneSignature &
1690
1839
  LabeledStatementCloneSignature &
1691
1840
  LogicalExpressionCloneSignature &
1692
1841
  MemberExpressionCloneSignature &
@@ -1706,6 +1855,7 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1706
1855
  ObjectTypeCallPropertyCloneSignature &
1707
1856
  ObjectTypeIndexerCloneSignature &
1708
1857
  ObjectTypeInternalSlotCloneSignature &
1858
+ ObjectTypeMappedTypePropertyCloneSignature &
1709
1859
  ObjectTypePropertyCloneSignature &
1710
1860
  ObjectTypeSpreadPropertyCloneSignature &
1711
1861
  OpaqueTypeCloneSignature &
@@ -1714,6 +1864,7 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1714
1864
  PropertyCloneSignature &
1715
1865
  PropertyDefinitionCloneSignature &
1716
1866
  QualifiedTypeIdentifierCloneSignature &
1867
+ QualifiedTypeofIdentifierCloneSignature &
1717
1868
  RegExpLiteralCloneSignature &
1718
1869
  RestElementCloneSignature &
1719
1870
  ReturnStatementCloneSignature &
@@ -1734,6 +1885,8 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1734
1885
  ThrowStatementCloneSignature &
1735
1886
  TryStatementCloneSignature &
1736
1887
  TupleTypeAnnotationCloneSignature &
1888
+ TupleTypeLabeledElementCloneSignature &
1889
+ TupleTypeSpreadElementCloneSignature &
1737
1890
  TypeAliasCloneSignature &
1738
1891
  TypeAnnotationCloneSignature &
1739
1892
  TypeCastExpressionCloneSignature &
@@ -1741,6 +1894,7 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1741
1894
  TypeParameterCloneSignature &
1742
1895
  TypeParameterDeclarationCloneSignature &
1743
1896
  TypeParameterInstantiationCloneSignature &
1897
+ TypePredicateCloneSignature &
1744
1898
  UnaryExpressionCloneSignature &
1745
1899
  UnionTypeAnnotationCloneSignature &
1746
1900
  UpdateExpressionCloneSignature &