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.
- package/LICENSE +1 -1
- package/dist/detachedNode.js +25 -49
- package/dist/detachedNode.js.flow +3 -3
- package/dist/generated/TransformCloneSignatures.js.flow +1728 -9
- package/dist/generated/TransformReplaceSignatures.js.flow +921 -780
- package/dist/generated/node-types.js +1099 -1156
- package/dist/generated/node-types.js.flow +77 -125
- package/dist/generated/special-case-node-types.js +106 -85
- package/dist/generated/special-case-node-types.js.flow +28 -2
- package/dist/getVisitorKeys.js +4 -6
- package/dist/getVisitorKeys.js.flow +1 -1
- package/dist/index.js +13 -18
- package/dist/index.js.flow +8 -2
- package/dist/transform/Errors.js +8 -116
- package/dist/transform/Errors.js.flow +1 -1
- package/dist/transform/MutationContext.js +54 -67
- package/dist/transform/MutationContext.js.flow +4 -3
- package/dist/transform/TransformContext.js +100 -58
- package/dist/transform/TransformContext.js.flow +277 -141
- package/dist/transform/comments/comments.js +127 -40
- package/dist/transform/comments/comments.js.flow +106 -29
- package/dist/transform/comments/prettier/common/util.js +46 -47
- package/dist/transform/comments/prettier/common/util.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/comments.js +199 -216
- package/dist/transform/comments/prettier/language-js/comments.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/loc.js +10 -9
- package/dist/transform/comments/prettier/language-js/loc.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/printer-estree.js +7 -6
- package/dist/transform/comments/prettier/language-js/printer-estree.js.flow +1 -1
- package/dist/transform/comments/prettier/language-js/utils.js +18 -30
- package/dist/transform/comments/prettier/language-js/utils.js.flow +1 -1
- package/dist/transform/comments/prettier/main/comments.js +225 -298
- package/dist/transform/comments/prettier/main/comments.js.flow +1 -1
- package/dist/transform/comments/prettier/utils/get-last.js +2 -4
- package/dist/transform/comments/prettier/utils/get-last.js.flow +1 -1
- package/dist/transform/getTransformedAST.js +81 -104
- package/dist/transform/getTransformedAST.js.flow +18 -13
- package/dist/transform/mutations/AddComments.js +43 -0
- package/dist/transform/mutations/AddComments.js.flow +50 -0
- package/dist/transform/mutations/CloneCommentsTo.js +16 -24
- package/dist/transform/mutations/CloneCommentsTo.js.flow +2 -3
- package/dist/transform/mutations/InsertStatement.js +28 -30
- package/dist/transform/mutations/InsertStatement.js.flow +7 -2
- package/dist/transform/mutations/RemoveComment.js +25 -43
- package/dist/transform/mutations/RemoveComment.js.flow +1 -1
- package/dist/transform/mutations/RemoveNode.js +192 -0
- package/dist/transform/mutations/RemoveNode.js.flow +290 -0
- package/dist/transform/mutations/RemoveStatement.js +7 -9
- package/dist/transform/mutations/RemoveStatement.js.flow +1 -1
- package/dist/transform/mutations/ReplaceNode.js +36 -44
- package/dist/transform/mutations/ReplaceNode.js.flow +1 -1
- package/dist/transform/mutations/ReplaceStatementWithMany.js +11 -13
- package/dist/transform/mutations/ReplaceStatementWithMany.js.flow +1 -1
- package/dist/transform/mutations/utils/arrayUtils.js +16 -14
- package/dist/transform/mutations/utils/arrayUtils.js.flow +16 -1
- package/dist/transform/mutations/utils/getStatementParent.js +23 -28
- package/dist/transform/mutations/utils/getStatementParent.js.flow +2 -2
- package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js +7 -24
- package/dist/transform/mutations/utils/isValidModuleDeclarationParent.js.flow +1 -1
- package/dist/transform/transform.js +58 -30
- package/dist/transform/transform.js.flow +51 -13
- package/dist/traverse/NodeEventGenerator.js +91 -165
- package/dist/traverse/NodeEventGenerator.js.flow +1 -1
- package/dist/traverse/SafeEmitter.js +20 -38
- package/dist/traverse/SafeEmitter.js.flow +1 -1
- package/dist/traverse/SimpleTraverser.js +67 -98
- package/dist/traverse/SimpleTraverser.js.flow +4 -1
- package/dist/traverse/esquery.js +6 -6
- package/dist/traverse/esquery.js.flow +1 -1
- package/dist/traverse/traverse.js +64 -52
- package/dist/traverse/traverse.js.flow +63 -10
- package/package.json +5 -3
- package/dist/transform/mutations/AddLeadingComments.js +0 -47
- package/dist/transform/mutations/AddLeadingComments.js.flow +0 -49
- package/dist/transform/mutations/AddTrailingComments.js +0 -47
- package/dist/transform/mutations/AddTrailingComments.js.flow +0 -49
|
@@ -9,9 +9,7 @@ var _detachedNode = require("../detachedNode");
|
|
|
9
9
|
|
|
10
10
|
var _comments = require("./comments/comments");
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _AddTrailingComments = require("./mutations/AddTrailingComments");
|
|
12
|
+
var _AddComments = require("./mutations/AddComments");
|
|
15
13
|
|
|
16
14
|
var _CloneCommentsTo = require("./mutations/CloneCommentsTo");
|
|
17
15
|
|
|
@@ -19,29 +17,28 @@ var _InsertStatement = require("./mutations/InsertStatement");
|
|
|
19
17
|
|
|
20
18
|
var _RemoveComment = require("./mutations/RemoveComment");
|
|
21
19
|
|
|
20
|
+
var _RemoveNode = require("./mutations/RemoveNode");
|
|
21
|
+
|
|
22
22
|
var _RemoveStatement = require("./mutations/RemoveStatement");
|
|
23
23
|
|
|
24
24
|
var _ReplaceNode = require("./mutations/ReplaceNode");
|
|
25
25
|
|
|
26
26
|
var _ReplaceStatementWithMany = require("./mutations/ReplaceStatementWithMany");
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
39
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
30
|
+
*
|
|
31
|
+
* This source code is licensed under the MIT license found in the
|
|
32
|
+
* LICENSE file in the root directory of this source tree.
|
|
33
|
+
*
|
|
34
|
+
*
|
|
35
|
+
* @format
|
|
36
|
+
*/
|
|
40
37
|
function getTransformContext() {
|
|
41
38
|
/**
|
|
42
39
|
* The mutations in order of collection.
|
|
43
40
|
*/
|
|
44
|
-
|
|
41
|
+
const mutations = [];
|
|
45
42
|
|
|
46
43
|
function pushMutation(mutation) {
|
|
47
44
|
if (mutation != null) {
|
|
@@ -49,81 +46,126 @@ function getTransformContext() {
|
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
const cloneAPIs = {
|
|
50
|
+
shallowCloneNode: node => {
|
|
51
|
+
if (node == null) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
get astWasMutated() {
|
|
57
|
-
return mutations.length > 0;
|
|
55
|
+
return (0, _detachedNode.shallowCloneNode)(node);
|
|
58
56
|
},
|
|
59
|
-
|
|
60
57
|
// $FlowExpectedError[incompatible-exact]
|
|
61
|
-
|
|
58
|
+
shallowCloneNodeWithOverrides: (node, newProps) => {
|
|
62
59
|
if (node == null) {
|
|
63
60
|
return null;
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
return (0, _detachedNode.shallowCloneNode)(node, newProps);
|
|
67
64
|
},
|
|
68
|
-
shallowCloneArray:
|
|
65
|
+
shallowCloneArray: nodes => {
|
|
69
66
|
if (nodes == null) {
|
|
70
67
|
return null;
|
|
71
68
|
}
|
|
72
69
|
|
|
73
|
-
return nodes.map(
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
return nodes.map(node => (0, _detachedNode.shallowCloneNode)(node));
|
|
71
|
+
},
|
|
72
|
+
deepCloneNode: node => {
|
|
73
|
+
if (node == null) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return (0, _detachedNode.deepCloneNode)(node);
|
|
76
78
|
},
|
|
77
79
|
// $FlowExpectedError[incompatible-exact]
|
|
78
|
-
|
|
80
|
+
deepCloneNodeWithOverrides: (node, newProps) => {
|
|
79
81
|
if (node == null) {
|
|
80
82
|
return null;
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
return (0, _detachedNode.deepCloneNode)(node, newProps);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const commentAPIs = {
|
|
89
|
+
getComments: node => {
|
|
90
|
+
return [...(0, _comments.getCommentsForNode)(node)];
|
|
84
91
|
},
|
|
85
|
-
|
|
86
|
-
pushMutation((0, _InsertStatement.createInsertStatementMutation)('after', target, toArray(nodesToInsert)));
|
|
87
|
-
},
|
|
88
|
-
insertBeforeStatement: function (target, nodesToInsert) {
|
|
89
|
-
pushMutation((0, _InsertStatement.createInsertStatementMutation)('before', target, toArray(nodesToInsert)));
|
|
90
|
-
},
|
|
91
|
-
replaceNode: function (target, nodeToReplaceWith, options) {
|
|
92
|
-
pushMutation((0, _ReplaceNode.createReplaceNodeMutation)(target, nodeToReplaceWith, options));
|
|
93
|
-
},
|
|
94
|
-
replaceStatementWithMany: function (target, nodesToReplaceWith, options) {
|
|
95
|
-
pushMutation((0, _ReplaceStatementWithMany.createReplaceStatementWithManyMutation)(target, nodesToReplaceWith, options));
|
|
96
|
-
},
|
|
97
|
-
removeStatement: function (node) {
|
|
98
|
-
pushMutation((0, _RemoveStatement.createRemoveStatementMutation)(node));
|
|
99
|
-
},
|
|
100
|
-
//
|
|
101
|
-
// Comment APIs
|
|
102
|
-
//
|
|
103
|
-
getComments: function (node) {
|
|
104
|
-
return _toConsumableArray((0, _comments.getCommentsForNode)(node));
|
|
105
|
-
},
|
|
106
|
-
getLeadingComments: function (node) {
|
|
92
|
+
getLeadingComments: node => {
|
|
107
93
|
return (0, _comments.getCommentsForNode)(node).filter(_comments.isLeadingComment);
|
|
108
94
|
},
|
|
109
|
-
getTrailingComments:
|
|
95
|
+
getTrailingComments: node => {
|
|
110
96
|
return (0, _comments.getCommentsForNode)(node).filter(_comments.isTrailingComment);
|
|
111
97
|
},
|
|
112
|
-
cloneCommentsTo:
|
|
98
|
+
cloneCommentsTo: (target, destination) => {
|
|
113
99
|
pushMutation((0, _CloneCommentsTo.createCloneCommentsToMutation)(target, destination));
|
|
114
100
|
},
|
|
115
|
-
addLeadingComments:
|
|
116
|
-
pushMutation((0,
|
|
101
|
+
addLeadingComments: (node, comments) => {
|
|
102
|
+
pushMutation((0, _AddComments.createAddCommentsMutation)(node, toArray(comments).map(comment => ({
|
|
103
|
+
comment,
|
|
104
|
+
placement: _comments.CommentPlacement.LEADING_OWN_LINE
|
|
105
|
+
}))));
|
|
106
|
+
},
|
|
107
|
+
addLeadingInlineComments: (node, comments) => {
|
|
108
|
+
pushMutation((0, _AddComments.createAddCommentsMutation)(node, toArray(comments).map(comment => ({
|
|
109
|
+
comment,
|
|
110
|
+
placement: _comments.CommentPlacement.LEADING_INLINE
|
|
111
|
+
}))));
|
|
117
112
|
},
|
|
118
|
-
addTrailingComments:
|
|
119
|
-
pushMutation((0,
|
|
113
|
+
addTrailingComments: (node, comments) => {
|
|
114
|
+
pushMutation((0, _AddComments.createAddCommentsMutation)(node, toArray(comments).map(comment => ({
|
|
115
|
+
comment,
|
|
116
|
+
placement: _comments.CommentPlacement.TRAILING_OWN_LINE
|
|
117
|
+
}))));
|
|
120
118
|
},
|
|
121
|
-
|
|
122
|
-
toArray(comments).
|
|
119
|
+
addTrailingInlineComments: (node, comments) => {
|
|
120
|
+
pushMutation((0, _AddComments.createAddCommentsMutation)(node, toArray(comments).map(comment => ({
|
|
121
|
+
comment,
|
|
122
|
+
placement: _comments.CommentPlacement.TRAILING_INLINE
|
|
123
|
+
}))));
|
|
124
|
+
},
|
|
125
|
+
removeComments: comments => {
|
|
126
|
+
toArray(comments).forEach(comment => {
|
|
123
127
|
pushMutation((0, _RemoveComment.createRemoveCommentMutation)(comment));
|
|
124
128
|
});
|
|
125
129
|
}
|
|
126
130
|
};
|
|
131
|
+
const insertAPIs = {
|
|
132
|
+
insertAfterStatement: (target, nodesToInsert) => {
|
|
133
|
+
pushMutation((0, _InsertStatement.createInsertStatementMutation)('after', target, toArray(nodesToInsert)));
|
|
134
|
+
},
|
|
135
|
+
insertBeforeStatement: (target, nodesToInsert) => {
|
|
136
|
+
pushMutation((0, _InsertStatement.createInsertStatementMutation)('before', target, toArray(nodesToInsert)));
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const removeAPIs = {
|
|
140
|
+
removeNode: node => {
|
|
141
|
+
pushMutation((0, _RemoveNode.createRemoveNodeMutation)(node));
|
|
142
|
+
},
|
|
143
|
+
removeStatement: node => {
|
|
144
|
+
pushMutation((0, _RemoveStatement.createRemoveStatementMutation)(node));
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const replaceAPIs = {
|
|
148
|
+
replaceNode: (target, nodeToReplaceWith, options) => {
|
|
149
|
+
pushMutation((0, _ReplaceNode.createReplaceNodeMutation)(target, nodeToReplaceWith, options));
|
|
150
|
+
},
|
|
151
|
+
replaceStatementWithMany: (target, nodesToReplaceWith, options) => {
|
|
152
|
+
pushMutation((0, _ReplaceStatementWithMany.createReplaceStatementWithManyMutation)(target, nodesToReplaceWith, options));
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
mutations,
|
|
157
|
+
|
|
158
|
+
// $FlowExpectedError[unsafe-getters-setters]
|
|
159
|
+
get astWasMutated() {
|
|
160
|
+
return mutations.length > 0;
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
...cloneAPIs,
|
|
164
|
+
...commentAPIs,
|
|
165
|
+
...insertAPIs,
|
|
166
|
+
...removeAPIs,
|
|
167
|
+
...replaceAPIs
|
|
168
|
+
};
|
|
127
169
|
}
|
|
128
170
|
|
|
129
171
|
function toArray(thing) {
|