hermes-transform 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,12 +33,11 @@ import type {
33
33
  BreakStatement,
34
34
  CallExpression,
35
35
  CatchClause,
36
+ ChainExpression,
36
37
  ClassBody,
37
38
  ClassDeclaration,
38
39
  ClassExpression,
39
40
  ClassImplements,
40
- ClassPrivateProperty,
41
- ClassProperty,
42
41
  ConditionalExpression,
43
42
  ContinueStatement,
44
43
  DebuggerStatement,
@@ -69,7 +68,6 @@ import type {
69
68
  ExportAllDeclaration,
70
69
  ExportDefaultDeclaration,
71
70
  ExportNamedDeclaration,
72
- ExportNamespaceSpecifier,
73
71
  ExportSpecifier,
74
72
  ExpressionStatement,
75
73
  ForInStatement,
@@ -131,11 +129,10 @@ import type {
131
129
  ObjectTypeProperty,
132
130
  ObjectTypeSpreadProperty,
133
131
  OpaqueType,
134
- OptionalCallExpression,
135
132
  OptionalIndexedAccessType,
136
- OptionalMemberExpression,
137
- PrivateName,
133
+ PrivateIdentifier,
138
134
  Property,
135
+ PropertyDefinition,
139
136
  QualifiedTypeIdentifier,
140
137
  RegExpLiteral,
141
138
  RestElement,
@@ -194,12 +191,11 @@ import type {
194
191
  BreakStatementProps,
195
192
  CallExpressionProps,
196
193
  CatchClauseProps,
194
+ ChainExpressionProps,
197
195
  ClassBodyProps,
198
196
  ClassDeclarationProps,
199
197
  ClassExpressionProps,
200
198
  ClassImplementsProps,
201
- ClassPrivatePropertyProps,
202
- ClassPropertyProps,
203
199
  ConditionalExpressionProps,
204
200
  ContinueStatementProps,
205
201
  DebuggerStatementProps,
@@ -230,7 +226,6 @@ import type {
230
226
  ExportAllDeclarationProps,
231
227
  ExportDefaultDeclarationProps,
232
228
  ExportNamedDeclarationProps,
233
- ExportNamespaceSpecifierProps,
234
229
  ExportSpecifierProps,
235
230
  ExpressionStatementProps,
236
231
  ForInStatementProps,
@@ -292,11 +287,10 @@ import type {
292
287
  ObjectTypePropertyProps,
293
288
  ObjectTypeSpreadPropertyProps,
294
289
  OpaqueTypeProps,
295
- OptionalCallExpressionProps,
296
290
  OptionalIndexedAccessTypeProps,
297
- OptionalMemberExpressionProps,
298
- PrivateNameProps,
291
+ PrivateIdentifierProps,
299
292
  PropertyProps,
293
+ PropertyDefinitionProps,
300
294
  QualifiedTypeIdentifierProps,
301
295
  RegExpLiteralProps,
302
296
  RestElementProps,
@@ -482,6 +476,14 @@ type CatchClauseCloneSignature = ((
482
476
  node: ?CatchClause,
483
477
  newProps: $Partial<CatchClauseProps>,
484
478
  ) => DetachedNode<CatchClause> | null);
479
+ type ChainExpressionCloneSignature = ((
480
+ node: ChainExpression,
481
+ newProps: $Partial<ChainExpressionProps>,
482
+ ) => DetachedNode<ChainExpression>) &
483
+ ((
484
+ node: ?ChainExpression,
485
+ newProps: $Partial<ChainExpressionProps>,
486
+ ) => DetachedNode<ChainExpression> | null);
485
487
  type ClassBodyCloneSignature = ((
486
488
  node: ClassBody,
487
489
  newProps: $Partial<ClassBodyProps>,
@@ -514,22 +516,6 @@ type ClassImplementsCloneSignature = ((
514
516
  node: ?ClassImplements,
515
517
  newProps: $Partial<ClassImplementsProps>,
516
518
  ) => DetachedNode<ClassImplements> | null);
517
- type ClassPrivatePropertyCloneSignature = ((
518
- node: ClassPrivateProperty,
519
- newProps: $Partial<ClassPrivatePropertyProps>,
520
- ) => DetachedNode<ClassPrivateProperty>) &
521
- ((
522
- node: ?ClassPrivateProperty,
523
- newProps: $Partial<ClassPrivatePropertyProps>,
524
- ) => DetachedNode<ClassPrivateProperty> | null);
525
- type ClassPropertyCloneSignature = ((
526
- node: ClassProperty,
527
- newProps: $Partial<ClassPropertyProps>,
528
- ) => DetachedNode<ClassProperty>) &
529
- ((
530
- node: ?ClassProperty,
531
- newProps: $Partial<ClassPropertyProps>,
532
- ) => DetachedNode<ClassProperty> | null);
533
519
  type ConditionalExpressionCloneSignature = ((
534
520
  node: ConditionalExpression,
535
521
  newProps: $Partial<ConditionalExpressionProps>,
@@ -770,14 +756,6 @@ type ExportNamedDeclarationCloneSignature = ((
770
756
  node: ?ExportNamedDeclaration,
771
757
  newProps: $Partial<ExportNamedDeclarationProps>,
772
758
  ) => DetachedNode<ExportNamedDeclaration> | null);
773
- type ExportNamespaceSpecifierCloneSignature = ((
774
- node: ExportNamespaceSpecifier,
775
- newProps: $Partial<ExportNamespaceSpecifierProps>,
776
- ) => DetachedNode<ExportNamespaceSpecifier>) &
777
- ((
778
- node: ?ExportNamespaceSpecifier,
779
- newProps: $Partial<ExportNamespaceSpecifierProps>,
780
- ) => DetachedNode<ExportNamespaceSpecifier> | null);
781
759
  type ExportSpecifierCloneSignature = ((
782
760
  node: ExportSpecifier,
783
761
  newProps: $Partial<ExportSpecifierProps>,
@@ -1266,14 +1244,6 @@ type OpaqueTypeCloneSignature = ((
1266
1244
  node: ?OpaqueType,
1267
1245
  newProps: $Partial<OpaqueTypeProps>,
1268
1246
  ) => DetachedNode<OpaqueType> | null);
1269
- type OptionalCallExpressionCloneSignature = ((
1270
- node: OptionalCallExpression,
1271
- newProps: $Partial<OptionalCallExpressionProps>,
1272
- ) => DetachedNode<OptionalCallExpression>) &
1273
- ((
1274
- node: ?OptionalCallExpression,
1275
- newProps: $Partial<OptionalCallExpressionProps>,
1276
- ) => DetachedNode<OptionalCallExpression> | null);
1277
1247
  type OptionalIndexedAccessTypeCloneSignature = ((
1278
1248
  node: OptionalIndexedAccessType,
1279
1249
  newProps: $Partial<OptionalIndexedAccessTypeProps>,
@@ -1282,22 +1252,14 @@ type OptionalIndexedAccessTypeCloneSignature = ((
1282
1252
  node: ?OptionalIndexedAccessType,
1283
1253
  newProps: $Partial<OptionalIndexedAccessTypeProps>,
1284
1254
  ) => DetachedNode<OptionalIndexedAccessType> | null);
1285
- type OptionalMemberExpressionCloneSignature = ((
1286
- node: OptionalMemberExpression,
1287
- newProps: $Partial<OptionalMemberExpressionProps>,
1288
- ) => DetachedNode<OptionalMemberExpression>) &
1289
- ((
1290
- node: ?OptionalMemberExpression,
1291
- newProps: $Partial<OptionalMemberExpressionProps>,
1292
- ) => DetachedNode<OptionalMemberExpression> | null);
1293
- type PrivateNameCloneSignature = ((
1294
- node: PrivateName,
1295
- newProps: $Partial<PrivateNameProps>,
1296
- ) => DetachedNode<PrivateName>) &
1297
- ((
1298
- node: ?PrivateName,
1299
- newProps: $Partial<PrivateNameProps>,
1300
- ) => DetachedNode<PrivateName> | null);
1255
+ type PrivateIdentifierCloneSignature = ((
1256
+ node: PrivateIdentifier,
1257
+ newProps: $Partial<PrivateIdentifierProps>,
1258
+ ) => DetachedNode<PrivateIdentifier>) &
1259
+ ((
1260
+ node: ?PrivateIdentifier,
1261
+ newProps: $Partial<PrivateIdentifierProps>,
1262
+ ) => DetachedNode<PrivateIdentifier> | null);
1301
1263
  type PropertyCloneSignature = ((
1302
1264
  node: Property,
1303
1265
  newProps: $Partial<PropertyProps>,
@@ -1306,6 +1268,14 @@ type PropertyCloneSignature = ((
1306
1268
  node: ?Property,
1307
1269
  newProps: $Partial<PropertyProps>,
1308
1270
  ) => DetachedNode<Property> | null);
1271
+ type PropertyDefinitionCloneSignature = ((
1272
+ node: PropertyDefinition,
1273
+ newProps: $Partial<PropertyDefinitionProps>,
1274
+ ) => DetachedNode<PropertyDefinition>) &
1275
+ ((
1276
+ node: ?PropertyDefinition,
1277
+ newProps: $Partial<PropertyDefinitionProps>,
1278
+ ) => DetachedNode<PropertyDefinition> | null);
1309
1279
  type QualifiedTypeIdentifierCloneSignature = ((
1310
1280
  node: QualifiedTypeIdentifier,
1311
1281
  newProps: $Partial<QualifiedTypeIdentifierProps>,
@@ -1628,12 +1598,11 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1628
1598
  BreakStatementCloneSignature &
1629
1599
  CallExpressionCloneSignature &
1630
1600
  CatchClauseCloneSignature &
1601
+ ChainExpressionCloneSignature &
1631
1602
  ClassBodyCloneSignature &
1632
1603
  ClassDeclarationCloneSignature &
1633
1604
  ClassExpressionCloneSignature &
1634
1605
  ClassImplementsCloneSignature &
1635
- ClassPrivatePropertyCloneSignature &
1636
- ClassPropertyCloneSignature &
1637
1606
  ConditionalExpressionCloneSignature &
1638
1607
  ContinueStatementCloneSignature &
1639
1608
  DebuggerStatementCloneSignature &
@@ -1664,7 +1633,6 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1664
1633
  ExportAllDeclarationCloneSignature &
1665
1634
  ExportDefaultDeclarationCloneSignature &
1666
1635
  ExportNamedDeclarationCloneSignature &
1667
- ExportNamespaceSpecifierCloneSignature &
1668
1636
  ExportSpecifierCloneSignature &
1669
1637
  ExpressionStatementCloneSignature &
1670
1638
  ForInStatementCloneSignature &
@@ -1726,11 +1694,10 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
1726
1694
  ObjectTypePropertyCloneSignature &
1727
1695
  ObjectTypeSpreadPropertyCloneSignature &
1728
1696
  OpaqueTypeCloneSignature &
1729
- OptionalCallExpressionCloneSignature &
1730
1697
  OptionalIndexedAccessTypeCloneSignature &
1731
- OptionalMemberExpressionCloneSignature &
1732
- PrivateNameCloneSignature &
1698
+ PrivateIdentifierCloneSignature &
1733
1699
  PropertyCloneSignature &
1700
+ PropertyDefinitionCloneSignature &
1734
1701
  QualifiedTypeIdentifierCloneSignature &
1735
1702
  RegExpLiteralCloneSignature &
1736
1703
  RestElementCloneSignature &
@@ -31,12 +31,11 @@ import type {
31
31
  BreakStatement,
32
32
  CallExpression,
33
33
  CatchClause,
34
+ ChainExpression,
34
35
  ClassBody,
35
36
  ClassDeclaration,
36
37
  ClassExpression,
37
38
  ClassImplements,
38
- ClassPrivateProperty,
39
- ClassProperty,
40
39
  ConditionalExpression,
41
40
  ContinueStatement,
42
41
  DebuggerStatement,
@@ -67,7 +66,6 @@ import type {
67
66
  ExportAllDeclaration,
68
67
  ExportDefaultDeclaration,
69
68
  ExportNamedDeclaration,
70
- ExportNamespaceSpecifier,
71
69
  ExportSpecifier,
72
70
  ExpressionStatement,
73
71
  ForInStatement,
@@ -127,12 +125,11 @@ import type {
127
125
  ObjectTypeProperty,
128
126
  ObjectTypeSpreadProperty,
129
127
  OpaqueType,
130
- OptionalCallExpression,
131
128
  OptionalIndexedAccessType,
132
- OptionalMemberExpression,
133
- PrivateName,
129
+ PrivateIdentifier,
134
130
  Program,
135
131
  Property,
132
+ PropertyDefinition,
136
133
  QualifiedTypeIdentifier,
137
134
  RestElement,
138
135
  ReturnStatement,
@@ -253,6 +250,11 @@ type CatchClauseReplaceSignature = (
253
250
  nodeToReplaceWith: DetachedNode<CatchClause>,
254
251
  options?: $ReadOnly<{keepComments?: boolean}>,
255
252
  ) => void;
253
+ type ChainExpressionReplaceSignature = (
254
+ target: ChainExpression,
255
+ nodeToReplaceWith: DetachedNode<ChainExpression>,
256
+ options?: $ReadOnly<{keepComments?: boolean}>,
257
+ ) => void;
256
258
  type ClassBodyReplaceSignature = (
257
259
  target: ClassBody,
258
260
  nodeToReplaceWith: DetachedNode<ClassBody>,
@@ -273,16 +275,6 @@ type ClassImplementsReplaceSignature = (
273
275
  nodeToReplaceWith: DetachedNode<ClassImplements>,
274
276
  options?: $ReadOnly<{keepComments?: boolean}>,
275
277
  ) => void;
276
- type ClassPrivatePropertyReplaceSignature = (
277
- target: ClassPrivateProperty,
278
- nodeToReplaceWith: DetachedNode<ClassPrivateProperty>,
279
- options?: $ReadOnly<{keepComments?: boolean}>,
280
- ) => void;
281
- type ClassPropertyReplaceSignature = (
282
- target: ClassProperty,
283
- nodeToReplaceWith: DetachedNode<ClassProperty>,
284
- options?: $ReadOnly<{keepComments?: boolean}>,
285
- ) => void;
286
278
  type ConditionalExpressionReplaceSignature = (
287
279
  target: ConditionalExpression,
288
280
  nodeToReplaceWith: DetachedNode<ConditionalExpression>,
@@ -433,11 +425,6 @@ type ExportNamedDeclarationReplaceSignature = (
433
425
  nodeToReplaceWith: DetachedNode<ExportNamedDeclaration>,
434
426
  options?: $ReadOnly<{keepComments?: boolean}>,
435
427
  ) => void;
436
- type ExportNamespaceSpecifierReplaceSignature = (
437
- target: ExportNamespaceSpecifier,
438
- nodeToReplaceWith: DetachedNode<ExportNamespaceSpecifier>,
439
- options?: $ReadOnly<{keepComments?: boolean}>,
440
- ) => void;
441
428
  type ExportSpecifierReplaceSignature = (
442
429
  target: ExportSpecifier,
443
430
  nodeToReplaceWith: DetachedNode<ExportSpecifier>,
@@ -733,24 +720,14 @@ type OpaqueTypeReplaceSignature = (
733
720
  nodeToReplaceWith: DetachedNode<OpaqueType>,
734
721
  options?: $ReadOnly<{keepComments?: boolean}>,
735
722
  ) => void;
736
- type OptionalCallExpressionReplaceSignature = (
737
- target: OptionalCallExpression,
738
- nodeToReplaceWith: DetachedNode<OptionalCallExpression>,
739
- options?: $ReadOnly<{keepComments?: boolean}>,
740
- ) => void;
741
723
  type OptionalIndexedAccessTypeReplaceSignature = (
742
724
  target: OptionalIndexedAccessType,
743
725
  nodeToReplaceWith: DetachedNode<OptionalIndexedAccessType>,
744
726
  options?: $ReadOnly<{keepComments?: boolean}>,
745
727
  ) => void;
746
- type OptionalMemberExpressionReplaceSignature = (
747
- target: OptionalMemberExpression,
748
- nodeToReplaceWith: DetachedNode<OptionalMemberExpression>,
749
- options?: $ReadOnly<{keepComments?: boolean}>,
750
- ) => void;
751
- type PrivateNameReplaceSignature = (
752
- target: PrivateName,
753
- nodeToReplaceWith: DetachedNode<PrivateName>,
728
+ type PrivateIdentifierReplaceSignature = (
729
+ target: PrivateIdentifier,
730
+ nodeToReplaceWith: DetachedNode<PrivateIdentifier>,
754
731
  options?: $ReadOnly<{keepComments?: boolean}>,
755
732
  ) => void;
756
733
  type ProgramReplaceSignature = (
@@ -763,6 +740,11 @@ type PropertyReplaceSignature = (
763
740
  nodeToReplaceWith: DetachedNode<Property>,
764
741
  options?: $ReadOnly<{keepComments?: boolean}>,
765
742
  ) => void;
743
+ type PropertyDefinitionReplaceSignature = (
744
+ target: PropertyDefinition,
745
+ nodeToReplaceWith: DetachedNode<PropertyDefinition>,
746
+ options?: $ReadOnly<{keepComments?: boolean}>,
747
+ ) => void;
766
748
  type QualifiedTypeIdentifierReplaceSignature = (
767
749
  target: QualifiedTypeIdentifier,
768
750
  nodeToReplaceWith: DetachedNode<QualifiedTypeIdentifier>,
@@ -964,12 +946,11 @@ export type TransformReplaceSignatures = AnyTypeAnnotationReplaceSignature &
964
946
  BreakStatementReplaceSignature &
965
947
  CallExpressionReplaceSignature &
966
948
  CatchClauseReplaceSignature &
949
+ ChainExpressionReplaceSignature &
967
950
  ClassBodyReplaceSignature &
968
951
  ClassDeclarationReplaceSignature &
969
952
  ClassExpressionReplaceSignature &
970
953
  ClassImplementsReplaceSignature &
971
- ClassPrivatePropertyReplaceSignature &
972
- ClassPropertyReplaceSignature &
973
954
  ConditionalExpressionReplaceSignature &
974
955
  ContinueStatementReplaceSignature &
975
956
  DebuggerStatementReplaceSignature &
@@ -1000,7 +981,6 @@ export type TransformReplaceSignatures = AnyTypeAnnotationReplaceSignature &
1000
981
  ExportAllDeclarationReplaceSignature &
1001
982
  ExportDefaultDeclarationReplaceSignature &
1002
983
  ExportNamedDeclarationReplaceSignature &
1003
- ExportNamespaceSpecifierReplaceSignature &
1004
984
  ExportSpecifierReplaceSignature &
1005
985
  ExpressionStatementReplaceSignature &
1006
986
  ForInStatementReplaceSignature &
@@ -1060,12 +1040,11 @@ export type TransformReplaceSignatures = AnyTypeAnnotationReplaceSignature &
1060
1040
  ObjectTypePropertyReplaceSignature &
1061
1041
  ObjectTypeSpreadPropertyReplaceSignature &
1062
1042
  OpaqueTypeReplaceSignature &
1063
- OptionalCallExpressionReplaceSignature &
1064
1043
  OptionalIndexedAccessTypeReplaceSignature &
1065
- OptionalMemberExpressionReplaceSignature &
1066
- PrivateNameReplaceSignature &
1044
+ PrivateIdentifierReplaceSignature &
1067
1045
  ProgramReplaceSignature &
1068
1046
  PropertyReplaceSignature &
1047
+ PropertyDefinitionReplaceSignature &
1069
1048
  QualifiedTypeIdentifierReplaceSignature &
1070
1049
  RestElementReplaceSignature &
1071
1050
  ReturnStatementReplaceSignature &
@@ -33,12 +33,11 @@ var _exportNames = {
33
33
  BreakStatement: true,
34
34
  CallExpression: true,
35
35
  CatchClause: true,
36
+ ChainExpression: true,
36
37
  ClassBody: true,
37
38
  ClassDeclaration: true,
38
39
  ClassExpression: true,
39
40
  ClassImplements: true,
40
- ClassPrivateProperty: true,
41
- ClassProperty: true,
42
41
  ConditionalExpression: true,
43
42
  ContinueStatement: true,
44
43
  DebuggerStatement: true,
@@ -69,7 +68,6 @@ var _exportNames = {
69
68
  ExportAllDeclaration: true,
70
69
  ExportDefaultDeclaration: true,
71
70
  ExportNamedDeclaration: true,
72
- ExportNamespaceSpecifier: true,
73
71
  ExportSpecifier: true,
74
72
  ExpressionStatement: true,
75
73
  ForInStatement: true,
@@ -128,11 +126,10 @@ var _exportNames = {
128
126
  ObjectTypeProperty: true,
129
127
  ObjectTypeSpreadProperty: true,
130
128
  OpaqueType: true,
131
- OptionalCallExpression: true,
132
129
  OptionalIndexedAccessType: true,
133
- OptionalMemberExpression: true,
134
- PrivateName: true,
130
+ PrivateIdentifier: true,
135
131
  Property: true,
132
+ PropertyDefinition: true,
136
133
  QualifiedTypeIdentifier: true,
137
134
  RestElement: true,
138
135
  ReturnStatement: true,
@@ -184,12 +181,11 @@ exports.BooleanTypeAnnotation = BooleanTypeAnnotation;
184
181
  exports.BreakStatement = BreakStatement;
185
182
  exports.CallExpression = CallExpression;
186
183
  exports.CatchClause = CatchClause;
184
+ exports.ChainExpression = ChainExpression;
187
185
  exports.ClassBody = ClassBody;
188
186
  exports.ClassDeclaration = ClassDeclaration;
189
187
  exports.ClassExpression = ClassExpression;
190
188
  exports.ClassImplements = ClassImplements;
191
- exports.ClassPrivateProperty = ClassPrivateProperty;
192
- exports.ClassProperty = ClassProperty;
193
189
  exports.ConditionalExpression = ConditionalExpression;
194
190
  exports.ContinueStatement = ContinueStatement;
195
191
  exports.DebuggerStatement = DebuggerStatement;
@@ -220,7 +216,6 @@ exports.ExistsTypeAnnotation = ExistsTypeAnnotation;
220
216
  exports.ExportAllDeclaration = ExportAllDeclaration;
221
217
  exports.ExportDefaultDeclaration = ExportDefaultDeclaration;
222
218
  exports.ExportNamedDeclaration = ExportNamedDeclaration;
223
- exports.ExportNamespaceSpecifier = ExportNamespaceSpecifier;
224
219
  exports.ExportSpecifier = ExportSpecifier;
225
220
  exports.ExpressionStatement = ExpressionStatement;
226
221
  exports.ForInStatement = ForInStatement;
@@ -279,11 +274,10 @@ exports.ObjectTypeInternalSlot = ObjectTypeInternalSlot;
279
274
  exports.ObjectTypeProperty = ObjectTypeProperty;
280
275
  exports.ObjectTypeSpreadProperty = ObjectTypeSpreadProperty;
281
276
  exports.OpaqueType = OpaqueType;
282
- exports.OptionalCallExpression = OptionalCallExpression;
283
277
  exports.OptionalIndexedAccessType = OptionalIndexedAccessType;
284
- exports.OptionalMemberExpression = OptionalMemberExpression;
285
- exports.PrivateName = PrivateName;
278
+ exports.PrivateIdentifier = PrivateIdentifier;
286
279
  exports.Property = Property;
280
+ exports.PropertyDefinition = PropertyDefinition;
287
281
  exports.QualifiedTypeIdentifier = QualifiedTypeIdentifier;
288
282
  exports.RestElement = RestElement;
289
283
  exports.ReturnStatement = ReturnStatement;
@@ -503,72 +497,60 @@ function CatchClause({
503
497
  return node;
504
498
  }
505
499
 
506
- function ClassBody({
500
+ function ChainExpression({
507
501
  parent,
508
502
  ...props
509
503
  }) {
510
504
  const node = (0, _detachedNode.detachedProps)(parent, {
511
- type: 'ClassBody',
505
+ type: 'ChainExpression',
512
506
  ...props
513
507
  });
514
508
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
515
509
  return node;
516
510
  }
517
511
 
518
- function ClassDeclaration({
519
- parent,
520
- ...props
521
- }) {
522
- const node = (0, _detachedNode.detachedProps)(parent, {
523
- type: 'ClassDeclaration',
524
- ...props
525
- });
526
- (0, _detachedNode.setParentPointersInDirectChildren)(node);
527
- return node;
528
- }
529
-
530
- function ClassExpression({
512
+ function ClassBody({
531
513
  parent,
532
514
  ...props
533
515
  }) {
534
516
  const node = (0, _detachedNode.detachedProps)(parent, {
535
- type: 'ClassExpression',
517
+ type: 'ClassBody',
536
518
  ...props
537
519
  });
538
520
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
539
521
  return node;
540
522
  }
541
523
 
542
- function ClassImplements({
524
+ function ClassDeclaration({
543
525
  parent,
544
526
  ...props
545
527
  }) {
546
528
  const node = (0, _detachedNode.detachedProps)(parent, {
547
- type: 'ClassImplements',
529
+ type: 'ClassDeclaration',
548
530
  ...props
549
531
  });
550
532
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
551
533
  return node;
552
534
  }
553
535
 
554
- function ClassPrivateProperty({
536
+ function ClassExpression({
555
537
  parent,
556
538
  ...props
557
539
  }) {
558
540
  const node = (0, _detachedNode.detachedProps)(parent, {
559
- type: 'ClassPrivateProperty',
541
+ type: 'ClassExpression',
560
542
  ...props
561
543
  });
562
544
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
563
545
  return node;
564
546
  }
565
547
 
566
- function ClassProperty({
548
+ function ClassImplements({
567
549
  parent,
568
550
  ...props
569
551
  }) {
570
552
  const node = (0, _detachedNode.detachedProps)(parent, {
571
- type: 'ClassProperty',
553
+ type: 'ClassImplements',
572
554
  ...props
573
555
  });
574
556
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
@@ -919,18 +901,6 @@ function ExportNamedDeclaration({
919
901
  return node;
920
902
  }
921
903
 
922
- function ExportNamespaceSpecifier({
923
- parent,
924
- ...props
925
- }) {
926
- const node = (0, _detachedNode.detachedProps)(parent, {
927
- type: 'ExportNamespaceSpecifier',
928
- ...props
929
- });
930
- (0, _detachedNode.setParentPointersInDirectChildren)(node);
931
- return node;
932
- }
933
-
934
904
  function ExportSpecifier({
935
905
  parent,
936
906
  ...props
@@ -1599,18 +1569,6 @@ function OpaqueType({
1599
1569
  return node;
1600
1570
  }
1601
1571
 
1602
- function OptionalCallExpression({
1603
- parent,
1604
- ...props
1605
- }) {
1606
- const node = (0, _detachedNode.detachedProps)(parent, {
1607
- type: 'OptionalCallExpression',
1608
- ...props
1609
- });
1610
- (0, _detachedNode.setParentPointersInDirectChildren)(node);
1611
- return node;
1612
- }
1613
-
1614
1572
  function OptionalIndexedAccessType({
1615
1573
  parent,
1616
1574
  ...props
@@ -1623,36 +1581,36 @@ function OptionalIndexedAccessType({
1623
1581
  return node;
1624
1582
  }
1625
1583
 
1626
- function OptionalMemberExpression({
1584
+ function PrivateIdentifier({
1627
1585
  parent,
1628
1586
  ...props
1629
1587
  }) {
1630
1588
  const node = (0, _detachedNode.detachedProps)(parent, {
1631
- type: 'OptionalMemberExpression',
1589
+ type: 'PrivateIdentifier',
1632
1590
  ...props
1633
1591
  });
1634
1592
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
1635
1593
  return node;
1636
1594
  }
1637
1595
 
1638
- function PrivateName({
1596
+ function Property({
1639
1597
  parent,
1640
1598
  ...props
1641
1599
  }) {
1642
1600
  const node = (0, _detachedNode.detachedProps)(parent, {
1643
- type: 'PrivateName',
1601
+ type: 'Property',
1644
1602
  ...props
1645
1603
  });
1646
1604
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
1647
1605
  return node;
1648
1606
  }
1649
1607
 
1650
- function Property({
1608
+ function PropertyDefinition({
1651
1609
  parent,
1652
1610
  ...props
1653
1611
  }) {
1654
1612
  const node = (0, _detachedNode.detachedProps)(parent, {
1655
- type: 'Property',
1613
+ type: 'PropertyDefinition',
1656
1614
  ...props
1657
1615
  });
1658
1616
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
@@ -31,12 +31,11 @@ import type {
31
31
  BreakStatement as BreakStatementType,
32
32
  CallExpression as CallExpressionType,
33
33
  CatchClause as CatchClauseType,
34
+ ChainExpression as ChainExpressionType,
34
35
  ClassBody as ClassBodyType,
35
36
  ClassDeclaration as ClassDeclarationType,
36
37
  ClassExpression as ClassExpressionType,
37
38
  ClassImplements as ClassImplementsType,
38
- ClassPrivateProperty as ClassPrivatePropertyType,
39
- ClassProperty as ClassPropertyType,
40
39
  ConditionalExpression as ConditionalExpressionType,
41
40
  ContinueStatement as ContinueStatementType,
42
41
  DebuggerStatement as DebuggerStatementType,
@@ -67,7 +66,6 @@ import type {
67
66
  ExportAllDeclaration as ExportAllDeclarationType,
68
67
  ExportDefaultDeclaration as ExportDefaultDeclarationType,
69
68
  ExportNamedDeclaration as ExportNamedDeclarationType,
70
- ExportNamespaceSpecifier as ExportNamespaceSpecifierType,
71
69
  ExportSpecifier as ExportSpecifierType,
72
70
  ExpressionStatement as ExpressionStatementType,
73
71
  ForInStatement as ForInStatementType,
@@ -126,11 +124,10 @@ import type {
126
124
  ObjectTypeProperty as ObjectTypePropertyType,
127
125
  ObjectTypeSpreadProperty as ObjectTypeSpreadPropertyType,
128
126
  OpaqueType as OpaqueTypeType,
129
- OptionalCallExpression as OptionalCallExpressionType,
130
127
  OptionalIndexedAccessType as OptionalIndexedAccessTypeType,
131
- OptionalMemberExpression as OptionalMemberExpressionType,
132
- PrivateName as PrivateNameType,
128
+ PrivateIdentifier as PrivateIdentifierType,
133
129
  Property as PropertyType,
130
+ PropertyDefinition as PropertyDefinitionType,
134
131
  QualifiedTypeIdentifier as QualifiedTypeIdentifierType,
135
132
  RestElement as RestElementType,
136
133
  ReturnStatement as ReturnStatementType,
@@ -245,6 +242,10 @@ export type CatchClauseProps = {
245
242
  +body: DetachedNode<CatchClauseType['body']>,
246
243
  };
247
244
 
245
+ export type ChainExpressionProps = {
246
+ +expression: DetachedNode<ChainExpressionType['expression']>,
247
+ };
248
+
248
249
  export type ClassBodyProps = {
249
250
  +body: $ReadOnlyArray<DetachedNode<ClassBodyType['body'][number]>>,
250
251
  };
@@ -286,27 +287,6 @@ export type ClassImplementsProps = {
286
287
  +typeParameters?: ?DetachedNode<ClassImplementsType['typeParameters']>,
287
288
  };
288
289
 
289
- export type ClassPrivatePropertyProps = {
290
- +key: DetachedNode<ClassPrivatePropertyType['key']>,
291
- +value?: ?DetachedNode<ClassPrivatePropertyType['value']>,
292
- +static: ClassPrivatePropertyType['static'],
293
- +declare: ClassPrivatePropertyType['declare'],
294
- +optional: ClassPrivatePropertyType['optional'],
295
- +variance?: ?DetachedNode<ClassPrivatePropertyType['variance']>,
296
- +typeAnnotation?: ?DetachedNode<ClassPrivatePropertyType['typeAnnotation']>,
297
- };
298
-
299
- export type ClassPropertyProps = {
300
- +key: DetachedNode<ClassPropertyType['key']>,
301
- +value?: ?DetachedNode<ClassPropertyType['value']>,
302
- +computed: ClassPropertyType['computed'],
303
- +static: ClassPropertyType['static'],
304
- +declare: ClassPropertyType['declare'],
305
- +optional: ClassPropertyType['optional'],
306
- +variance?: ?DetachedNode<ClassPropertyType['variance']>,
307
- +typeAnnotation?: ?DetachedNode<ClassPropertyType['typeAnnotation']>,
308
- };
309
-
310
290
  export type ConditionalExpressionProps = {
311
291
  +test: DetachedNode<ConditionalExpressionType['test']>,
312
292
  +alternate: DetachedNode<ConditionalExpressionType['alternate']>,
@@ -449,6 +429,7 @@ export type EnumSymbolBodyProps = {
449
429
  export type ExistsTypeAnnotationProps = {};
450
430
 
451
431
  export type ExportAllDeclarationProps = {
432
+ +exported?: ?DetachedNode<ExportAllDeclarationType['exported']>,
452
433
  +source: DetachedNode<ExportAllDeclarationType['source']>,
453
434
  +exportKind: ExportAllDeclarationType['exportKind'],
454
435
  };
@@ -466,10 +447,6 @@ export type ExportNamedDeclarationProps = {
466
447
  +exportKind: ExportNamedDeclarationType['exportKind'],
467
448
  };
468
449
 
469
- export type ExportNamespaceSpecifierProps = {
470
- +exported: DetachedNode<ExportNamespaceSpecifierType['exported']>,
471
- };
472
-
473
450
  export type ExportSpecifierProps = {
474
451
  +exported: DetachedNode<ExportSpecifierType['exported']>,
475
452
  +local: DetachedNode<ExportSpecifierType['local']>,
@@ -814,30 +791,14 @@ export type OpaqueTypeProps = {
814
791
  +supertype?: ?DetachedNode<OpaqueTypeType['supertype']>,
815
792
  };
816
793
 
817
- export type OptionalCallExpressionProps = {
818
- +callee: DetachedNode<OptionalCallExpressionType['callee']>,
819
- +typeArguments?: ?DetachedNode<OptionalCallExpressionType['typeArguments']>,
820
- +arguments: $ReadOnlyArray<
821
- DetachedNode<OptionalCallExpressionType['arguments'][number]>,
822
- >,
823
- +optional: OptionalCallExpressionType['optional'],
824
- };
825
-
826
794
  export type OptionalIndexedAccessTypeProps = {
827
795
  +objectType: DetachedNode<OptionalIndexedAccessTypeType['objectType']>,
828
796
  +indexType: DetachedNode<OptionalIndexedAccessTypeType['indexType']>,
829
797
  +optional: OptionalIndexedAccessTypeType['optional'],
830
798
  };
831
799
 
832
- export type OptionalMemberExpressionProps = {
833
- +object: DetachedNode<OptionalMemberExpressionType['object']>,
834
- +property: DetachedNode<OptionalMemberExpressionType['property']>,
835
- +computed: OptionalMemberExpressionType['computed'],
836
- +optional: OptionalMemberExpressionType['optional'],
837
- };
838
-
839
- export type PrivateNameProps = {
840
- +id: DetachedNode<PrivateNameType['id']>,
800
+ export type PrivateIdentifierProps = {
801
+ +name: PrivateIdentifierType['name'],
841
802
  };
842
803
 
843
804
  export type PropertyProps = {
@@ -849,6 +810,17 @@ export type PropertyProps = {
849
810
  +shorthand: PropertyType['shorthand'],
850
811
  };
851
812
 
813
+ export type PropertyDefinitionProps = {
814
+ +key: DetachedNode<PropertyDefinitionType['key']>,
815
+ +value?: ?DetachedNode<PropertyDefinitionType['value']>,
816
+ +computed: PropertyDefinitionType['computed'],
817
+ +static: PropertyDefinitionType['static'],
818
+ +declare: PropertyDefinitionType['declare'],
819
+ +optional: PropertyDefinitionType['optional'],
820
+ +variance?: ?DetachedNode<PropertyDefinitionType['variance']>,
821
+ +typeAnnotation?: ?DetachedNode<PropertyDefinitionType['typeAnnotation']>,
822
+ };
823
+
852
824
  export type QualifiedTypeIdentifierProps = {
853
825
  +qualification: DetachedNode<QualifiedTypeIdentifierType['qualification']>,
854
826
  +id: DetachedNode<QualifiedTypeIdentifierType['id']>,
@@ -1231,6 +1203,21 @@ export function CatchClause({
1231
1203
  return node;
1232
1204
  }
1233
1205
 
1206
+ export function ChainExpression({
1207
+ parent,
1208
+ ...props
1209
+ }: {
1210
+ ...$ReadOnly<ChainExpressionProps>,
1211
+ +parent?: ESNode,
1212
+ }): DetachedNode<ChainExpressionType> {
1213
+ const node = detachedProps<ChainExpressionType>(parent, {
1214
+ type: 'ChainExpression',
1215
+ ...props,
1216
+ });
1217
+ setParentPointersInDirectChildren(node);
1218
+ return node;
1219
+ }
1220
+
1234
1221
  export function ClassBody({
1235
1222
  parent,
1236
1223
  ...props
@@ -1291,36 +1278,6 @@ export function ClassImplements({
1291
1278
  return node;
1292
1279
  }
1293
1280
 
1294
- export function ClassPrivateProperty({
1295
- parent,
1296
- ...props
1297
- }: {
1298
- ...$ReadOnly<ClassPrivatePropertyProps>,
1299
- +parent?: ESNode,
1300
- }): DetachedNode<ClassPrivatePropertyType> {
1301
- const node = detachedProps<ClassPrivatePropertyType>(parent, {
1302
- type: 'ClassPrivateProperty',
1303
- ...props,
1304
- });
1305
- setParentPointersInDirectChildren(node);
1306
- return node;
1307
- }
1308
-
1309
- export function ClassProperty({
1310
- parent,
1311
- ...props
1312
- }: {
1313
- ...$ReadOnly<ClassPropertyProps>,
1314
- +parent?: ESNode,
1315
- }): DetachedNode<ClassPropertyType> {
1316
- const node = detachedProps<ClassPropertyType>(parent, {
1317
- type: 'ClassProperty',
1318
- ...props,
1319
- });
1320
- setParentPointersInDirectChildren(node);
1321
- return node;
1322
- }
1323
-
1324
1281
  export function ConditionalExpression({
1325
1282
  parent,
1326
1283
  ...props
@@ -1751,21 +1708,6 @@ export function ExportNamedDeclaration({
1751
1708
  return node;
1752
1709
  }
1753
1710
 
1754
- export function ExportNamespaceSpecifier({
1755
- parent,
1756
- ...props
1757
- }: {
1758
- ...$ReadOnly<ExportNamespaceSpecifierProps>,
1759
- +parent?: ESNode,
1760
- }): DetachedNode<ExportNamespaceSpecifierType> {
1761
- const node = detachedProps<ExportNamespaceSpecifierType>(parent, {
1762
- type: 'ExportNamespaceSpecifier',
1763
- ...props,
1764
- });
1765
- setParentPointersInDirectChildren(node);
1766
- return node;
1767
- }
1768
-
1769
1711
  export function ExportSpecifier({
1770
1712
  parent,
1771
1713
  ...props
@@ -2601,21 +2543,6 @@ export function OpaqueType({
2601
2543
  return node;
2602
2544
  }
2603
2545
 
2604
- export function OptionalCallExpression({
2605
- parent,
2606
- ...props
2607
- }: {
2608
- ...$ReadOnly<OptionalCallExpressionProps>,
2609
- +parent?: ESNode,
2610
- }): DetachedNode<OptionalCallExpressionType> {
2611
- const node = detachedProps<OptionalCallExpressionType>(parent, {
2612
- type: 'OptionalCallExpression',
2613
- ...props,
2614
- });
2615
- setParentPointersInDirectChildren(node);
2616
- return node;
2617
- }
2618
-
2619
2546
  export function OptionalIndexedAccessType({
2620
2547
  parent,
2621
2548
  ...props
@@ -2631,45 +2558,45 @@ export function OptionalIndexedAccessType({
2631
2558
  return node;
2632
2559
  }
2633
2560
 
2634
- export function OptionalMemberExpression({
2561
+ export function PrivateIdentifier({
2635
2562
  parent,
2636
2563
  ...props
2637
2564
  }: {
2638
- ...$ReadOnly<OptionalMemberExpressionProps>,
2565
+ ...$ReadOnly<PrivateIdentifierProps>,
2639
2566
  +parent?: ESNode,
2640
- }): DetachedNode<OptionalMemberExpressionType> {
2641
- const node = detachedProps<OptionalMemberExpressionType>(parent, {
2642
- type: 'OptionalMemberExpression',
2567
+ }): DetachedNode<PrivateIdentifierType> {
2568
+ const node = detachedProps<PrivateIdentifierType>(parent, {
2569
+ type: 'PrivateIdentifier',
2643
2570
  ...props,
2644
2571
  });
2645
2572
  setParentPointersInDirectChildren(node);
2646
2573
  return node;
2647
2574
  }
2648
2575
 
2649
- export function PrivateName({
2576
+ export function Property({
2650
2577
  parent,
2651
2578
  ...props
2652
2579
  }: {
2653
- ...$ReadOnly<PrivateNameProps>,
2580
+ ...$ReadOnly<PropertyProps>,
2654
2581
  +parent?: ESNode,
2655
- }): DetachedNode<PrivateNameType> {
2656
- const node = detachedProps<PrivateNameType>(parent, {
2657
- type: 'PrivateName',
2582
+ }): DetachedNode<PropertyType> {
2583
+ const node = detachedProps<PropertyType>(parent, {
2584
+ type: 'Property',
2658
2585
  ...props,
2659
2586
  });
2660
2587
  setParentPointersInDirectChildren(node);
2661
2588
  return node;
2662
2589
  }
2663
2590
 
2664
- export function Property({
2591
+ export function PropertyDefinition({
2665
2592
  parent,
2666
2593
  ...props
2667
2594
  }: {
2668
- ...$ReadOnly<PropertyProps>,
2595
+ ...$ReadOnly<PropertyDefinitionProps>,
2669
2596
  +parent?: ESNode,
2670
- }): DetachedNode<PropertyType> {
2671
- const node = detachedProps<PropertyType>(parent, {
2672
- type: 'Property',
2597
+ }): DetachedNode<PropertyDefinitionType> {
2598
+ const node = detachedProps<PropertyDefinitionType>(parent, {
2599
+ type: 'PropertyDefinition',
2673
2600
  ...props,
2674
2601
  });
2675
2602
  setParentPointersInDirectChildren(node);
@@ -43,6 +43,7 @@ function createInsertStatementMutation(side, target, nodesToInsert) {
43
43
  }
44
44
 
45
45
  function performInsertStatementMutation(mutationContext, mutation) {
46
+ mutationContext.assertNotDeleted(mutation.target, `Attempted to insert ${mutation.side} a deleted ${mutation.target.type} node. This likely means that you attempted to mutate around the target after it was deleted/replaced.`);
46
47
  const insertionParent = (0, _getStatementParent.getStatementParent)(mutation.target); // enforce that if we are inserting module declarations - they are being inserted in a valid location
47
48
 
48
49
  if (!(0, _isValidModuleDeclarationParent.isValidModuleDeclarationParent)(insertionParent.parent, mutation.nodesToInsert)) {
@@ -46,6 +46,11 @@ export function performInsertStatementMutation(
46
46
  mutationContext: MutationContext,
47
47
  mutation: InsertStatementMutation,
48
48
  ): ESNode {
49
+ mutationContext.assertNotDeleted(
50
+ mutation.target,
51
+ `Attempted to insert ${mutation.side} a deleted ${mutation.target.type} node. This likely means that you attempted to mutate around the target after it was deleted/replaced.`,
52
+ );
53
+
49
54
  const insertionParent = getStatementParent(mutation.target);
50
55
 
51
56
  // enforce that if we are inserting module declarations - they are being inserted in a valid location
@@ -46,8 +46,7 @@ function getRemovalParent(node) {
46
46
 
47
47
  switch (node.type) {
48
48
  // ClassMember
49
- case 'ClassProperty':
50
- case 'ClassPrivateProperty':
49
+ case 'PropertyDefinition':
51
50
  case 'MethodDefinition':
52
51
  assertParent('ClassBody');
53
52
  return 'body';
@@ -70,6 +69,14 @@ function getRemovalParent(node) {
70
69
  assertParent('FunctionTypeAnnotation');
71
70
  return 'params';
72
71
 
72
+ case 'JSXAttribute':
73
+ assertParent('JSXOpeningElement');
74
+ return 'attributes';
75
+
76
+ case 'ImportDeclaration':
77
+ assertParent('Program');
78
+ return 'body';
79
+
73
80
  case 'ObjectTypeCallProperty':
74
81
  assertParent('ObjectTypeAnnotation');
75
82
  return 'callProperties';
@@ -161,7 +168,7 @@ function getRemovalParent(node) {
161
168
  const idx = arr.indexOf(node);
162
169
 
163
170
  if (idx === -1) {
164
- throw new _Errors.InvalidRemovalError(`Could not find target in array of \`${parent.type}.${key}\`.`);
171
+ throw new _Errors.InvalidRemovalError(`Could not find target in array of \`${node.parent.type}.${key}\`.`);
165
172
  }
166
173
 
167
174
  return idx;
@@ -17,6 +17,8 @@ import type {
17
17
  EnumStringMember,
18
18
  FunctionParameter,
19
19
  FunctionTypeParam,
20
+ JSXAttribute,
21
+ ImportDeclaration,
20
22
  ObjectTypeCallProperty,
21
23
  ObjectTypeIndexer,
22
24
  ObjectTypeInternalSlot,
@@ -41,6 +43,8 @@ export type RemoveNodeMutation = $ReadOnly<{
41
43
  | EnumStringMember
42
44
  | FunctionParameter
43
45
  | FunctionTypeParam
46
+ | JSXAttribute
47
+ | ImportDeclaration
44
48
  | ObjectTypeCallProperty
45
49
  | ObjectTypeIndexer
46
50
  | ObjectTypeInternalSlot
@@ -102,8 +106,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
102
106
 
103
107
  switch (node.type) {
104
108
  // ClassMember
105
- case 'ClassProperty':
106
- case 'ClassPrivateProperty':
109
+ case 'PropertyDefinition':
107
110
  case 'MethodDefinition':
108
111
  assertParent('ClassBody');
109
112
  return 'body';
@@ -126,6 +129,14 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
126
129
  assertParent('FunctionTypeAnnotation');
127
130
  return 'params';
128
131
 
132
+ case 'JSXAttribute':
133
+ assertParent('JSXOpeningElement');
134
+ return 'attributes';
135
+
136
+ case 'ImportDeclaration':
137
+ assertParent('Program');
138
+ return 'body';
139
+
129
140
  case 'ObjectTypeCallProperty':
130
141
  assertParent('ObjectTypeAnnotation');
131
142
  return 'callProperties';
@@ -244,7 +255,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
244
255
  const idx = arr.indexOf(node);
245
256
  if (idx === -1) {
246
257
  throw new InvalidRemovalError(
247
- `Could not find target in array of \`${parent.type}.${key}\`.`,
258
+ `Could not find target in array of \`${node.parent.type}.${key}\`.`,
248
259
  );
249
260
  }
250
261
  return idx;
@@ -33,16 +33,26 @@ function transform(originalCode, visitors, prettierOptions = {}) {
33
33
 
34
34
  if (!astWasMutated) {
35
35
  return originalCode;
36
- } // prettier fully expects the parent pointers are NOT set and
37
- // certain cases can crash due to prettier infinite-looping
38
- // whilst naively traversing the parent property
39
- // https://github.com/prettier/prettier/issues/11793
40
-
36
+ }
41
37
 
42
38
  _SimpleTraverser.SimpleTraverser.traverse(ast, {
43
39
  enter(node) {
40
+ // prettier fully expects the parent pointers are NOT set and
41
+ // certain cases can crash due to prettier infinite-looping
42
+ // whilst naively traversing the parent property
43
+ // https://github.com/prettier/prettier/issues/11793
44
44
  // $FlowExpectedError[cannot-write]
45
- delete node.parent;
45
+ delete node.parent; // prettier currently relies on the AST being in the old-school, deprecated AST format for optional chaining
46
+ // so we have to apply their transform to our AST so it can actually format it.
47
+
48
+ if (node.type === 'ChainExpression') {
49
+ const newNode = transformChainExpression(node.expression); // $FlowExpectedError[cannot-write]
50
+
51
+ delete node.expression; // $FlowExpectedError[prop-missing]
52
+ // $FlowExpectedError[cannot-write]
53
+
54
+ Object.assign(node, newNode);
55
+ }
46
56
  },
47
57
 
48
58
  leave() {}
@@ -62,4 +72,26 @@ function transform(originalCode, visitors, prettierOptions = {}) {
62
72
  }
63
73
 
64
74
  });
75
+ } // https://github.com/prettier/prettier/blob/d962466a828f8ef51435e3e8840178d90b7ec6cd/src/language-js/parse/postprocess/index.js#L161-L182
76
+
77
+
78
+ function transformChainExpression(node) {
79
+ switch (node.type) {
80
+ case 'CallExpression':
81
+ // $FlowExpectedError[cannot-write]
82
+ node.type = 'OptionalCallExpression'; // $FlowExpectedError[cannot-write]
83
+
84
+ node.callee = transformChainExpression(node.callee);
85
+ break;
86
+
87
+ case 'MemberExpression':
88
+ // $FlowExpectedError[cannot-write]
89
+ node.type = 'OptionalMemberExpression'; // $FlowExpectedError[cannot-write]
90
+
91
+ node.object = transformChainExpression(node.object);
92
+ break;
93
+ // No default
94
+ }
95
+
96
+ return node;
65
97
  }
@@ -10,6 +10,7 @@
10
10
 
11
11
  'use strict';
12
12
 
13
+ import type {ESNode} from 'hermes-estree';
13
14
  import type {Visitor} from '../traverse/traverse';
14
15
  import type {TransformContextAdditions} from './TransformContext';
15
16
 
@@ -33,14 +34,25 @@ export function transform(
33
34
  return originalCode;
34
35
  }
35
36
 
36
- // prettier fully expects the parent pointers are NOT set and
37
- // certain cases can crash due to prettier infinite-looping
38
- // whilst naively traversing the parent property
39
- // https://github.com/prettier/prettier/issues/11793
40
37
  SimpleTraverser.traverse(ast, {
41
38
  enter(node) {
39
+ // prettier fully expects the parent pointers are NOT set and
40
+ // certain cases can crash due to prettier infinite-looping
41
+ // whilst naively traversing the parent property
42
+ // https://github.com/prettier/prettier/issues/11793
42
43
  // $FlowExpectedError[cannot-write]
43
44
  delete node.parent;
45
+
46
+ // prettier currently relies on the AST being in the old-school, deprecated AST format for optional chaining
47
+ // so we have to apply their transform to our AST so it can actually format it.
48
+ if (node.type === 'ChainExpression') {
49
+ const newNode = transformChainExpression(node.expression);
50
+ // $FlowExpectedError[cannot-write]
51
+ delete node.expression;
52
+ // $FlowExpectedError[prop-missing]
53
+ // $FlowExpectedError[cannot-write]
54
+ Object.assign(node, newNode);
55
+ }
44
56
  },
45
57
  leave() {},
46
58
  });
@@ -62,3 +74,25 @@ export function transform(
62
74
  },
63
75
  );
64
76
  }
77
+
78
+ // https://github.com/prettier/prettier/blob/d962466a828f8ef51435e3e8840178d90b7ec6cd/src/language-js/parse/postprocess/index.js#L161-L182
79
+ function transformChainExpression(node: ESNode) {
80
+ switch (node.type) {
81
+ case 'CallExpression':
82
+ // $FlowExpectedError[cannot-write]
83
+ node.type = 'OptionalCallExpression';
84
+ // $FlowExpectedError[cannot-write]
85
+ node.callee = transformChainExpression(node.callee);
86
+ break;
87
+
88
+ case 'MemberExpression':
89
+ // $FlowExpectedError[cannot-write]
90
+ node.type = 'OptionalMemberExpression';
91
+ // $FlowExpectedError[cannot-write]
92
+ node.object = transformChainExpression(node.object);
93
+ break;
94
+ // No default
95
+ }
96
+
97
+ return node;
98
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hermes-transform",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "description": "Tools built on top of Hermes-ESTree to enable codebase transformation",
5
5
  "main": "dist/index.js",
6
6
  "license": "MIT",
@@ -12,8 +12,8 @@
12
12
  "@babel/code-frame": "^7.16.0",
13
13
  "esquery": "^1.4.0",
14
14
  "flow-enums-runtime": "^0.0.6",
15
- "hermes-eslint": "0.7.0",
16
- "hermes-estree": "0.7.0"
15
+ "hermes-eslint": "0.8.0",
16
+ "hermes-estree": "0.8.0"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "prettier": "^2.4.1"