hermes-transform 0.8.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/ESLINT_LICENCE +19 -0
- package/PRETTIER_LICENCE +7 -0
- package/dist/detachedNode.js +100 -42
- package/dist/detachedNode.js.flow +116 -41
- package/dist/generated/TransformCloneSignatures.js.flow +18 -0
- package/dist/generated/TransformModifySignatures.js.flow +1127 -0
- package/dist/generated/TransformReplaceSignatures.js.flow +15 -1
- package/dist/generated/node-types.js +852 -883
- package/dist/generated/node-types.js.flow +1187 -1217
- 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 -180
- package/dist/generated/special-case-node-types.js.flow +7 -258
- package/dist/index.js +19 -3
- package/dist/index.js.flow +6 -2
- package/dist/transform/TransformContext.js +34 -11
- package/dist/transform/TransformContext.js.flow +90 -33
- package/dist/transform/comments/comments.js +34 -5
- package/dist/transform/comments/comments.js.flow +39 -4
- 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 +4 -3
- package/dist/transform/mutations/InsertStatement.js.flow +4 -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 +10 -7
- package/dist/transform/mutations/ReplaceNode.js.flow +7 -5
- package/dist/transform/mutations/ReplaceStatementWithMany.js +2 -2
- package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +7 -4
- 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 -16
- package/dist/transform/{getTransformedAST.js.flow → transformAST.js.flow} +7 -14
- package/dist/traverse/NodeEventGenerator.js.flow +1 -1
- package/dist/traverse/traverse.js +36 -35
- package/dist/traverse/traverse.js.flow +46 -27
- package/package.json +10 -5
- 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/ESLINT_LICENCE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright OpenJS Foundation and other contributors, <www.openjsf.org>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/PRETTIER_LICENCE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright © James Long and contributors
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/detachedNode.js
CHANGED
|
@@ -3,15 +3,16 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.asDetachedNode = void 0;
|
|
6
7
|
exports.deepCloneNode = deepCloneNode;
|
|
7
8
|
exports.detachedProps = detachedProps;
|
|
9
|
+
exports.getOriginalNode = getOriginalNode;
|
|
10
|
+
exports.isDetachedNode = isDetachedNode;
|
|
8
11
|
exports.setParentPointersInDirectChildren = setParentPointersInDirectChildren;
|
|
9
12
|
exports.shallowCloneNode = shallowCloneNode;
|
|
10
13
|
exports.updateAllParentPointers = updateAllParentPointers;
|
|
11
14
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _SimpleTraverser = require("./traverse/SimpleTraverser");
|
|
15
|
+
var _hermesParser = require("hermes-parser");
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -22,41 +23,115 @@ var _SimpleTraverser = require("./traverse/SimpleTraverser");
|
|
|
22
23
|
*
|
|
23
24
|
* @format
|
|
24
25
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const DETACHED_MARKER = Symbol.for('hermes-transform - Detached AST Node');
|
|
27
|
+
const ORIGINAL_NODE = Symbol.for('hermes-transform - Original Node');
|
|
28
|
+
|
|
29
|
+
function isDetachedNode(node) {
|
|
30
|
+
// $FlowExpectedError[invalid-in-lhs] flow doesn't support symbols as keys
|
|
31
|
+
return DETACHED_MARKER in node;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getOriginalNode(node) {
|
|
35
|
+
// $FlowExpectedError[prop-missing]
|
|
36
|
+
return node[ORIGINAL_NODE];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const asDetachedNode = (node, {
|
|
40
|
+
useDeepClone
|
|
41
|
+
} = {
|
|
42
|
+
useDeepClone: false
|
|
43
|
+
}) => {
|
|
44
|
+
if (node == null) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (isDetachedNode(node)) {
|
|
49
|
+
return node;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return useDeepClone ? deepCloneNode(node, {}) : shallowCloneNode(node, {});
|
|
53
|
+
}; // used by the node type function codegen
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
exports.asDetachedNode = asDetachedNode;
|
|
57
|
+
|
|
58
|
+
function detachedProps(parent, props, config = {}) {
|
|
59
|
+
// $FlowExpectedError[incompatible-type]
|
|
60
|
+
const detachedNode = { ...props,
|
|
61
|
+
...((config == null ? void 0 : config.preserveLocation) !== true ? {
|
|
62
|
+
// if this is [0,0] AND the file has a docblock then prettier will insert newlines between
|
|
63
|
+
// certain detached nodes. Because of "intended" formatting behaviour (https://github.com/prettier/prettier/issues/12078)
|
|
64
|
+
// this can cause us to output weirdly formatted code that should have been collapsed.
|
|
65
|
+
//
|
|
66
|
+
// prettier works backwards from the position you give it to find newlines or non whitespace
|
|
67
|
+
// tokens and uses this to determine if newlines should be inserted between nodes.
|
|
68
|
+
// By placing the range at [1, 1] we can ensure a token is always found before a newline
|
|
69
|
+
// and therefore no newlines will be placed between nodes.
|
|
70
|
+
//
|
|
71
|
+
// NOTE: we will still run into the bug if there is weird code like a docblock with whitespace
|
|
72
|
+
// characters before it. However we assume this isn't going to happen because any file
|
|
73
|
+
// already formatted by prettier will have that whitespace removed.
|
|
74
|
+
// We considered a more complex solution involving traversing the AST and manually updating
|
|
75
|
+
// detached node ranges after mutations are applied - however this is a lot heavier and will
|
|
76
|
+
// probably never be needed.
|
|
77
|
+
range: [1, 1],
|
|
78
|
+
loc: {
|
|
79
|
+
start: {
|
|
80
|
+
line: 1,
|
|
81
|
+
column: 0
|
|
82
|
+
},
|
|
83
|
+
end: {
|
|
84
|
+
line: 1,
|
|
85
|
+
column: 0
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
} : {}),
|
|
29
89
|
// if not provided, then we purposely don't set this here
|
|
30
90
|
// and will rely on the tooling to update it as appropriate.
|
|
31
91
|
// nothing should be reading from this before it's set anyway.
|
|
32
|
-
parent: parent
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
92
|
+
parent: parent
|
|
93
|
+
}; // mark the node as detached
|
|
94
|
+
|
|
95
|
+
Object.defineProperty(detachedNode, DETACHED_MARKER, {
|
|
96
|
+
configurable: false,
|
|
97
|
+
enumerable: false,
|
|
98
|
+
value: true,
|
|
99
|
+
writable: false
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
if (config.originalNode) {
|
|
103
|
+
Object.defineProperty(detachedNode, ORIGINAL_NODE, {
|
|
104
|
+
configurable: false,
|
|
105
|
+
enumerable: false,
|
|
106
|
+
value: config.originalNode,
|
|
107
|
+
writable: false
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return detachedNode;
|
|
45
112
|
}
|
|
46
113
|
/**
|
|
47
114
|
* Shallowly clones the node, but not its children.
|
|
48
115
|
*/
|
|
49
116
|
|
|
50
117
|
|
|
51
|
-
function shallowCloneNode(node, newProps = {}) {
|
|
52
|
-
|
|
118
|
+
function shallowCloneNode(node, newProps, config = {}) {
|
|
119
|
+
var _config$preserveLocat, _config$originalNode;
|
|
120
|
+
|
|
121
|
+
return detachedProps(null, // $FlowFixMe[cannot-spread-interface]
|
|
122
|
+
{ ...node,
|
|
123
|
+
...newProps
|
|
124
|
+
}, {
|
|
125
|
+
preserveLocation: (_config$preserveLocat = config.preserveLocation) != null ? _config$preserveLocat : true,
|
|
126
|
+
originalNode: (_config$originalNode = config.originalNode) != null ? _config$originalNode : node
|
|
127
|
+
});
|
|
53
128
|
}
|
|
54
129
|
/**
|
|
55
130
|
* Deeply clones node and its entire tree.
|
|
56
131
|
*/
|
|
57
132
|
|
|
58
133
|
|
|
59
|
-
function deepCloneNode(node, newProps
|
|
134
|
+
function deepCloneNode(node, newProps) {
|
|
60
135
|
const clone = Object.assign(JSON.parse(JSON.stringify(node, (key, value) => {
|
|
61
136
|
// null out parent pointers
|
|
62
137
|
if (key === 'parent') {
|
|
@@ -75,16 +150,7 @@ function deepCloneNode(node, newProps = {}) {
|
|
|
75
150
|
|
|
76
151
|
|
|
77
152
|
function setParentPointersInDirectChildren(node) {
|
|
78
|
-
|
|
79
|
-
if ((0, _getVisitorKeys.isNode)( // $FlowExpectedError[prop-missing]
|
|
80
|
-
node[key])) {
|
|
81
|
-
node[key].parent = node;
|
|
82
|
-
} else if (Array.isArray(node[key])) {
|
|
83
|
-
for (const child of node[key]) {
|
|
84
|
-
child.parent = node;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
153
|
+
_hermesParser.astNodeMutationHelpers.setParentPointersInDirectChildren(node);
|
|
88
154
|
}
|
|
89
155
|
/**
|
|
90
156
|
* Traverses the entire subtree to ensure the parent pointers are set correctly
|
|
@@ -92,13 +158,5 @@ function setParentPointersInDirectChildren(node) {
|
|
|
92
158
|
|
|
93
159
|
|
|
94
160
|
function updateAllParentPointers(node) {
|
|
95
|
-
|
|
96
|
-
enter(node, parent) {
|
|
97
|
-
// $FlowExpectedError[cannot-write]
|
|
98
|
-
node.parent = parent;
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
leave() {}
|
|
102
|
-
|
|
103
|
-
});
|
|
161
|
+
_hermesParser.astNodeMutationHelpers.updateAllParentPointers(node);
|
|
104
162
|
}
|
|
@@ -10,35 +10,118 @@
|
|
|
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;
|
|
16
|
+
export type MaybeDetachedNode<+T> = T | DetachedNode<T>;
|
|
17
|
+
|
|
18
|
+
type DetachConfig = $ReadOnly<{
|
|
19
|
+
preserveLocation?: boolean,
|
|
20
|
+
originalNode?: ESNode,
|
|
21
|
+
}>;
|
|
22
|
+
|
|
23
|
+
const DETACHED_MARKER = Symbol.for('hermes-transform - Detached AST Node');
|
|
24
|
+
const ORIGINAL_NODE = Symbol.for('hermes-transform - Original Node');
|
|
25
|
+
|
|
26
|
+
export function isDetachedNode(node: MaybeDetachedNode<ESNode>): boolean {
|
|
27
|
+
// $FlowExpectedError[invalid-in-lhs] flow doesn't support symbols as keys
|
|
28
|
+
return DETACHED_MARKER in node;
|
|
29
|
+
}
|
|
30
|
+
export function getOriginalNode(node: MaybeDetachedNode<ESNode>): ?ESNode {
|
|
31
|
+
// $FlowExpectedError[prop-missing]
|
|
32
|
+
return node[ORIGINAL_NODE];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const asDetachedNode: {
|
|
36
|
+
<T: ESNode>(
|
|
37
|
+
node: MaybeDetachedNode<T>,
|
|
38
|
+
config?: {useDeepClone: boolean},
|
|
39
|
+
): DetachedNode<T>,
|
|
40
|
+
<T: ?ESNode>(
|
|
41
|
+
node: ?MaybeDetachedNode<T>,
|
|
42
|
+
config?: {useDeepClone: boolean},
|
|
43
|
+
): ?DetachedNode<T>,
|
|
44
|
+
} = <T: ESNode>(
|
|
45
|
+
node: ?MaybeDetachedNode<T>,
|
|
46
|
+
{useDeepClone}: {useDeepClone: boolean} = {useDeepClone: false},
|
|
47
|
+
): // $FlowExpectedError[incompatible-type]
|
|
48
|
+
?DetachedNode<T> => {
|
|
49
|
+
if (node == null) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (isDetachedNode(node)) {
|
|
54
|
+
return node;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return useDeepClone
|
|
58
|
+
? deepCloneNode<T>(node, {})
|
|
59
|
+
: shallowCloneNode<T>(node, {});
|
|
60
|
+
};
|
|
17
61
|
|
|
18
62
|
// used by the node type function codegen
|
|
19
63
|
export function detachedProps<T: BaseNode>(
|
|
20
64
|
parent: ?ESNode,
|
|
21
|
-
props: {...}
|
|
65
|
+
props: $ReadOnly<$Partial<{...}>>,
|
|
66
|
+
config: DetachConfig = {},
|
|
22
67
|
): DetachedNode<T> {
|
|
23
|
-
// $FlowExpectedError[incompatible-
|
|
24
|
-
|
|
68
|
+
// $FlowExpectedError[incompatible-type]
|
|
69
|
+
const detachedNode: DetachedNode<T> = {
|
|
25
70
|
...props,
|
|
71
|
+
...(config?.preserveLocation !== true
|
|
72
|
+
? {
|
|
73
|
+
// if this is [0,0] AND the file has a docblock then prettier will insert newlines between
|
|
74
|
+
// certain detached nodes. Because of "intended" formatting behaviour (https://github.com/prettier/prettier/issues/12078)
|
|
75
|
+
// this can cause us to output weirdly formatted code that should have been collapsed.
|
|
76
|
+
//
|
|
77
|
+
// prettier works backwards from the position you give it to find newlines or non whitespace
|
|
78
|
+
// tokens and uses this to determine if newlines should be inserted between nodes.
|
|
79
|
+
// By placing the range at [1, 1] we can ensure a token is always found before a newline
|
|
80
|
+
// and therefore no newlines will be placed between nodes.
|
|
81
|
+
//
|
|
82
|
+
// NOTE: we will still run into the bug if there is weird code like a docblock with whitespace
|
|
83
|
+
// characters before it. However we assume this isn't going to happen because any file
|
|
84
|
+
// already formatted by prettier will have that whitespace removed.
|
|
85
|
+
// We considered a more complex solution involving traversing the AST and manually updating
|
|
86
|
+
// detached node ranges after mutations are applied - however this is a lot heavier and will
|
|
87
|
+
// probably never be needed.
|
|
88
|
+
range: [1, 1],
|
|
89
|
+
loc: {
|
|
90
|
+
start: {
|
|
91
|
+
line: 1,
|
|
92
|
+
column: 0,
|
|
93
|
+
},
|
|
94
|
+
end: {
|
|
95
|
+
line: 1,
|
|
96
|
+
column: 0,
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
}
|
|
100
|
+
: {}),
|
|
26
101
|
// if not provided, then we purposely don't set this here
|
|
27
102
|
// and will rely on the tooling to update it as appropriate.
|
|
28
103
|
// nothing should be reading from this before it's set anyway.
|
|
29
104
|
parent: (parent: $FlowFixMe),
|
|
30
|
-
range: [0, 0],
|
|
31
|
-
loc: {
|
|
32
|
-
start: {
|
|
33
|
-
line: 1,
|
|
34
|
-
column: 0,
|
|
35
|
-
},
|
|
36
|
-
end: {
|
|
37
|
-
line: 1,
|
|
38
|
-
column: 0,
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
105
|
};
|
|
106
|
+
|
|
107
|
+
// mark the node as detached
|
|
108
|
+
Object.defineProperty(detachedNode, DETACHED_MARKER, {
|
|
109
|
+
configurable: false,
|
|
110
|
+
enumerable: false,
|
|
111
|
+
value: true,
|
|
112
|
+
writable: false,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (config.originalNode) {
|
|
116
|
+
Object.defineProperty(detachedNode, ORIGINAL_NODE, {
|
|
117
|
+
configurable: false,
|
|
118
|
+
enumerable: false,
|
|
119
|
+
value: config.originalNode,
|
|
120
|
+
writable: false,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return detachedNode;
|
|
42
125
|
}
|
|
43
126
|
|
|
44
127
|
/**
|
|
@@ -46,9 +129,18 @@ export function detachedProps<T: BaseNode>(
|
|
|
46
129
|
*/
|
|
47
130
|
export function shallowCloneNode<T: ESNode>(
|
|
48
131
|
node: T,
|
|
49
|
-
newProps: $Partial<{...}
|
|
132
|
+
newProps: $ReadOnly<$Partial<{...}>>,
|
|
133
|
+
config?: DetachConfig = {},
|
|
50
134
|
): DetachedNode<T> {
|
|
51
|
-
return detachedProps(
|
|
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
|
+
);
|
|
52
144
|
}
|
|
53
145
|
|
|
54
146
|
/**
|
|
@@ -56,7 +148,7 @@ export function shallowCloneNode<T: ESNode>(
|
|
|
56
148
|
*/
|
|
57
149
|
export function deepCloneNode<T: ESNode>(
|
|
58
150
|
node: T,
|
|
59
|
-
newProps: $Partial<{...}
|
|
151
|
+
newProps: $ReadOnly<$Partial<{...}>>,
|
|
60
152
|
): DetachedNode<T> {
|
|
61
153
|
const clone: DetachedNode<T> = Object.assign(
|
|
62
154
|
JSON.parse(
|
|
@@ -83,31 +175,14 @@ export function deepCloneNode<T: ESNode>(
|
|
|
83
175
|
export function setParentPointersInDirectChildren(
|
|
84
176
|
node: DetachedNode<ESNode>,
|
|
85
177
|
): void {
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
isNode(
|
|
89
|
-
// $FlowExpectedError[prop-missing]
|
|
90
|
-
node[key],
|
|
91
|
-
)
|
|
92
|
-
) {
|
|
93
|
-
node[key].parent = node;
|
|
94
|
-
} else if (Array.isArray(node[key])) {
|
|
95
|
-
for (const child of node[key]) {
|
|
96
|
-
child.parent = node;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
178
|
+
astNodeMutationHelpers.setParentPointersInDirectChildren(node);
|
|
100
179
|
}
|
|
101
180
|
|
|
102
181
|
/**
|
|
103
182
|
* Traverses the entire subtree to ensure the parent pointers are set correctly
|
|
104
183
|
*/
|
|
105
|
-
export function updateAllParentPointers(
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
node.parent = parent;
|
|
110
|
-
},
|
|
111
|
-
leave() {},
|
|
112
|
-
});
|
|
184
|
+
export function updateAllParentPointers(
|
|
185
|
+
node: ESNode | DetachedNode<ESNode>,
|
|
186
|
+
): void {
|
|
187
|
+
astNodeMutationHelpers.updateAllParentPointers(node);
|
|
113
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 &
|