hermes-transform 0.9.0 → 0.10.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.
- package/dist/detachedNode.js +9 -27
- package/dist/detachedNode.js.flow +18 -31
- package/dist/generated/TransformCloneSignatures.js.flow +18 -0
- package/dist/generated/TransformModifySignatures.js.flow +14 -0
- package/dist/generated/TransformReplaceSignatures.js.flow +15 -1
- package/dist/generated/node-types.js +253 -59
- package/dist/generated/node-types.js.flow +257 -102
- package/dist/generated/special-case-node-types/Comment.js +36 -0
- package/dist/generated/special-case-node-types/Comment.js.flow +36 -0
- package/dist/generated/special-case-node-types/DeclareExportDeclaration.js +55 -0
- package/dist/generated/special-case-node-types/DeclareExportDeclaration.js.flow +97 -0
- package/dist/generated/special-case-node-types/ExportNamedDeclaration.js +42 -0
- package/dist/generated/special-case-node-types/ExportNamedDeclaration.js.flow +75 -0
- package/dist/generated/special-case-node-types/Literal.js +97 -0
- package/dist/generated/special-case-node-types/Literal.js.flow +139 -0
- package/dist/generated/special-case-node-types/ObjectTypeProperty.js +73 -0
- package/dist/generated/special-case-node-types/ObjectTypeProperty.js.flow +107 -0
- package/dist/generated/special-case-node-types/Property.js +136 -0
- package/dist/generated/special-case-node-types/Property.js.flow +237 -0
- package/dist/generated/special-case-node-types/misc.js +119 -0
- package/dist/generated/special-case-node-types/misc.js.flow +205 -0
- package/dist/generated/special-case-node-types.js +42 -174
- package/dist/generated/special-case-node-types.js.flow +7 -274
- package/dist/index.js +19 -3
- package/dist/index.js.flow +6 -2
- package/dist/transform/TransformContext.js +1 -1
- package/dist/transform/TransformContext.js.flow +2 -2
- package/dist/transform/comments/comments.js +11 -0
- package/dist/transform/comments/comments.js.flow +16 -1
- package/dist/transform/comments/prettier/main/comments.js +1 -1
- package/dist/transform/comments/prettier/main/comments.js.flow +2 -1
- package/dist/transform/mutations/InsertStatement.js +3 -3
- package/dist/transform/mutations/InsertStatement.js.flow +3 -3
- package/dist/transform/mutations/RemoveComment.js +3 -3
- package/dist/transform/mutations/RemoveComment.js.flow +3 -5
- package/dist/transform/mutations/RemoveNode.js +2 -2
- package/dist/transform/mutations/RemoveNode.js.flow +2 -2
- package/dist/transform/mutations/RemoveStatement.js +2 -2
- package/dist/transform/mutations/RemoveStatement.js.flow +2 -2
- package/dist/transform/mutations/ReplaceNode.js +4 -6
- package/dist/transform/mutations/ReplaceNode.js.flow +2 -3
- package/dist/transform/mutations/ReplaceStatementWithMany.js +2 -2
- package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +2 -2
- package/dist/transform/mutations/utils/getStatementParent.js +3 -2
- package/dist/transform/mutations/utils/getStatementParent.js.flow +5 -2
- package/dist/transform/parse.js +55 -0
- package/dist/transform/parse.js.flow +55 -0
- package/dist/transform/print.js +160 -0
- package/dist/transform/print.js.flow +176 -0
- package/dist/transform/transform.js +6 -67
- package/dist/transform/transform.js.flow +6 -69
- package/dist/transform/{getTransformedAST.js → transformAST.js} +7 -31
- package/dist/transform/{getTransformedAST.js.flow → transformAST.js.flow} +7 -32
- package/dist/traverse/traverse.js +36 -35
- package/dist/traverse/traverse.js.flow +45 -26
- package/package.json +5 -4
- package/dist/getVisitorKeys.js +0 -33
- package/dist/getVisitorKeys.js.flow +0 -31
- package/dist/transform/mutations/utils/arrayUtils.js +0 -43
- package/dist/transform/mutations/utils/arrayUtils.js.flow +0 -50
- package/dist/traverse/SimpleTraverser.js +0 -118
- package/dist/traverse/SimpleTraverser.js.flow +0 -112
package/dist/detachedNode.js
CHANGED
|
@@ -12,9 +12,7 @@ exports.setParentPointersInDirectChildren = setParentPointersInDirectChildren;
|
|
|
12
12
|
exports.shallowCloneNode = shallowCloneNode;
|
|
13
13
|
exports.updateAllParentPointers = updateAllParentPointers;
|
|
14
14
|
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
var _SimpleTraverser = require("./traverse/SimpleTraverser");
|
|
15
|
+
var _hermesParser = require("hermes-parser");
|
|
18
16
|
|
|
19
17
|
/**
|
|
20
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -57,8 +55,7 @@ const asDetachedNode = (node, {
|
|
|
57
55
|
|
|
58
56
|
exports.asDetachedNode = asDetachedNode;
|
|
59
57
|
|
|
60
|
-
function detachedProps(parent, props, config = {
|
|
61
|
-
}) {
|
|
58
|
+
function detachedProps(parent, props, config = {}) {
|
|
62
59
|
// $FlowExpectedError[incompatible-type]
|
|
63
60
|
const detachedNode = { ...props,
|
|
64
61
|
...((config == null ? void 0 : config.preserveLocation) !== true ? {
|
|
@@ -118,11 +115,13 @@ function detachedProps(parent, props, config = { ...null
|
|
|
118
115
|
*/
|
|
119
116
|
|
|
120
117
|
|
|
121
|
-
function shallowCloneNode(node, newProps, config = {
|
|
122
|
-
}) {
|
|
118
|
+
function shallowCloneNode(node, newProps, config = {}) {
|
|
123
119
|
var _config$preserveLocat, _config$originalNode;
|
|
124
120
|
|
|
125
|
-
return detachedProps(null,
|
|
121
|
+
return detachedProps(null, // $FlowFixMe[cannot-spread-interface]
|
|
122
|
+
{ ...node,
|
|
123
|
+
...newProps
|
|
124
|
+
}, {
|
|
126
125
|
preserveLocation: (_config$preserveLocat = config.preserveLocation) != null ? _config$preserveLocat : true,
|
|
127
126
|
originalNode: (_config$originalNode = config.originalNode) != null ? _config$originalNode : node
|
|
128
127
|
});
|
|
@@ -151,16 +150,7 @@ function deepCloneNode(node, newProps) {
|
|
|
151
150
|
|
|
152
151
|
|
|
153
152
|
function setParentPointersInDirectChildren(node) {
|
|
154
|
-
|
|
155
|
-
if ((0, _getVisitorKeys.isNode)( // $FlowExpectedError[prop-missing]
|
|
156
|
-
node[key])) {
|
|
157
|
-
node[key].parent = node;
|
|
158
|
-
} else if (Array.isArray(node[key])) {
|
|
159
|
-
for (const child of node[key]) {
|
|
160
|
-
child.parent = node;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
153
|
+
_hermesParser.astNodeMutationHelpers.setParentPointersInDirectChildren(node);
|
|
164
154
|
}
|
|
165
155
|
/**
|
|
166
156
|
* Traverses the entire subtree to ensure the parent pointers are set correctly
|
|
@@ -168,13 +158,5 @@ function setParentPointersInDirectChildren(node) {
|
|
|
168
158
|
|
|
169
159
|
|
|
170
160
|
function updateAllParentPointers(node) {
|
|
171
|
-
|
|
172
|
-
enter(node, parent) {
|
|
173
|
-
// $FlowExpectedError[cannot-write]
|
|
174
|
-
node.parent = parent;
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
leave() {}
|
|
178
|
-
|
|
179
|
-
});
|
|
161
|
+
_hermesParser.astNodeMutationHelpers.updateAllParentPointers(node);
|
|
180
162
|
}
|
|
@@ -10,8 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import type {BaseNode, ESNode} from 'hermes-estree';
|
|
12
12
|
|
|
13
|
-
import {
|
|
14
|
-
import {SimpleTraverser} from './traverse/SimpleTraverser';
|
|
13
|
+
import {astNodeMutationHelpers} from 'hermes-parser';
|
|
15
14
|
|
|
16
15
|
export opaque type DetachedNode<+T> = T;
|
|
17
16
|
export type MaybeDetachedNode<+T> = T | DetachedNode<T>;
|
|
@@ -38,7 +37,7 @@ export const asDetachedNode: {
|
|
|
38
37
|
node: MaybeDetachedNode<T>,
|
|
39
38
|
config?: {useDeepClone: boolean},
|
|
40
39
|
): DetachedNode<T>,
|
|
41
|
-
<T: ESNode>(
|
|
40
|
+
<T: ?ESNode>(
|
|
42
41
|
node: ?MaybeDetachedNode<T>,
|
|
43
42
|
config?: {useDeepClone: boolean},
|
|
44
43
|
): ?DetachedNode<T>,
|
|
@@ -64,7 +63,7 @@ export const asDetachedNode: {
|
|
|
64
63
|
export function detachedProps<T: BaseNode>(
|
|
65
64
|
parent: ?ESNode,
|
|
66
65
|
props: $ReadOnly<$Partial<{...}>>,
|
|
67
|
-
config: DetachConfig = {
|
|
66
|
+
config: DetachConfig = {},
|
|
68
67
|
): DetachedNode<T> {
|
|
69
68
|
// $FlowExpectedError[incompatible-type]
|
|
70
69
|
const detachedNode: DetachedNode<T> = {
|
|
@@ -131,12 +130,17 @@ export function detachedProps<T: BaseNode>(
|
|
|
131
130
|
export function shallowCloneNode<T: ESNode>(
|
|
132
131
|
node: T,
|
|
133
132
|
newProps: $ReadOnly<$Partial<{...}>>,
|
|
134
|
-
config?: DetachConfig = {
|
|
133
|
+
config?: DetachConfig = {},
|
|
135
134
|
): DetachedNode<T> {
|
|
136
|
-
return detachedProps(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
return detachedProps(
|
|
136
|
+
null,
|
|
137
|
+
// $FlowFixMe[cannot-spread-interface]
|
|
138
|
+
{...node, ...newProps},
|
|
139
|
+
{
|
|
140
|
+
preserveLocation: config.preserveLocation ?? true,
|
|
141
|
+
originalNode: config.originalNode ?? node,
|
|
142
|
+
},
|
|
143
|
+
);
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
/**
|
|
@@ -171,31 +175,14 @@ export function deepCloneNode<T: ESNode>(
|
|
|
171
175
|
export function setParentPointersInDirectChildren(
|
|
172
176
|
node: DetachedNode<ESNode>,
|
|
173
177
|
): void {
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
isNode(
|
|
177
|
-
// $FlowExpectedError[prop-missing]
|
|
178
|
-
node[key],
|
|
179
|
-
)
|
|
180
|
-
) {
|
|
181
|
-
node[key].parent = node;
|
|
182
|
-
} else if (Array.isArray(node[key])) {
|
|
183
|
-
for (const child of node[key]) {
|
|
184
|
-
child.parent = node;
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
178
|
+
astNodeMutationHelpers.setParentPointersInDirectChildren(node);
|
|
188
179
|
}
|
|
189
180
|
|
|
190
181
|
/**
|
|
191
182
|
* Traverses the entire subtree to ensure the parent pointers are set correctly
|
|
192
183
|
*/
|
|
193
|
-
export function updateAllParentPointers(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
node.parent = parent;
|
|
198
|
-
},
|
|
199
|
-
leave() {},
|
|
200
|
-
});
|
|
184
|
+
export function updateAllParentPointers(
|
|
185
|
+
node: ESNode | DetachedNode<ESNode>,
|
|
186
|
+
): void {
|
|
187
|
+
astNodeMutationHelpers.updateAllParentPointers(node);
|
|
201
188
|
}
|
|
@@ -6,6 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @flow strict-local
|
|
8
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`.
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
// lint directives to let us do some basic validation of generated files
|
|
@@ -25,6 +32,7 @@ import type {
|
|
|
25
32
|
AwaitExpression,
|
|
26
33
|
BigIntLiteral,
|
|
27
34
|
BigIntLiteralTypeAnnotation,
|
|
35
|
+
BigIntTypeAnnotation,
|
|
28
36
|
BinaryExpression,
|
|
29
37
|
BlockStatement,
|
|
30
38
|
BooleanLiteral,
|
|
@@ -183,6 +191,7 @@ import type {
|
|
|
183
191
|
AwaitExpressionProps,
|
|
184
192
|
BigIntLiteralProps,
|
|
185
193
|
BigIntLiteralTypeAnnotationProps,
|
|
194
|
+
BigIntTypeAnnotationProps,
|
|
186
195
|
BinaryExpressionProps,
|
|
187
196
|
BlockStatementProps,
|
|
188
197
|
BooleanLiteralProps,
|
|
@@ -412,6 +421,14 @@ type BigIntLiteralTypeAnnotationCloneSignature = ((
|
|
|
412
421
|
node: ?BigIntLiteralTypeAnnotation,
|
|
413
422
|
newProps: $Partial<BigIntLiteralTypeAnnotationProps>,
|
|
414
423
|
) => DetachedNode<BigIntLiteralTypeAnnotation> | null);
|
|
424
|
+
type BigIntTypeAnnotationCloneSignature = ((
|
|
425
|
+
node: BigIntTypeAnnotation,
|
|
426
|
+
newProps: $Partial<BigIntTypeAnnotationProps>,
|
|
427
|
+
) => DetachedNode<BigIntTypeAnnotation>) &
|
|
428
|
+
((
|
|
429
|
+
node: ?BigIntTypeAnnotation,
|
|
430
|
+
newProps: $Partial<BigIntTypeAnnotationProps>,
|
|
431
|
+
) => DetachedNode<BigIntTypeAnnotation> | null);
|
|
415
432
|
type BinaryExpressionCloneSignature = ((
|
|
416
433
|
node: BinaryExpression,
|
|
417
434
|
newProps: $Partial<BinaryExpressionProps>,
|
|
@@ -1590,6 +1607,7 @@ export type TransformCloneSignatures = AnyTypeAnnotationCloneSignature &
|
|
|
1590
1607
|
AwaitExpressionCloneSignature &
|
|
1591
1608
|
BigIntLiteralCloneSignature &
|
|
1592
1609
|
BigIntLiteralTypeAnnotationCloneSignature &
|
|
1610
|
+
BigIntTypeAnnotationCloneSignature &
|
|
1593
1611
|
BinaryExpressionCloneSignature &
|
|
1594
1612
|
BlockStatementCloneSignature &
|
|
1595
1613
|
BooleanLiteralCloneSignature &
|
|
@@ -6,6 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @flow strict-local
|
|
8
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`.
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
// lint directives to let us do some basic validation of generated files
|
|
@@ -25,6 +32,7 @@ import type {
|
|
|
25
32
|
AwaitExpression,
|
|
26
33
|
BigIntLiteral,
|
|
27
34
|
BigIntLiteralTypeAnnotation,
|
|
35
|
+
BigIntTypeAnnotation,
|
|
28
36
|
BinaryExpression,
|
|
29
37
|
BlockStatement,
|
|
30
38
|
BooleanLiteral,
|
|
@@ -183,6 +191,7 @@ import type {
|
|
|
183
191
|
AwaitExpressionProps,
|
|
184
192
|
BigIntLiteralProps,
|
|
185
193
|
BigIntLiteralTypeAnnotationProps,
|
|
194
|
+
BigIntTypeAnnotationProps,
|
|
186
195
|
BinaryExpressionProps,
|
|
187
196
|
BlockStatementProps,
|
|
188
197
|
BooleanLiteralProps,
|
|
@@ -371,6 +380,10 @@ type BigIntLiteralTypeAnnotationModifySignature = (
|
|
|
371
380
|
node: ?BigIntLiteralTypeAnnotation,
|
|
372
381
|
newProps: $Partial<BigIntLiteralTypeAnnotationProps>,
|
|
373
382
|
) => void;
|
|
383
|
+
type BigIntTypeAnnotationModifySignature = (
|
|
384
|
+
node: ?BigIntTypeAnnotation,
|
|
385
|
+
newProps: $Partial<BigIntTypeAnnotationProps>,
|
|
386
|
+
) => void;
|
|
374
387
|
type BinaryExpressionModifySignature = (
|
|
375
388
|
node: ?BinaryExpression,
|
|
376
389
|
newProps: $Partial<BinaryExpressionProps>,
|
|
@@ -965,6 +978,7 @@ export type TransformModifySignatures = AnyTypeAnnotationModifySignature &
|
|
|
965
978
|
AwaitExpressionModifySignature &
|
|
966
979
|
BigIntLiteralModifySignature &
|
|
967
980
|
BigIntLiteralTypeAnnotationModifySignature &
|
|
981
|
+
BigIntTypeAnnotationModifySignature &
|
|
968
982
|
BinaryExpressionModifySignature &
|
|
969
983
|
BlockStatementModifySignature &
|
|
970
984
|
BooleanLiteralModifySignature &
|
|
@@ -4,8 +4,15 @@
|
|
|
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.
|
|
6
6
|
*
|
|
7
|
-
* @flow strict
|
|
7
|
+
* @flow strict-local
|
|
8
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`.
|
|
9
16
|
*/
|
|
10
17
|
|
|
11
18
|
// lint directives to let us do some basic validation of generated files
|
|
@@ -24,6 +31,7 @@ import type {
|
|
|
24
31
|
AssignmentPattern,
|
|
25
32
|
AwaitExpression,
|
|
26
33
|
BigIntLiteralTypeAnnotation,
|
|
34
|
+
BigIntTypeAnnotation,
|
|
27
35
|
BinaryExpression,
|
|
28
36
|
BlockStatement,
|
|
29
37
|
BooleanLiteralTypeAnnotation,
|
|
@@ -215,6 +223,11 @@ type BigIntLiteralTypeAnnotationReplaceSignature = (
|
|
|
215
223
|
nodeToReplaceWith: DetachedNode<BigIntLiteralTypeAnnotation>,
|
|
216
224
|
options?: $ReadOnly<{keepComments?: boolean}>,
|
|
217
225
|
) => void;
|
|
226
|
+
type BigIntTypeAnnotationReplaceSignature = (
|
|
227
|
+
target: BigIntTypeAnnotation,
|
|
228
|
+
nodeToReplaceWith: DetachedNode<BigIntTypeAnnotation>,
|
|
229
|
+
options?: $ReadOnly<{keepComments?: boolean}>,
|
|
230
|
+
) => void;
|
|
218
231
|
type BinaryExpressionReplaceSignature = (
|
|
219
232
|
target: BinaryExpression,
|
|
220
233
|
nodeToReplaceWith: DetachedNode<BinaryExpression>,
|
|
@@ -939,6 +952,7 @@ export type TransformReplaceSignatures = AnyTypeAnnotationReplaceSignature &
|
|
|
939
952
|
AssignmentPatternReplaceSignature &
|
|
940
953
|
AwaitExpressionReplaceSignature &
|
|
941
954
|
BigIntLiteralTypeAnnotationReplaceSignature &
|
|
955
|
+
BigIntTypeAnnotationReplaceSignature &
|
|
942
956
|
BinaryExpressionReplaceSignature &
|
|
943
957
|
BlockStatementReplaceSignature &
|
|
944
958
|
BooleanLiteralTypeAnnotationReplaceSignature &
|