hermes-transform 0.5.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.
Files changed (76) hide show
  1. package/LICENSE +1 -1
  2. package/dist/detachedNode.js +25 -49
  3. package/dist/detachedNode.js.flow +3 -3
  4. package/dist/generated/TransformCloneSignatures.js.flow +1728 -9
  5. package/dist/generated/TransformReplaceSignatures.js.flow +921 -780
  6. package/dist/generated/node-types.js +1099 -1156
  7. package/dist/generated/node-types.js.flow +77 -125
  8. package/dist/generated/special-case-node-types.js +106 -85
  9. package/dist/generated/special-case-node-types.js.flow +28 -2
  10. package/dist/getVisitorKeys.js +4 -6
  11. package/dist/getVisitorKeys.js.flow +1 -1
  12. package/dist/index.js +13 -18
  13. package/dist/index.js.flow +8 -2
  14. package/dist/transform/Errors.js +8 -116
  15. package/dist/transform/Errors.js.flow +1 -1
  16. package/dist/transform/MutationContext.js +54 -67
  17. package/dist/transform/MutationContext.js.flow +4 -3
  18. package/dist/transform/TransformContext.js +100 -58
  19. package/dist/transform/TransformContext.js.flow +277 -141
  20. package/dist/transform/comments/comments.js +127 -40
  21. package/dist/transform/comments/comments.js.flow +106 -29
  22. package/dist/transform/comments/prettier/common/util.js +46 -47
  23. package/dist/transform/comments/prettier/common/util.js.flow +1 -1
  24. package/dist/transform/comments/prettier/language-js/comments.js +199 -216
  25. package/dist/transform/comments/prettier/language-js/comments.js.flow +1 -1
  26. package/dist/transform/comments/prettier/language-js/loc.js +10 -9
  27. package/dist/transform/comments/prettier/language-js/loc.js.flow +1 -1
  28. package/dist/transform/comments/prettier/language-js/printer-estree.js +7 -6
  29. package/dist/transform/comments/prettier/language-js/printer-estree.js.flow +1 -1
  30. package/dist/transform/comments/prettier/language-js/utils.js +18 -30
  31. package/dist/transform/comments/prettier/language-js/utils.js.flow +1 -1
  32. package/dist/transform/comments/prettier/main/comments.js +225 -298
  33. package/dist/transform/comments/prettier/main/comments.js.flow +1 -1
  34. package/dist/transform/comments/prettier/utils/get-last.js +2 -4
  35. package/dist/transform/comments/prettier/utils/get-last.js.flow +1 -1
  36. package/dist/transform/getTransformedAST.js +81 -104
  37. package/dist/transform/getTransformedAST.js.flow +18 -13
  38. package/dist/transform/mutations/AddComments.js +43 -0
  39. package/dist/transform/mutations/AddComments.js.flow +50 -0
  40. package/dist/transform/mutations/CloneCommentsTo.js +16 -24
  41. package/dist/transform/mutations/CloneCommentsTo.js.flow +2 -3
  42. package/dist/transform/mutations/InsertStatement.js +28 -30
  43. package/dist/transform/mutations/InsertStatement.js.flow +7 -2
  44. package/dist/transform/mutations/RemoveComment.js +25 -43
  45. package/dist/transform/mutations/RemoveComment.js.flow +1 -1
  46. package/dist/transform/mutations/RemoveNode.js +192 -0
  47. package/dist/transform/mutations/RemoveNode.js.flow +290 -0
  48. package/dist/transform/mutations/RemoveStatement.js +7 -9
  49. package/dist/transform/mutations/RemoveStatement.js.flow +1 -1
  50. package/dist/transform/mutations/ReplaceNode.js +36 -44
  51. package/dist/transform/mutations/ReplaceNode.js.flow +1 -1
  52. package/dist/transform/mutations/ReplaceStatementWithMany.js +11 -13
  53. package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +1 -1
  54. package/dist/transform/mutations/utils/arrayUtils.js +16 -14
  55. package/dist/transform/mutations/utils/arrayUtils.js.flow +16 -1
  56. package/dist/transform/mutations/utils/getStatementParent.js +23 -28
  57. package/dist/transform/mutations/utils/getStatementParent.js.flow +2 -2
  58. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +7 -24
  59. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +1 -1
  60. package/dist/transform/transform.js +58 -30
  61. package/dist/transform/transform.js.flow +51 -13
  62. package/dist/traverse/NodeEventGenerator.js +91 -165
  63. package/dist/traverse/NodeEventGenerator.js.flow +1 -1
  64. package/dist/traverse/SafeEmitter.js +20 -38
  65. package/dist/traverse/SafeEmitter.js.flow +1 -1
  66. package/dist/traverse/SimpleTraverser.js +67 -98
  67. package/dist/traverse/SimpleTraverser.js.flow +4 -1
  68. package/dist/traverse/esquery.js +6 -6
  69. package/dist/traverse/esquery.js.flow +1 -1
  70. package/dist/traverse/traverse.js +64 -52
  71. package/dist/traverse/traverse.js.flow +63 -10
  72. package/package.json +5 -3
  73. package/dist/transform/mutations/AddLeadingComments.js +0 -47
  74. package/dist/transform/mutations/AddLeadingComments.js.flow +0 -49
  75. package/dist/transform/mutations/AddTrailingComments.js +0 -47
  76. package/dist/transform/mutations/AddTrailingComments.js.flow +0 -49
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -8,6 +8,10 @@
8
8
  * @format
