hermes-transform 0.36.1 → 0.37.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 (115) hide show
  1. package/dist/detachedNode.js +3 -57
  2. package/dist/detachedNode.js.flow +12 -12
  3. package/dist/generated/TransformCloneSignatures.js.flow +1 -1
  4. package/dist/generated/TransformModifySignatures.js.flow +1 -1
  5. package/dist/generated/TransformReplaceSignatures.js.flow +207 -207
  6. package/dist/generated/node-types.js +0 -21
  7. package/dist/generated/node-types.js.flow +1086 -978
  8. package/dist/generated/special-case-node-types/Comment.js +0 -13
  9. package/dist/generated/special-case-node-types/Comment.js.flow +2 -2
  10. package/dist/generated/special-case-node-types/DeclareExportDeclaration.js +0 -12
  11. package/dist/generated/special-case-node-types/DeclareExportDeclaration.js.flow +10 -10
  12. package/dist/generated/special-case-node-types/DeclareHook.js +0 -9
  13. package/dist/generated/special-case-node-types/DeclareHook.js.flow +4 -4
  14. package/dist/generated/special-case-node-types/ExportNamedDeclaration.js +0 -11
  15. package/dist/generated/special-case-node-types/ExportNamedDeclaration.js.flow +9 -9
  16. package/dist/generated/special-case-node-types/Literal.js +1 -12
  17. package/dist/generated/special-case-node-types/Literal.js.flow +20 -20
  18. package/dist/generated/special-case-node-types/ObjectTypeProperty.js +0 -10
  19. package/dist/generated/special-case-node-types/ObjectTypeProperty.js.flow +23 -21
  20. package/dist/generated/special-case-node-types/Property.js +0 -9
  21. package/dist/generated/special-case-node-types/Property.js.flow +50 -42
  22. package/dist/generated/special-case-node-types/misc.js +6 -35
  23. package/dist/generated/special-case-node-types/misc.js.flow +56 -48
  24. package/dist/index.js +0 -9
  25. package/dist/src/detachedNode.js +3 -57
  26. package/dist/src/generated/node-types.js +0 -21
  27. package/dist/src/generated/special-case-node-types/Comment.js +0 -13
  28. package/dist/src/generated/special-case-node-types/DeclareExportDeclaration.js +0 -12
  29. package/dist/src/generated/special-case-node-types/DeclareHook.js +0 -9
  30. package/dist/src/generated/special-case-node-types/ExportNamedDeclaration.js +0 -11
  31. package/dist/src/generated/special-case-node-types/Literal.js +1 -12
  32. package/dist/src/generated/special-case-node-types/ObjectTypeProperty.js +0 -10
  33. package/dist/src/generated/special-case-node-types/Property.js +0 -9
  34. package/dist/src/generated/special-case-node-types/misc.js +6 -35
  35. package/dist/src/index.js +0 -9
  36. package/dist/src/transform/Errors.js +0 -9
  37. package/dist/src/transform/MutationContext.js +1 -28
  38. package/dist/src/transform/TransformContext.js +0 -18
  39. package/dist/src/transform/comments/comments.js +12 -78
  40. package/dist/src/transform/comments/prettier/common/util.js +4 -133
  41. package/dist/src/transform/comments/prettier/language-js/comments.js +12 -137
  42. package/dist/src/transform/comments/prettier/language-js/loc.js +1 -13
  43. package/dist/src/transform/comments/prettier/language-js/printer-estree.js +1 -10
  44. package/dist/src/transform/comments/prettier/language-js/utils.js +3 -33
  45. package/dist/src/transform/comments/prettier/main/comments.js +11 -77
  46. package/dist/src/transform/comments/prettier/utils/get-last.js +0 -8
  47. package/dist/src/transform/mutations/AddComments.js +0 -9
  48. package/dist/src/transform/mutations/CloneCommentsTo.js +0 -9
  49. package/dist/src/transform/mutations/InsertStatement.js +4 -16
  50. package/dist/src/transform/mutations/ModifyNodeInPlace.js +4 -17
  51. package/dist/src/transform/mutations/RemoveComment.js +0 -10
  52. package/dist/src/transform/mutations/RemoveNode.js +1 -23
  53. package/dist/src/transform/mutations/RemoveStatement.js +0 -16
  54. package/dist/src/transform/mutations/ReplaceNode.js +2 -16
  55. package/dist/src/transform/mutations/ReplaceStatementWithMany.js +2 -14
  56. package/dist/src/transform/mutations/utils/getStatementParent.js +3 -19
  57. package/dist/src/transform/mutations/utils/isValidModuleDeclarationParent.js +5 -20
  58. package/dist/src/transform/parse.js +6 -25
  59. package/dist/src/transform/print.js +9 -35
  60. package/dist/src/transform/transform.js +0 -9
  61. package/dist/src/transform/transformAST.js +3 -31
  62. package/dist/src/traverse/NodeEventGenerator.js +2 -108
  63. package/dist/src/traverse/SafeEmitter.js +0 -19
  64. package/dist/src/traverse/esquery.js +0 -18
  65. package/dist/src/traverse/traverse.js +1 -22
  66. package/dist/transform/Errors.js +0 -9
  67. package/dist/transform/MutationContext.js +1 -28
  68. package/dist/transform/MutationContext.js.flow +3 -3
  69. package/dist/transform/TransformContext.js +0 -18
  70. package/dist/transform/TransformContext.js.flow +60 -54
  71. package/dist/transform/comments/comments.js +12 -78
  72. package/dist/transform/comments/comments.js.flow +8 -8
  73. package/dist/transform/comments/prettier/common/util.js +4 -133
  74. package/dist/transform/comments/prettier/language-js/comments.js +12 -137
  75. package/dist/transform/comments/prettier/language-js/loc.js +1 -13
  76. package/dist/transform/comments/prettier/language-js/printer-estree.js +1 -10
  77. package/dist/transform/comments/prettier/language-js/utils.js +3 -33
  78. package/dist/transform/comments/prettier/main/comments.js +11 -77
  79. package/dist/transform/comments/prettier/utils/get-last.js +0 -8
  80. package/dist/transform/mutations/AddComments.js +0 -9
  81. package/dist/transform/mutations/AddComments.js.flow +2 -2
  82. package/dist/transform/mutations/CloneCommentsTo.js +0 -9
  83. package/dist/transform/mutations/CloneCommentsTo.js.flow +1 -1
  84. package/dist/transform/mutations/InsertStatement.js +4 -16
  85. package/dist/transform/mutations/InsertStatement.js.flow +7 -6
  86. package/dist/transform/mutations/ModifyNodeInPlace.js +4 -17
  87. package/dist/transform/mutations/ModifyNodeInPlace.js.flow +2 -2
  88. package/dist/transform/mutations/RemoveComment.js +0 -10
  89. package/dist/transform/mutations/RemoveComment.js.flow +4 -4
  90. package/dist/transform/mutations/RemoveNode.js +1 -23
  91. package/dist/transform/mutations/RemoveNode.js.flow +9 -9
  92. package/dist/transform/mutations/RemoveStatement.js +0 -16
  93. package/dist/transform/mutations/RemoveStatement.js.flow +3 -3
  94. package/dist/transform/mutations/ReplaceNode.js +2 -16
  95. package/dist/transform/mutations/ReplaceNode.js.flow +6 -6
  96. package/dist/transform/mutations/ReplaceStatementWithMany.js +2 -14
  97. package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +7 -8
  98. package/dist/transform/mutations/utils/getStatementParent.js +3 -19
  99. package/dist/transform/mutations/utils/getStatementParent.js.flow +5 -6
  100. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +5 -20
  101. package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +4 -3
  102. package/dist/transform/parse.js +6 -25
  103. package/dist/transform/print.js +9 -35
  104. package/dist/transform/print.js.flow +7 -15
  105. package/dist/transform/transform.js +0 -9
  106. package/dist/transform/transformAST.js +3 -31
  107. package/dist/traverse/NodeEventGenerator.js +2 -108
  108. package/dist/traverse/NodeEventGenerator.js.flow +13 -9
  109. package/dist/traverse/SafeEmitter.js +0 -19
  110. package/dist/traverse/SafeEmitter.js.flow +2 -2
  111. package/dist/traverse/esquery.js +0 -18
  112. package/dist/traverse/esquery.js.flow +10 -10
  113. package/dist/traverse/traverse.js +1 -22
  114. package/dist/traverse/traverse.js.flow +4 -4
  115. package/package.json +7 -12