9
9
  */
10
10
 
11
+ // lint directives to let us do some basic validation of generated files
12
+ /* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
13
+ /* global $NonMaybeType, $Partial, $ReadOnly, $ReadOnlyArray */
14
+
11
15
  'use strict';
12
16
 
13
17
  import type {
@@ -19,6 +23,7 @@ import type {
19
23
  AssignmentExpression as AssignmentExpressionType,
20
24
  AssignmentPattern as AssignmentPatternType,
21
25
  AwaitExpression as AwaitExpressionType,
26
+ BigIntLiteralTypeAnnotation as BigIntLiteralTypeAnnotationType,
22
27
  BinaryExpression as BinaryExpressionType,
23
28
  BlockStatement as BlockStatementType,
24
29
  BooleanLiteralTypeAnnotation as BooleanLiteralTypeAnnotationType,
@@ -26,12 +31,11 @@ import type {
26
31
  BreakStatement as BreakStatementType,
27
32
  CallExpression as CallExpressionType,
28
33
  CatchClause as CatchClauseType,
34
+ ChainExpression as ChainExpressionType,
29
35
  ClassBody as ClassBodyType,
30
36
  ClassDeclaration as ClassDeclarationType,
31
37
  ClassExpression as ClassExpressionType,
32
38
  ClassImplements as ClassImplementsType,
33
- ClassPrivateProperty as ClassPrivatePropertyType,
34
- ClassProperty as ClassPropertyType,
35
39
  ConditionalExpression as ConditionalExpressionType,
36
40
  ContinueStatement as ContinueStatementType,
37
41
  DebuggerStatement as DebuggerStatementType,
@@ -62,7 +66,6 @@ import type {
62
66
  ExportAllDeclaration as ExportAllDeclarationType,
63
67
  ExportDefaultDeclaration as ExportDefaultDeclarationType,
64
68
  ExportNamedDeclaration as ExportNamedDeclarationType,
65
- ExportNamespaceSpecifier as ExportNamespaceSpecifierType,
66
69
  ExportSpecifier as ExportSpecifierType,
67
70
  ExpressionStatement as ExpressionStatementType,
68
71
  ForInStatement as ForInStatementType,
@@ -121,11 +124,10 @@ import type {
121
124
  ObjectTypeProperty as ObjectTypePropertyType,
122
125
  ObjectTypeSpreadProperty as ObjectTypeSpreadPropertyType,
123
126
  OpaqueType as OpaqueTypeType,
124
- OptionalCallExpression as OptionalCallExpressionType,
125
127
  OptionalIndexedAccessType as OptionalIndexedAccessTypeType,
126
- OptionalMemberExpression as OptionalMemberExpressionType,
127
- PrivateName as PrivateNameType,
128
+ PrivateIdentifier as PrivateIdentifierType,
128
129
  Property as PropertyType,
130
+ PropertyDefinition as PropertyDefinitionType,
129
131
  QualifiedTypeIdentifier as QualifiedTypeIdentifierType,
130
132
  RestElement as RestElementType,
131
133
  ReturnStatement as ReturnStatementType,
@@ -202,6 +204,10 @@ export type AwaitExpressionProps = {
202
204
  +argument: DetachedNode<AwaitExpressionType['argument']>,
203
205
  };
204
206
 
207
+ export type BigIntLiteralTypeAnnotationProps = {
208
+ +raw: BigIntLiteralTypeAnnotationType['raw'],
209
+ };
210
+
205
211
  export type BinaryExpressionProps = {
206
212
  +left: DetachedNode<BinaryExpressionType['left']>,
207
213
  +right: DetachedNode<BinaryExpressionType['right']>,
@@ -236,6 +242,10 @@ export type CatchClauseProps = {
236
242
  +body: DetachedNode<CatchClauseType['body']>,
237
243
  };
238
244
 
245
+ export type ChainExpressionProps = {
246
+ +expression: DetachedNode<ChainExpressionType['expression']>,
247
+ };
248
+
239
249
  export type ClassBodyProps = {
240
250
  +body: $ReadOnlyArray<DetachedNode<ClassBodyType['body'][number]>>,
241
251
  };
@@ -277,27 +287,6 @@ export type ClassImplementsProps = {
277
287
  +typeParameters?: ?DetachedNode<ClassImplementsType['typeParameters']>,
278
288
  };
279
289
 
280
- export type ClassPrivatePropertyProps = {
281
- +key: DetachedNode<ClassPrivatePropertyType['key']>,
282
- +value?: ?DetachedNode<ClassPrivatePropertyType['value']>,
283
- +static: ClassPrivatePropertyType['static'],
284
- +declare: ClassPrivatePropertyType['declare'],
285
- +optional: ClassPrivatePropertyType['optional'],
286
- +variance?: ?DetachedNode<ClassPrivatePropertyType['variance']>,
287
- +typeAnnotation?: ?DetachedNode<ClassPrivatePropertyType['typeAnnotation']>,
288
- };
289
-
290
- export type ClassPropertyProps = {
291
- +key: DetachedNode<ClassPropertyType['key']>,
292
- +value?: ?DetachedNode<ClassPropertyType['value']>,
293
- +computed: ClassPropertyType['computed'],
294
- +static: ClassPropertyType['static'],
295
- +declare: ClassPropertyType['declare'],
296
- +optional: ClassPropertyType['optional'],
297
- +variance?: ?DetachedNode<ClassPropertyType['variance']>,
298
- +typeAnnotation?: ?DetachedNode<ClassPropertyType['typeAnnotation']>,
299
- };
300
-
301
290
  export type ConditionalExpressionProps = {
302
291
  +test: DetachedNode<ConditionalExpressionType['test']>,
303
292
  +alternate: DetachedNode<ConditionalExpressionType['alternate']>,
@@ -440,6 +429,7 @@ export type EnumSymbolBodyProps = {
440
429
  export type ExistsTypeAnnotationProps = {};
441
430
 
442
431
  export type ExportAllDeclarationProps = {
432
+ +exported?: ?DetachedNode<ExportAllDeclarationType['exported']>,
443
433
  +source: DetachedNode<ExportAllDeclarationType['source']>,
444
434
  +exportKind: ExportAllDeclarationType['exportKind'],
445
435
  };
@@ -457,10 +447,6 @@ export type ExportNamedDeclarationProps = {
457
447
  +exportKind: ExportNamedDeclarationType['exportKind'],
458
448
  };
459
449
 
460
- export type ExportNamespaceSpecifierProps = {
461
- +exported: DetachedNode<ExportNamespaceSpecifierType['exported']>,
462
- };
463
-
464
450
  export type ExportSpecifierProps = {
465
451
  +exported: DetachedNode<ExportSpecifierType['exported']>,
466
452
  +local: DetachedNode<ExportSpecifierType['local']>,
@@ -805,30 +791,14 @@ export type OpaqueTypeProps = {
805
791
  +supertype?: ?DetachedNode<OpaqueTypeType['supertype']>,
806
792
  };
807
793
 
808
- export type OptionalCallExpressionProps = {
809
- +callee: DetachedNode<OptionalCallExpressionType['callee']>,
810
- +typeArguments?: ?DetachedNode<OptionalCallExpressionType['typeArguments']>,
811
- +arguments: $ReadOnlyArray<
812
- DetachedNode<OptionalCallExpressionType['arguments'][number]>,
813
- >,
814
- +optional: OptionalCallExpressionType['optional'],
815
- };
816
-
817
794
  export type OptionalIndexedAccessTypeProps = {
818
795
  +objectType: DetachedNode<OptionalIndexedAccessTypeType['objectType']>,
819
796
  +indexType: DetachedNode<OptionalIndexedAccessTypeType['indexType']>,
820
797
  +optional: OptionalIndexedAccessTypeType['optional'],
821
798
  };
822
799
 
823
- export type OptionalMemberExpressionProps = {
824
- +object: DetachedNode<OptionalMemberExpressionType['object']>,
825
- +property: DetachedNode<OptionalMemberExpressionType['property']>,
826
- +computed: OptionalMemberExpressionType['computed'],
827
- +optional: OptionalMemberExpressionType['optional'],
828
- };
829
-
830
- export type PrivateNameProps = {
831
- +id: DetachedNode<PrivateNameType['id']>,
800
+ export type PrivateIdentifierProps = {
801
+ +name: PrivateIdentifierType['name'],
832
802
  };
833
803
 
834
804
  export type PropertyProps = {
@@ -840,6 +810,17 @@ export type PropertyProps = {
840
810
  +shorthand: PropertyType['shorthand'],
841
811
  };
842
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
+
843
824
  export type QualifiedTypeIdentifierProps = {
844
825
  +qualification: DetachedNode<QualifiedTypeIdentifierType['qualification']>,
845
826
  +id: DetachedNode<QualifiedTypeIdentifierType['id']>,
@@ -865,6 +846,7 @@ export type SpreadElementProps = {
865
846
 
866
847
  export type StringLiteralTypeAnnotationProps = {
867
848
  +value: StringLiteralTypeAnnotationType['value'],
849
+ +raw: StringLiteralTypeAnnotationType['raw'],
868
850
  };
869
851
 
870
852
  export type StringTypeAnnotationProps = {};
@@ -1106,6 +1088,21 @@ export function AwaitExpression({
1106
1088
  return node;
1107
1089
  }
1108
1090
 
1091
+ export function BigIntLiteralTypeAnnotation({
1092
+ parent,
1093
+ ...props
1094
+ }: {
1095
+ ...$ReadOnly<BigIntLiteralTypeAnnotationProps>,
1096
+ +parent?: ESNode,
1097
+ }): DetachedNode<BigIntLiteralTypeAnnotationType> {
1098
+ const node = detachedProps<BigIntLiteralTypeAnnotationType>(parent, {
1099
+ type: 'BigIntLiteralTypeAnnotation',
1100
+ ...props,
1101
+ });
1102
+ setParentPointersInDirectChildren(node);
1103
+ return node;
1104
+ }
1105
+
1109
1106
  export function BinaryExpression({
1110
1107
  parent,
1111
1108
  ...props
@@ -1206,6 +1203,21 @@ export function CatchClause({
1206
1203
  return node;
1207
1204
  }
1208
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
+
1209
1221
  export function ClassBody({
1210
1222
  parent,
1211
1223
  ...props
@@ -1266,36 +1278,6 @@ export function ClassImplements({
1266
1278
  return node;
1267
1279
  }
1268
1280
 
1269
- export function ClassPrivateProperty({
1270
- parent,
1271
- ...props
1272
- }: {
1273
- ...$ReadOnly<ClassPrivatePropertyProps>,
1274
- +parent?: ESNode,
1275
- }): DetachedNode<ClassPrivatePropertyType> {
1276
- const node = detachedProps<ClassPrivatePropertyType>(parent, {
1277
- type: 'ClassPrivateProperty',
1278
- ...props,
1279
- });
1280
- setParentPointersInDirectChildren(node);
1281
- return node;
1282
- }
1283
-
1284
- export function ClassProperty({
1285
- parent,
1286
- ...props
1287
- }: {
1288
- ...$ReadOnly<ClassPropertyProps>,
1289
- +parent?: ESNode,
1290
- }): DetachedNode<ClassPropertyType> {
1291
- const node = detachedProps<ClassPropertyType>(parent, {
1292
- type: 'ClassProperty',
1293
- ...props,
1294
- });
1295
- setParentPointersInDirectChildren(node);
1296
- return node;
1297
- }
1298
-
1299
1281
  export function ConditionalExpression({
1300
1282
  parent,
1301
1283
  ...props
@@ -1726,21 +1708,6 @@ export function ExportNamedDeclaration({
1726
1708
  return node;
1727
1709
  }
1728
1710
 
1729
- export function ExportNamespaceSpecifier({
1730
- parent,
1731
- ...props
1732
- }: {
1733
- ...$ReadOnly<ExportNamespaceSpecifierProps>,
1734
- +parent?: ESNode,
1735
- }): DetachedNode<ExportNamespaceSpecifierType> {
1736
- const node = detachedProps<ExportNamespaceSpecifierType>(parent, {
1737
- type: 'ExportNamespaceSpecifier',
1738
- ...props,
1739
- });
1740
- setParentPointersInDirectChildren(node);
1741
- return node;
1742
- }
1743
-
1744
1711
  export function ExportSpecifier({
1745
1712
  parent,
1746
1713
  ...props
@@ -2576,21 +2543,6 @@ export function OpaqueType({
2576
2543
  return node;
2577
2544
  }
2578
2545
 
2579
- export function OptionalCallExpression({
2580
- parent,
2581
- ...props
2582
- }: {
2583
- ...$ReadOnly<OptionalCallExpressionProps>,
2584
- +parent?: ESNode,
2585
- }): DetachedNode<OptionalCallExpressionType> {
2586
- const node = detachedProps<OptionalCallExpressionType>(parent, {
2587
- type: 'OptionalCallExpression',
2588
- ...props,
2589
- });
2590
- setParentPointersInDirectChildren(node);
2591
- return node;
2592
- }
2593
-
2594
2546
  export function OptionalIndexedAccessType({
2595
2547
  parent,
2596
2548
  ...props
@@ -2606,45 +2558,45 @@ export function OptionalIndexedAccessType({
2606
2558
  return node;
2607
2559
  }
2608
2560
 
2609
- export function OptionalMemberExpression({
2561
+ export function PrivateIdentifier({
2610
2562
  parent,
2611
2563
  ...props
2612
2564
  }: {
2613
- ...$ReadOnly<OptionalMemberExpressionProps>,
2565
+ ...$ReadOnly<PrivateIdentifierProps>,
2614
2566
  +parent?: ESNode,
2615
- }): DetachedNode<OptionalMemberExpressionType> {
2616
- const node = detachedProps<OptionalMemberExpressionType>(parent, {
2617
- type: 'OptionalMemberExpression',
2567
+ }): DetachedNode<PrivateIdentifierType> {
2568
+ const node = detachedProps<PrivateIdentifierType>(parent, {
2569
+ type: 'PrivateIdentifier',
2618
2570
  ...props,
2619
2571
  });
2620
2572
  setParentPointersInDirectChildren(node);
2621
2573
  return node;
2622
2574
  }
2623
2575
 
2624
- export function PrivateName({
2576
+ export function Property({
2625
2577
  parent,
2626
2578
  ...props
2627
2579
  }: {
2628
- ...$ReadOnly<PrivateNameProps>,
2580
+ ...$ReadOnly<PropertyProps>,
2629
2581
  +parent?: ESNode,
2630
- }): DetachedNode<PrivateNameType> {
2631
- const node = detachedProps<PrivateNameType>(parent, {
2632
- type: 'PrivateName',
2582
+ }): DetachedNode<PropertyType> {
2583
+ const node = detachedProps<PropertyType>(parent, {
2584
+ type: 'Property',
2633
2585
  ...props,
2634
2586
  });
2635
2587
  setParentPointersInDirectChildren(node);
2636
2588
  return node;
2637
2589
  }
2638
2590
 
2639
- export function Property({
2591
+ export function PropertyDefinition({
2640
2592
  parent,
2641
2593
  ...props
2642
2594
  }: {
2643
- ...$ReadOnly<PropertyProps>,
2595
+ ...$ReadOnly<PropertyDefinitionProps>,
2644
2596
  +parent?: ESNode,
2645
- }): DetachedNode<PropertyType> {
2646
- const node = detachedProps<PropertyType>(parent, {
2647
- type: 'Property',
2597
+ }): DetachedNode<PropertyDefinitionType> {
2598
+ const node = detachedProps<PropertyDefinitionType>(parent, {
2599
+ type: 'PropertyDefinition',
2648
2600
  ...props,
2649
2601
  });
2650
2602
  setParentPointersInDirectChildren(node);
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ArrowFunctionExpression = ArrowFunctionExpression;
7
+ exports.BigIntLiteral = BigIntLiteral;
7
8
  exports.BlockComment = BlockComment;
8
9
  exports.BooleanLiteral = BooleanLiteral;
9
10
  exports.Identifier = Identifier;
@@ -16,81 +17,82 @@ exports.TemplateElement = TemplateElement;
16
17
 
17
18
  var _detachedNode = require("../detachedNode");
18
19
 
19
- var _excluded = ["parent"],
20
- _excluded2 = ["tail", "parent"],
21
- _excluded3 = ["parent", "optional", "typeAnnotation"],
22
- _excluded4 = ["parent"];
23
-
24
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
25
-
26
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
27
-
28
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
-
30
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
31
-
32
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
33
-
34
- function ArrowFunctionExpression(_ref) {
35
- var parent = _ref.parent,
36
- props = _objectWithoutProperties(_ref, _excluded);
37
-
38
- var node = (0, _detachedNode.detachedProps)(parent, _objectSpread({
20
+ /**
21
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
22
+ *
23
+ * This source code is licensed under the MIT license found in the
24
+ * LICENSE file in the root directory of this source tree.
25
+ *
26
+ *
27
+ * @format
28
+ */
29
+
30
+ /*
31
+ These are a number of special-case node creation functions that we can't auto-generate.
32
+ The list of exported functions here must be kept in sync with the `NODES_WITH_SPECIAL_HANDLING`
33
+ list in `scripts/genTransformNodeTypes` to ensure there's no duplicates
34
+ */
35
+ function ArrowFunctionExpression({
36
+ parent,
37
+ ...props
38
+ }) {
39
+ const node = (0, _detachedNode.detachedProps)(parent, {
39
40
  type: 'ArrowFunctionExpression',
40
41
  id: null,
41
42
  // $FlowExpectedError[incompatible-use]
42
- expression: props.body.type !== 'BlockStatement'
43
- }, props));
43
+ expression: props.body.type !== 'BlockStatement',
44
+ ...props
45
+ });
44
46
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
45
47
  return node;
46
48
  } // pattern/flags are on a subobject in the estree spec, but are flat on the hermes types
47
49
  // also the value is supposed to be a RegExp instance
48
50
 
49
51
 
50
- function RegExpLiteral(_ref2) {
51
- var pattern = _ref2.pattern,
52
- flags = _ref2.flags,
53
- parent = _ref2.parent;
54
- var value = new RegExp(pattern, flags);
52
+ function RegExpLiteral({
53
+ pattern,
54
+ flags,
55
+ parent
56
+ }) {
57
+ const value = new RegExp(pattern, flags);
55
58
  return (0, _detachedNode.detachedProps)(parent, {
56
59
  type: 'Literal',
57
- value: value,
60
+ value,
58
61
  raw: value.toString(),
59
62
  regex: {
60
- pattern: pattern,
61
- flags: flags
63
+ pattern,
64
+ flags
62
65
  }
63
66
  });
64
67
  } // raw/cooked are on a subobject in the estree spec, but are flat on the hermes types
65
68
 
66
69
 
67
- function TemplateElement(_ref3) {
68
- var tail = _ref3.tail,
69
- parent = _ref3.parent,
70
- value = _objectWithoutProperties(_ref3, _excluded2);
71
-
70
+ function TemplateElement({
71
+ tail,
72
+ parent,
73
+ ...value
74
+ }) {
72
75
  return (0, _detachedNode.detachedProps)(parent, {
73
76
  type: 'TemplateElement',
74
- tail: tail,
75
- value: value
77
+ tail,
78
+ value
76
79
  });
77
80
  } // Identifier has a bunch of stuff that usually you don't want to provide - so we have
78
81
  // this manual def to allow us to default some values
79
82
 
80
83
 
81
- function Identifier(_ref4) {
82
- var parent = _ref4.parent,
83
- _ref4$optional = _ref4.optional,
84
- optional = _ref4$optional === void 0 ? false : _ref4$optional,
85
- _ref4$typeAnnotation = _ref4.typeAnnotation,
86
- typeAnnotation = _ref4$typeAnnotation === void 0 ? null : _ref4$typeAnnotation,
87
- props = _objectWithoutProperties(_ref4, _excluded3);
88
-
89
- var node = (0, _detachedNode.detachedProps)(parent, _objectSpread({
84
+ function Identifier({
85
+ parent,
86
+ optional = false,
87
+ typeAnnotation = null,
88
+ ...props
89
+ }) {
90
+ const node = (0, _detachedNode.detachedProps)(parent, {
90
91
  type: 'Identifier',
91
- optional: optional,
92
- typeAnnotation: typeAnnotation
93
- }, props));
92
+ optional,
93
+ typeAnnotation,
94
+ ...props
95
+ });
94
96
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
95
97
  return node;
96
98
  } //
@@ -98,33 +100,49 @@ function Identifier(_ref4) {
98
100
  //
99
101
 
100
102
 
101
- function BooleanLiteral(_ref5) {
102
- var parent = _ref5.parent,
103
- value = _ref5.value;
103
+ function BigIntLiteral({
104
+ parent,
105
+ ...props
106
+ }) {
107
+ var _props$raw;
108
+
109
+ const node = (0, _detachedNode.detachedProps)(parent, {
110
+ type: 'Literal',
111
+ ...props,
112
+ raw: (_props$raw = props.raw) != null ? _props$raw : `${props.value}n`,
113
+ bigint: `${props.value}`
114
+ });
115
+ (0, _detachedNode.setParentPointersInDirectChildren)(node);
116
+ return node;
117
+ }
118
+
119
+ function BooleanLiteral({
120
+ parent,
121
+ value
122
+ }) {
104
123
  return (0, _detachedNode.detachedProps)(parent, {
105
124
  type: 'Literal',
106
125
  raw: value ? 'true' : 'false',
107
- value: value
126
+ value
108
127
  });
109
128
  }
110
129
 
111
- function NumericLiteral(_ref6) {
112
- var _props$raw;
113
-
114
- var parent = _ref6.parent,
115
- props = _objectWithoutProperties(_ref6, _excluded4);
130
+ function NumericLiteral({
131
+ parent,
132
+ ...props
133
+ }) {
134
+ var _props$raw2;
116
135
 
117
- return (0, _detachedNode.detachedProps)(parent, _objectSpread(_objectSpread({
118
- type: 'Literal'
119
- }, props), {}, {
120
- raw: (_props$raw = props.raw) !== null && _props$raw !== void 0 ? _props$raw : "".concat(props.value)
121
- }));
136
+ return (0, _detachedNode.detachedProps)(parent, {
137
+ type: 'Literal',
138
+ ...props,
139
+ raw: (_props$raw2 = props.raw) != null ? _props$raw2 : `${props.value}`
140
+ });
122
141
  }
123
142
 
124
- function NullLiteral() {
125
- var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
126
- parent = _ref7.parent;
127
-
143
+ function NullLiteral({
144
+ parent
145
+ } = {}) {
128
146
  return (0, _detachedNode.detachedProps)(parent, {
129
147
  type: 'Literal',
130
148
  value: null,
@@ -132,47 +150,50 @@ function NullLiteral() {
132
150
  });
133
151
  }
134
152
 
135
- function StringLiteral(_ref8) {
136
- var parent = _ref8.parent,
137
- rawIn = _ref8.raw,
138
- value = _ref8.value;
139
- var hasSingleQuote = value.includes('"');
140
- var hasDoubleQuote = value.includes("'");
141
- var raw = rawIn;
153
+ function StringLiteral({
154
+ parent,
155
+ raw: rawIn,
156
+ value
157
+ }) {
158
+ const hasSingleQuote = value.includes('"');
159
+ const hasDoubleQuote = value.includes("'");
160
+ let raw = rawIn;
142
161
 
143
162
  if (raw == null) {
144
163
  if (hasSingleQuote && hasDoubleQuote) {
145
- raw = "'".concat(value.replace(/'/g, "\\'"), "'");
164
+ raw = `'${value.replace(/'/g, "\\'")}'`;
146
165
  } else if (hasSingleQuote) {
147
- raw = "\"".concat(value, "\"");
166
+ raw = `"${value}"`;
148
167
  } else {
149
- raw = "'".concat(value, "'");
168
+ raw = `'${value}'`;
150
169
  }
151
170
  }
152
171
 
153
172
  return (0, _detachedNode.detachedProps)(parent, {
154
173
  type: 'Literal',
155
- raw: raw,
156
- value: value
174
+ raw,
175
+ value
157
176
  });
158
177
  }
159
178
 
160
- function LineComment(_ref9) {
161
- var value = _ref9.value;
179
+ function LineComment({
180
+ value
181
+ }) {
162
182
  // $FlowExpectedError[prop-missing]
163
183
  // $FlowExpectedError[incompatible-return]
164
184
  return (0, _detachedNode.detachedProps)(undefined, {
165
185
  type: 'Line',
166
- value: value
186
+ value
167
187
  });
168
188
  }
169
189
 
170
- function BlockComment(_ref10) {
171
- var value = _ref10.value;
190
+ function BlockComment({
191
+ value
192
+ }) {
172
193
  // $FlowExpectedError[prop-missing]
173
194
  // $FlowExpectedError[incompatible-return]
174
195
  return (0, _detachedNode.detachedProps)(undefined, {
175
196
  type: 'Block',
176
- value: value
197
+ value
177
198
  });
178
199
  }