@@ -28,14 +28,14 @@ import {
28
28
  } from '../../detachedNode';
29
29
 
30
30
  export type DestructuringObjectPropertyProps = {
31
- +key: MaybeDetachedNode<DestructuringObjectPropertyType['key']>,
32
- +value: MaybeDetachedNode<DestructuringObjectPropertyType['value']>,
33
- +computed: DestructuringObjectPropertyType['computed'],
34
- +shorthand: DestructuringObjectPropertyType['shorthand'],
31
+ readonly key: MaybeDetachedNode<DestructuringObjectPropertyType['key']>,
32
+ readonly value: MaybeDetachedNode<DestructuringObjectPropertyType['value']>,
33
+ readonly computed: DestructuringObjectPropertyType['computed'],
34
+ readonly shorthand: DestructuringObjectPropertyType['shorthand'],
35
35
  };
36
36
  export function DestructuringObjectProperty(props: {
37
- ...$ReadOnly<DestructuringObjectPropertyProps>,
38
- +parent?: ESNode,
37
+ ...Readonly<DestructuringObjectPropertyProps>,
38
+ readonly parent?: ESNode,
39
39
  }): DetachedNode<DestructuringObjectPropertyType> {
40
40
  const node = detachedProps<DestructuringObjectPropertyType>(props.parent, {
41
41
  type: 'Property',
@@ -51,16 +51,16 @@ export function DestructuringObjectProperty(props: {
51
51
  }
52
52
 
53
53
  export type DestructuringObjectPropertyWithNonShorthandStaticNameProps = {
54
- +key: MaybeDetachedNode<
54
+ readonly key: MaybeDetachedNode<
55
55
  DestructuringObjectPropertyWithNonShorthandStaticNameType['key'],
56
56
  >,
57
- +value: MaybeDetachedNode<
57
+ readonly value: MaybeDetachedNode<
58
58
  DestructuringObjectPropertyWithNonShorthandStaticNameType['value'],
59
59
  >,
60
60
  };
61
61
  export function DestructuringObjectPropertyWithNonShorthandStaticName(props: {
62
- ...$ReadOnly<DestructuringObjectPropertyWithNonShorthandStaticNameProps>,
63
- +parent?: ESNode,
62
+ ...Readonly<DestructuringObjectPropertyWithNonShorthandStaticNameProps>,
63
+ readonly parent?: ESNode,
64
64
  }): DetachedNode<DestructuringObjectPropertyWithNonShorthandStaticNameType> {
65
65
  const node =
66
66
  detachedProps<DestructuringObjectPropertyWithNonShorthandStaticNameType>(
@@ -80,16 +80,16 @@ export function DestructuringObjectPropertyWithNonShorthandStaticName(props: {
80
80
  }
81
81
 
82
82
  export type DestructuringObjectPropertyWithShorthandStaticNameProps = {
83
- +key: MaybeDetachedNode<
83
+ readonly key: MaybeDetachedNode<
84
84
  DestructuringObjectPropertyWithShorthandStaticNameType['key'],
85
85
  >,
86
- +value: MaybeDetachedNode<
86
+ readonly value: MaybeDetachedNode<
87
87
  DestructuringObjectPropertyWithShorthandStaticNameType['value'],
88
88
  >,
89
89
  };
90
90
  export function DestructuringObjectPropertyWithShorthandStaticName(props: {
91
- ...$ReadOnly<DestructuringObjectPropertyWithShorthandStaticNameProps>,
92
- +parent?: ESNode,
91
+ ...Readonly<DestructuringObjectPropertyWithShorthandStaticNameProps>,
92
+ readonly parent?: ESNode,
93
93
  }): DetachedNode<DestructuringObjectPropertyWithShorthandStaticNameType> {
94
94
  const node =
95
95
  detachedProps<DestructuringObjectPropertyWithShorthandStaticNameType>(
@@ -109,16 +109,16 @@ export function DestructuringObjectPropertyWithShorthandStaticName(props: {
109
109
  }
110
110
 
111
111
  export type DestructuringObjectPropertyWithComputedNameProps = {
112
- +key: MaybeDetachedNode<
112
+ readonly key: MaybeDetachedNode<
113
113
  DestructuringObjectPropertyWithComputedNameType['key'],
114
114
  >,
115
- +value: MaybeDetachedNode<
115
+ readonly value: MaybeDetachedNode<
116
116
  DestructuringObjectPropertyWithComputedNameType['value'],
117
117
  >,
118
118
  };
119
119
  export function DestructuringObjectPropertyWithComputedName(props: {
120
- ...$ReadOnly<DestructuringObjectPropertyWithComputedNameProps>,
121
- +parent?: ESNode,
120
+ ...Readonly<DestructuringObjectPropertyWithComputedNameProps>,
121
+ readonly parent?: ESNode,
122
122
  }): DetachedNode<DestructuringObjectPropertyWithComputedNameType> {
123
123
  const node = detachedProps<DestructuringObjectPropertyWithComputedNameType>(
124
124
  props.parent,
@@ -137,16 +137,16 @@ export function DestructuringObjectPropertyWithComputedName(props: {
137
137
  }
138
138
 
139
139
  export type ObjectPropertyProps = {
140
- +key: MaybeDetachedNode<ObjectPropertyType['key']>,
141
- +value: MaybeDetachedNode<ObjectPropertyType['value']>,
142
- +kind: ObjectPropertyType['kind'],
143
- +computed: ObjectPropertyType['computed'],
144
- +method: ObjectPropertyType['method'],
145
- +shorthand: ObjectPropertyType['shorthand'],
140
+ readonly key: MaybeDetachedNode<ObjectPropertyType['key']>,
141
+ readonly value: MaybeDetachedNode<ObjectPropertyType['value']>,
142
+ readonly kind: ObjectPropertyType['kind'],
143
+ readonly computed: ObjectPropertyType['computed'],
144
+ readonly method: ObjectPropertyType['method'],
145
+ readonly shorthand: ObjectPropertyType['shorthand'],
146
146
  };
147
147
  export function ObjectProperty(props: {
148
- ...$ReadOnly<ObjectPropertyProps>,
149
- +parent?: ESNode,
148
+ ...Readonly<ObjectPropertyProps>,
149
+ readonly parent?: ESNode,
150
150
  }): DetachedNode<ObjectPropertyType> {
151
151
  const node = detachedProps<ObjectPropertyType>(props.parent, {
152
152
  type: 'Property',
@@ -162,16 +162,18 @@ export function ObjectProperty(props: {
162
162
  }
163
163
 
164
164
  export type ObjectPropertyWithNonShorthandStaticNameProps = {
165
- +key: MaybeDetachedNode<ObjectPropertyWithNonShorthandStaticNameType['key']>,
166
- +value: MaybeDetachedNode<
165
+ readonly key: MaybeDetachedNode<
166
+ ObjectPropertyWithNonShorthandStaticNameType['key'],
167
+ >,
168
+ readonly value: MaybeDetachedNode<
167
169
  ObjectPropertyWithNonShorthandStaticNameType['value'],
168
170
  >,
169
- +kind: ObjectPropertyWithNonShorthandStaticNameType['kind'],
170
- +method: ObjectPropertyWithNonShorthandStaticNameType['method'],
171
+ readonly kind: ObjectPropertyWithNonShorthandStaticNameType['kind'],
172
+ readonly method: ObjectPropertyWithNonShorthandStaticNameType['method'],
171
173
  };
172
174
  export function ObjectPropertyWithNonShorthandStaticName(props: {
173
- ...$ReadOnly<ObjectPropertyWithNonShorthandStaticNameProps>,
174
- +parent?: ESNode,
175
+ ...Readonly<ObjectPropertyWithNonShorthandStaticNameProps>,
176
+ readonly parent?: ESNode,
175
177
  }): DetachedNode<ObjectPropertyWithNonShorthandStaticNameType> {
176
178
  const node = detachedProps<ObjectPropertyWithNonShorthandStaticNameType>(
177
179
  props.parent,
@@ -190,12 +192,16 @@ export function ObjectPropertyWithNonShorthandStaticName(props: {
190
192
  }
191
193
 
192
194
  export type ObjectPropertyWithShorthandStaticNameProps = {
193
- +key: MaybeDetachedNode<ObjectPropertyWithShorthandStaticNameType['key']>,
194
- +value: MaybeDetachedNode<ObjectPropertyWithShorthandStaticNameType['value']>,
195
+ readonly key: MaybeDetachedNode<
196
+ ObjectPropertyWithShorthandStaticNameType['key'],
197
+ >,
198
+ readonly value: MaybeDetachedNode<
199
+ ObjectPropertyWithShorthandStaticNameType['value'],
200
+ >,
195
201
  };
196
202
  export function ObjectPropertyWithShorthandStaticName(props: {
197
- ...$ReadOnly<ObjectPropertyWithShorthandStaticNameProps>,
198
- +parent?: ESNode,
203
+ ...Readonly<ObjectPropertyWithShorthandStaticNameProps>,
204
+ readonly parent?: ESNode,
199
205
  }): DetachedNode<ObjectPropertyWithShorthandStaticNameType> {
200
206
  const node = detachedProps<ObjectPropertyWithShorthandStaticNameType>(
201
207
  props.parent,
@@ -214,14 +220,16 @@ export function ObjectPropertyWithShorthandStaticName(props: {
214
220
  }
215
221
 
216
222
  export type ObjectPropertyWithComputedNameProps = {
217
- +key: MaybeDetachedNode<ObjectPropertyWithComputedNameType['key']>,
218
- +value: MaybeDetachedNode<ObjectPropertyWithComputedNameType['value']>,
219
- +kind: ObjectPropertyWithComputedNameType['kind'],
220
- +method: ObjectPropertyWithComputedNameType['method'],
223
+ readonly key: MaybeDetachedNode<ObjectPropertyWithComputedNameType['key']>,
224
+ readonly value: MaybeDetachedNode<
225
+ ObjectPropertyWithComputedNameType['value'],
226
+ >,
227
+ readonly kind: ObjectPropertyWithComputedNameType['kind'],
228
+ readonly method: ObjectPropertyWithComputedNameType['method'],
221
229
  };
222
230
  export function ObjectPropertyWithComputedName(props: {
223
- ...$ReadOnly<ObjectPropertyWithComputedNameProps>,
224
- +parent?: ESNode,
231
+ ...Readonly<ObjectPropertyWithComputedNameProps>,
232
+ readonly parent?: ESNode,
225
233
  }): DetachedNode<ObjectPropertyWithComputedNameType> {
226
234
  const node = detachedProps<ObjectPropertyWithComputedNameType>(props.parent, {
227
235
  type: 'Property',
@@ -14,28 +14,15 @@ exports.TemplateElement = TemplateElement;
14
14
 
15
15
  var _detachedNode = require("../../detachedNode");
16
16
 
17
- /**
18
- * Copyright (c) Meta Platforms, Inc. and affiliates.
19
- *
20
- * This source code is licensed under the MIT license found in the
21
- * LICENSE file in the root directory of this source tree.
22
- *
23
- *
24
- * @format
25
- */
26
17
  function ArrowFunctionExpression(props) {
27
18
  const node = (0, _detachedNode.detachedProps)(props.parent, {
28
19
  type: 'ArrowFunctionExpression',
29
20
  id: null,
30
- // $FlowExpectedError[incompatible-use]
31
21
  expression: props.body.type !== 'BlockStatement',
32
22
  params: props.params.map(n => (0, _detachedNode.asDetachedNode)(n)),
33
23
  body: (0, _detachedNode.asDetachedNode)(props.body),
34
- // $FlowFixMe[incompatible-type]
35
24
  typeParameters: (0, _detachedNode.asDetachedNode)(props.typeParameters),
36
- // $FlowFixMe[incompatible-type]
37
25
  returnType: (0, _detachedNode.asDetachedNode)(props.returnType),
38
- // $FlowFixMe[incompatible-type]
39
26
  predicate: (0, _detachedNode.asDetachedNode)(props.predicate),
40
27
  async: props.async
41
28
  });
@@ -48,13 +35,9 @@ function ClassDeclaration(props) {
48
35
 
49
36
  const node = (0, _detachedNode.detachedProps)(props.parent, {
50
37
  type: 'ClassDeclaration',
51
- // $FlowFixMe[incompatible-type]
52
38
  id: (0, _detachedNode.asDetachedNode)(props.id),
53
- // $FlowFixMe[incompatible-type]
54
39
  typeParameters: (0, _detachedNode.asDetachedNode)(props.typeParameters),
55
- // $FlowFixMe[incompatible-type]
56
40
  superClass: (0, _detachedNode.asDetachedNode)(props.superClass),
57
- // $FlowFixMe[incompatible-type]
58
41
  superTypeArguments: (0, _detachedNode.asDetachedNode)(props.superTypeArguments),
59
42
  decorators: ((_props$decorators = props.decorators) != null ? _props$decorators : []).map(n => (0, _detachedNode.asDetachedNode)(n)),
60
43
  implements: ((_props$implements = props.implements) != null ? _props$implements : []).map(n => (0, _detachedNode.asDetachedNode)(n)),
@@ -62,8 +45,7 @@ function ClassDeclaration(props) {
62
45
  });
63
46
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
64
47
  return node;
65
- } // raw/cooked are on a subobject in the estree spec, but are flat on the hermes types
66
-
48
+ }
67
49
 
68
50
  function TemplateElement(props) {
69
51
  return (0, _detachedNode.detachedProps)(props.parent, {
@@ -74,9 +56,7 @@ function TemplateElement(props) {
74
56
  raw: props.raw
75
57
  }
76
58
  });
77
- } // Identifier has a bunch of stuff that usually you don't want to provide - so we have
78
- // this manual def to allow us to default some values
79
-
59
+ }
80
60
 
81
61
  function Identifier(props) {
82
62
  var _props$optional;
@@ -85,14 +65,11 @@ function Identifier(props) {
85
65
  type: 'Identifier',
86
66
  name: props.name,
87
67
  optional: (_props$optional = props.optional) != null ? _props$optional : false,
88
- // $FlowFixMe[incompatible-type]
89
68
  typeAnnotation: (0, _detachedNode.asDetachedNode)(props.typeAnnotation)
90
69
  });
91
70
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
92
71
  return node;
93
- } // Program has a bunch of stuff that usually you don't want to provide - so we have
94
- // this manual def to allow us to default some values
95
-
72
+ }
96
73
 
97
74
  function Program(props) {
98
75
  var _props$sourceType, _props$tokens, _props$comments;
@@ -103,17 +80,13 @@ function Program(props) {
103
80
  body: props.body.map(n => (0, _detachedNode.asDetachedNode)(n)),
104
81
  tokens: (_props$tokens = props.tokens) != null ? _props$tokens : [],
105
82
  comments: (_props$comments = props.comments) != null ? _props$comments : [],
106
- interpreter: props.interpreter != null ? // $FlowFixMe[incompatible-type]
107
- (0, _detachedNode.asDetachedNode)({
83
+ interpreter: props.interpreter != null ? (0, _detachedNode.asDetachedNode)({
108
84
  type: 'InterpreterDirective',
109
85
  value: props.interpreter
110
86
  }) : null,
111
87
  docblock: props.docblock
112
88
  });
113
- } // the type annotation is stored on the Identifier's typeAnnotation
114
- // which is super awkward to work with and type - so we flatten the input
115
- // and put it in the right spot after
116
-
89
+ }
117
90
 
118
91
  function DeclareFunction(props) {
119
92
  const node = (0, _detachedNode.detachedProps)(props.parent, {
@@ -126,7 +99,6 @@ function DeclareFunction(props) {
126
99
  typeAnnotation: (0, _detachedNode.asDetachedNode)(props.functionType)
127
100
  })
128
101
  }),
129
- // $FlowFixMe[incompatible-type]
130
102
  predicate: (0, _detachedNode.asDetachedNode)(props.predicate)
131
103
  });
132
104
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
@@ -145,8 +117,7 @@ function MemberExpression(props) {
145
117
  });
146
118
  (0, _detachedNode.setParentPointersInDirectChildren)(node);
147
119
  return node;
148
- } // Ignore the hermes-specific `implicit` property.
149
-
120
+ }
150
121
 
151
122
  function BlockStatement(props) {
152
123
  const node = (0, _detachedNode.detachedProps)(props.parent, {
@@ -43,20 +43,24 @@ import {
43
43
  // boolean which is true when the body isn't a BlockStatement.
44
44
  // No need to make consumers set these
45
45
  export type ArrowFunctionExpressionProps = {
46
- +params: $ReadOnlyArray<
46
+ readonly params: ReadonlyArray<
47
47
  MaybeDetachedNode<ArrowFunctionExpressionType['params'][number]>,
48
48
  >,
49
- +body: MaybeDetachedNode<ArrowFunctionExpressionType['body']>,
50
- +typeParameters?: ?MaybeDetachedNode<
49
+ readonly body: MaybeDetachedNode<ArrowFunctionExpressionType['body']>,
50
+ readonly typeParameters?: ?MaybeDetachedNode<
51
51
  ArrowFunctionExpressionType['typeParameters'],
52
52
  >,
53
- +returnType?: ?MaybeDetachedNode<ArrowFunctionExpressionType['returnType']>,
54
- +predicate?: ?MaybeDetachedNode<ArrowFunctionExpressionType['predicate']>,
55
- +async: ArrowFunctionExpressionType['async'],
53
+ readonly returnType?: ?MaybeDetachedNode<
54
+ ArrowFunctionExpressionType['returnType'],
55
+ >,
56
+ readonly predicate?: ?MaybeDetachedNode<
57
+ ArrowFunctionExpressionType['predicate'],
58
+ >,
59
+ readonly async: ArrowFunctionExpressionType['async'],
56
60
  };
57
61
  export function ArrowFunctionExpression(props: {
58
- ...$ReadOnly<ArrowFunctionExpressionProps>,
59
- +parent?: ESNode,
62
+ ...Readonly<ArrowFunctionExpressionProps>,
63
+ readonly parent?: ESNode,
60
64
  }): DetachedNode<ArrowFunctionExpressionType> {
61
65
  const node = detachedProps<ArrowFunctionExpressionType>(props.parent, {
62
66
  type: 'ArrowFunctionExpression',
@@ -78,25 +82,27 @@ export function ArrowFunctionExpression(props: {
78
82
  }
79
83
 
80
84
  export type ClassDeclarationProps = {
81
- +id?: ?MaybeDetachedNode<ClassDeclarationType['id']>,
82
- +typeParameters?: ?MaybeDetachedNode<ClassDeclarationType['typeParameters']>,
83
- +superClass?: ?MaybeDetachedNode<ClassDeclarationType['superClass']>,
84
- +superTypeArguments?: ?MaybeDetachedNode<
85
+ readonly id?: ?MaybeDetachedNode<ClassDeclarationType['id']>,
86
+ readonly typeParameters?: ?MaybeDetachedNode<
87
+ ClassDeclarationType['typeParameters'],
88
+ >,
89
+ readonly superClass?: ?MaybeDetachedNode<ClassDeclarationType['superClass']>,
90
+ readonly superTypeArguments?: ?MaybeDetachedNode<
85
91
  ClassDeclarationType['superTypeArguments'],
86
92
  >,
87
93
  // make this optional as it's rarer that people would want to include them
88
- +implements?: $ReadOnlyArray<
94
+ readonly implements?: ReadonlyArray<
89
95
  MaybeDetachedNode<ClassDeclarationType['implements'][number]>,
90
96
  >,
91
97
  // make this optional as it's rarer that people would want to include them
92
- +decorators?: $ReadOnlyArray<
98
+ readonly decorators?: ReadonlyArray<
93
99
  MaybeDetachedNode<ClassDeclarationType['decorators'][number]>,
94
100
  >,
95
- +body: MaybeDetachedNode<ClassDeclarationType['body']>,
101
+ readonly body: MaybeDetachedNode<ClassDeclarationType['body']>,
96
102
  };
97
103
  export function ClassDeclaration(props: {
98
- ...$ReadOnly<ClassDeclarationProps>,
99
- +parent?: ESNode,
104
+ ...Readonly<ClassDeclarationProps>,
105
+ readonly parent?: ESNode,
100
106
  }): DetachedNode<ClassDeclarationType> {
101
107
  const node = detachedProps<ClassDeclarationType>(props.parent, {
102
108
  type: 'ClassDeclaration',
@@ -118,13 +124,13 @@ export function ClassDeclaration(props: {
118
124
 
119
125
  // raw/cooked are on a subobject in the estree spec, but are flat on the hermes types
120
126
  export type TemplateElementProps = {
121
- +tail: TemplateElementType['tail'],
122
- +cooked: TemplateElementType['value']['cooked'],
123
- +raw: TemplateElementType['value']['raw'],
127
+ readonly tail: TemplateElementType['tail'],
128
+ readonly cooked: TemplateElementType['value']['cooked'],
129
+ readonly raw: TemplateElementType['value']['raw'],
124
130
  };
125
131
  export function TemplateElement(props: {
126
- ...$ReadOnly<TemplateElementProps>,
127
- +parent?: ESNode,
132
+ ...Readonly<TemplateElementProps>,
133
+ readonly parent?: ESNode,
128
134
  }): DetachedNode<TemplateElementType> {
129
135
  return detachedProps<TemplateElementType>(props.parent, {
130
136
  type: 'TemplateElement',
@@ -139,13 +145,15 @@ export function TemplateElement(props: {
139
145
  // Identifier has a bunch of stuff that usually you don't want to provide - so we have
140
146
  // this manual def to allow us to default some values
141
147
  export type IdentifierProps = {
142
- +name: IdentifierType['name'],
143
- +typeAnnotation?: ?MaybeDetachedNode<IdentifierType['typeAnnotation']>,
144
- +optional?: IdentifierType['optional'],
148
+ readonly name: IdentifierType['name'],
149
+ readonly typeAnnotation?: ?MaybeDetachedNode<
150
+ IdentifierType['typeAnnotation'],
151
+ >,
152
+ readonly optional?: IdentifierType['optional'],
145
153
  };
146
154
  export function Identifier(props: {
147
- ...$ReadOnly<IdentifierProps>,
148
- +parent?: ESNode,
155
+ ...Readonly<IdentifierProps>,
156
+ readonly parent?: ESNode,
149
157
  }): DetachedNode<IdentifierType> {
150
158
  const node = detachedProps<IdentifierType>(props.parent, {
151
159
  type: 'Identifier',
@@ -161,15 +169,15 @@ export function Identifier(props: {
161
169
  // Program has a bunch of stuff that usually you don't want to provide - so we have
162
170
  // this manual def to allow us to default some values
163
171
  export type ProgramProps = {
164
- +sourceType?: ?ProgramType['sourceType'],
165
- +body: $ReadOnlyArray<MaybeDetachedNode<ProgramType['body'][number]>>,
166
- +tokens?: ?$ReadOnlyArray<MaybeDetachedNode<TokenType>>,
167
- +comments?: ?$ReadOnlyArray<MaybeDetachedNode<CommentType>>,
168
- +interpreter?: ?string,
169
- +docblock?: ?DocblockMetadataType,
172
+ readonly sourceType?: ?ProgramType['sourceType'],
173
+ readonly body: ReadonlyArray<MaybeDetachedNode<ProgramType['body'][number]>>,
174
+ readonly tokens?: ?ReadonlyArray<MaybeDetachedNode<TokenType>>,
175
+ readonly comments?: ?ReadonlyArray<MaybeDetachedNode<CommentType>>,
176
+ readonly interpreter?: ?string,
177
+ readonly docblock?: ?DocblockMetadataType,
170
178
  };
171
179
  export function Program(props: {
172
- ...$ReadOnly<ProgramProps>,
180
+ ...Readonly<ProgramProps>,
173
181
  }): DetachedNode<ProgramType> {
174
182
  return detachedProps<ProgramType>(null, {
175
183
  type: 'Program',
@@ -193,13 +201,13 @@ export function Program(props: {
193
201
  // which is super awkward to work with and type - so we flatten the input
194
202
  // and put it in the right spot after
195
203
  export type DeclareFunctionProps = {
196
- +name: string,
197
- +functionType: MaybeDetachedNode<FunctionTypeAnnotationType>,
198
- +predicate?: ?MaybeDetachedNode<DeclareFunctionType['predicate']>,
204
+ readonly name: string,
205
+ readonly functionType: MaybeDetachedNode<FunctionTypeAnnotationType>,
206
+ readonly predicate?: ?MaybeDetachedNode<DeclareFunctionType['predicate']>,
199
207
  };
200
208
  export function DeclareFunction(props: {
201
- ...$ReadOnly<DeclareFunctionProps>,
202
- +parent?: ESNode,
209
+ ...Readonly<DeclareFunctionProps>,
210
+ readonly parent?: ESNode,
203
211
  }): DetachedNode<DeclareFunctionType> {
204
212
  const node = detachedProps<DeclareFunctionType>(props.parent, {
205
213
  type: 'DeclareFunction',
@@ -219,15 +227,15 @@ export function DeclareFunction(props: {
219
227
  }
220
228
 
221
229
  export type MemberExpressionProps = {
222
- +object: MaybeDetachedNode<MemberExpressionType['object']>,
223
- +property: MaybeDetachedNode<MemberExpressionType['property']>,
224
- +computed: MemberExpressionType['computed'],
225
- +optional?: MemberExpressionType['optional'],
230
+ readonly object: MaybeDetachedNode<MemberExpressionType['object']>,
231
+ readonly property: MaybeDetachedNode<MemberExpressionType['property']>,
232
+ readonly computed: MemberExpressionType['computed'],
233
+ readonly optional?: MemberExpressionType['optional'],
226
234
  };
227
235
 
228
236
  export function MemberExpression(props: {
229
- ...$ReadOnly<MemberExpressionProps>,
230
- +parent?: ESNode,
237
+ ...Readonly<MemberExpressionProps>,
238
+ readonly parent?: ESNode,
231
239
  }): DetachedNode<MemberExpressionType> {
232
240
  const node = detachedProps<MemberExpressionType>(props.parent, {
233
241
  type: 'MemberExpression',
@@ -242,11 +250,11 @@ export function MemberExpression(props: {
242
250
 
243
251
  // Ignore the hermes-specific `implicit` property.
244
252
  export type BlockStatementProps = {
245
- +body: $ReadOnlyArray<MaybeDetachedNode<StatementType>>,
253
+ readonly body: ReadonlyArray<MaybeDetachedNode<StatementType>>,
246
254
  };
247
255
  export function BlockStatement(props: {
248
- ...$ReadOnly<BlockStatementProps>,
249
- +parent?: ESNode,
256
+ ...Readonly<BlockStatementProps>,
257
+ readonly parent?: ESNode,
250
258
  }): DetachedNode<BlockStatementType> {
251
259
  const node = detachedProps<BlockStatementType>(props.parent, {
252
260
  type: 'BlockStatement',
package/dist/index.js CHANGED
@@ -1,12 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
2
 
12
3
  Object.defineProperty(exports, "__esModule", {
@@ -15,30 +15,16 @@ exports.updateAllParentPointers = updateAllParentPointers;
15
15
 
16
16
  var _hermesParser = require("hermes-parser");
17
17
 
18
- /**
19
- * Copyright (c) Meta Platforms, Inc. and affiliates.
20
- *
21
- * This source code is licensed under the MIT license found in the
22
- * LICENSE file in the root directory of this source tree.
23
- *
24
- *
25
- * @format
26
- */
27
18
  const DETACHED_MARKER = Symbol.for('hermes-transform - Detached AST Node');
28
19
  const ORIGINAL_NODE = Symbol.for('hermes-transform - Original Node');
29
20
 
30
21
  function isDetachedNode(node) {
31
- // $FlowExpectedError[invalid-in-lhs] flow doesn't support symbols as keys
32
22
  return DETACHED_MARKER in node;
33
23
  }
34
24
 
35
25
  function getOriginalNode(node) {
36
- // $FlowExpectedError[prop-missing]
37
26
  return node[ORIGINAL_NODE];
38
27
  }
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
28
 
43
29
  function asDetachedNodeForCodeGen(node) {
44
30
  if (node == null) {
@@ -66,30 +52,13 @@ const asDetachedNode = (node, {
66
52
  }
67
53
 
68
54
  return useDeepClone ? deepCloneNode(node, {}) : shallowCloneNode(node, {});
69
- }; // used by the node type function codegen
70
-
55
+ };
71
56
 
72
57
  exports.asDetachedNode = asDetachedNode;
73
58
 
74
59
  function detachedProps(parent, props, config = {}) {
75
- // $FlowExpectedError[incompatible-type]
76
60
  const detachedNode = { ...props,
77
61
  ...((config == null ? void 0 : config.preserveLocation) !== true ? {
78
- // if this is [0,0] AND the file has a docblock then prettier will insert newlines between
79
- // certain detached nodes. Because of "intended" formatting behaviour (https://github.com/prettier/prettier/issues/12078)
80
- // this can cause us to output weirdly formatted code that should have been collapsed.
81
- //
82
- // prettier works backwards from the position you give it to find newlines or non whitespace
83
- // tokens and uses this to determine if newlines should be inserted between nodes.
84
- // By placing the range at [1, 1] we can ensure a token is always found before a newline
85
- // and therefore no newlines will be placed between nodes.
86
- //
87
- // NOTE: we will still run into the bug if there is weird code like a docblock with whitespace
88
- // characters before it. However we assume this isn't going to happen because any file
89
- // already formatted by prettier will have that whitespace removed.
90
- // We considered a more complex solution involving traversing the AST and manually updating
91
- // detached node ranges after mutations are applied - however this is a lot heavier and will
92
- // probably never be needed.
93
62
  range: [1, 1],
94
63
  loc: {
95
64
  start: {
@@ -102,12 +71,8 @@ function detachedProps(parent, props, config = {}) {
102
71
  }
103
72
  }
104
73
  } : {}),
105
- // if not provided, then we purposely don't set this here
106
- // and will rely on the tooling to update it as appropriate.
107
- // nothing should be reading from this before it's set anyway.
108
74
  parent: parent
109
- }; // mark the node as detached
110
-
75
+ };
111
76
  Object.defineProperty(detachedNode, DETACHED_MARKER, {
112
77
  configurable: false,
113
78
  enumerable: false,
@@ -126,10 +91,6 @@ function detachedProps(parent, props, config = {}) {
126
91
 
127
92
  return detachedNode;
128
93
  }
129
- /**
130
- * Shallowly clones the node, but not its children.
131
- */
132
-
133
94
 
134
95
  function shallowCloneNode(node, newProps, config = {}) {
135
96
  var _config$preserveLocat, _config$originalNode;
@@ -141,37 +102,22 @@ function shallowCloneNode(node, newProps, config = {}) {
141
102
  originalNode: (_config$originalNode = config.originalNode) != null ? _config$originalNode : node
142
103
  });
143
104
  }
144
- /**
145
- * Deeply clones node and its entire tree.
146
- */
147
-
148
105
 
149
106
  function deepCloneNode(node, newProps) {
150
- // $FlowFixMe[unsafe-object-assign]
151
107
  const clone = Object.assign(JSON.parse(JSON.stringify(node, (key, value) => {
152
- // null out parent pointers
153
108
  if (key === 'parent') {
154
109
  return undefined;
155
110
  }
156
111
 
157
112
  return value;
158
113
  })), newProps);
159
- updateAllParentPointers(clone); // $FlowExpectedError[class-object-subtyping]
160
-
114
+ updateAllParentPointers(clone);
161
115
  return detachedProps(null, clone);
162
116
  }
163
- /**
164
- * Corrects the parent pointers in direct children of the given node
165
- */
166
-
167
117
 
168
118
  function setParentPointersInDirectChildren(node) {
169
119
  _hermesParser.astNodeMutationHelpers.setParentPointersInDirectChildren(node);
170
120
  }
171
- /**
172
- * Traverses the entire subtree to ensure the parent pointers are set correctly
173
- */
174
-
175
121
 
176
122
  function updateAllParentPointers(node) {
177
123
  _hermesParser.astNodeMutationHelpers.updateAllParentPointers(node);
@@ -1,24 +1,3 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- * @generated
10
- */
11
-
12
- /*
13
- * !!! GENERATED FILE !!!
14
- *
15
- * Any manual changes to this file will be overwritten. To regenerate run `yarn build`.
16
- */
17
- // lint directives to let us do some basic validation of generated files
18
-
19
- /* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
20
-
21
- /* global $NonMaybeType, Partial, $ReadOnly, $ReadOnlyArray, $FlowFixMe */
22
1
  'use strict';
23
2
 
24
3
  Object.defineProperty(exports, "__esModule", {
@@ -8,18 +8,7 @@ exports.LineComment = LineComment;
8
8
 
9
9
  var _detachedNode = require("../../detachedNode");
10
10
 
11
- /**
12
- * Copyright (c) Meta Platforms, Inc. and affiliates.
13
- *
14
- * This source code is licensed under the MIT license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- *
17
- *
18
- * @format
19
- */
20
11
  function LineComment(props) {
21
- // $FlowExpectedError[prop-missing]
22
- // $FlowExpectedError[incompatible-type]
23
12
  return (0, _detachedNode.detachedProps)(undefined, {
24
13
  type: 'Line',
25
14
  value: props.value
@@ -27,8 +16,6 @@ function LineComment(props) {
27
16
  }
28
17
 
29
18
  function BlockComment(props) {
30
- // $FlowExpectedError[prop-missing]
31
- // $FlowExpectedError[incompatible-type]
32
19
  return (0, _detachedNode.detachedProps)(undefined, {
33
20
  type: 'Block',
34
21
  value: props.value