hermes-transform 0.32.0 → 0.32.1
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/src/transform/comments/comments.js +7 -4
- package/dist/src/transform/mutations/ModifyNodeInPlace.js +1 -0
- package/dist/src/transform/mutations/RemoveNode.js +3 -1
- package/dist/src/transform/mutations/ReplaceNode.js +1 -0
- package/dist/src/transform/mutations/utils/getStatementParent.js +3 -1
- package/dist/transform/comments/comments.js +7 -4
- package/dist/transform/comments/comments.js.flow +7 -4
- package/dist/transform/mutations/ModifyNodeInPlace.js +1 -0
- package/dist/transform/mutations/ModifyNodeInPlace.js.flow +1 -0
- package/dist/transform/mutations/RemoveNode.js +3 -1
- package/dist/transform/mutations/RemoveNode.js.flow +3 -0
- package/dist/transform/mutations/ReplaceNode.js +1 -0
- package/dist/transform/mutations/ReplaceNode.js.flow +1 -0
- package/dist/transform/mutations/utils/getStatementParent.js +3 -1
- package/dist/transform/mutations/utils/getStatementParent.js.flow +2 -0
- package/package.json +4 -4
|
@@ -128,14 +128,17 @@ function cloneJSDocCommentsToNewNode(oldNode, newNode) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
function setCommentsOnNode(node, comments) {
|
|
131
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
131
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
132
|
+
// $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
|
|
133
|
+
// $FlowExpectedError[cannot-write] - this property is secretly added by prettier.
|
|
132
134
|
node.comments = comments;
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
function getCommentsForNode(node) {
|
|
136
138
|
var _node$comments;
|
|
137
139
|
|
|
138
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
140
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
141
|
+
// $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
|
|
139
142
|
return (_node$comments = node.comments) != null ? _node$comments : [];
|
|
140
143
|
}
|
|
141
144
|
|
|
@@ -146,12 +149,12 @@ function isAttachedComment(comment) {
|
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
function isLeadingComment(comment) {
|
|
149
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
152
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
150
153
|
return comment.leading === true;
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
function isTrailingComment(comment) {
|
|
154
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
157
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
155
158
|
return comment.trailing === true;
|
|
156
159
|
}
|
|
157
160
|
|
|
@@ -33,6 +33,7 @@ function performModifyNodeInPlaceMutation(mutationContext, mutation) {
|
|
|
33
33
|
|
|
34
34
|
for (const [key, newPropValue] of Object.entries(newProps)) {
|
|
35
35
|
const prevPropValue = target[key]; // If the value did not change, skip.
|
|
36
|
+
// $FlowFixMe[invalid-compare]
|
|
36
37
|
|
|
37
38
|
if (prevPropValue === newPropValue) {
|
|
38
39
|
continue;
|
|
@@ -140,6 +140,7 @@ function getRemovalParent(node) {
|
|
|
140
140
|
case 'ObjectPattern':
|
|
141
141
|
return 'properties';
|
|
142
142
|
// $FlowFixMe[incompatible-type]
|
|
143
|
+
// $FlowFixMe[invalid-compare]
|
|
143
144
|
|
|
144
145
|
case 'OptionalCallExpression':
|
|
145
146
|
case 'CallExpression':
|
|
@@ -160,6 +161,7 @@ function getRemovalParent(node) {
|
|
|
160
161
|
case 'ObjectExpression':
|
|
161
162
|
return 'properties';
|
|
162
163
|
// $FlowFixMe[incompatible-type]
|
|
164
|
+
// $FlowFixMe[invalid-compare]
|
|
163
165
|
|
|
164
166
|
case 'OptionalCallExpression':
|
|
165
167
|
case 'CallExpression':
|
|
@@ -178,7 +180,7 @@ function getRemovalParent(node) {
|
|
|
178
180
|
const targetIndex = (() => {
|
|
179
181
|
// $FlowExpectedError[prop-missing]
|
|
180
182
|
const arr = node.parent[key];
|
|
181
|
-
const idx = arr.indexOf(node);
|
|
183
|
+
const idx = arr.indexOf(node); // $FlowFixMe[invalid-compare]
|
|
182
184
|
|
|
183
185
|
if (idx === -1) {
|
|
184
186
|
throw new _Errors.InvalidRemovalError(`Could not find target in array of \`${node.parent.type}.${key}\`.`);
|
|
@@ -22,7 +22,8 @@ function getStatementParent(target) {
|
|
|
22
22
|
// $FlowExpectedError[prop-missing]
|
|
23
23
|
const value = parentWithType[key];
|
|
24
24
|
|
|
25
|
-
if (
|
|
25
|
+
if ( // $FlowFixMe[invalid-compare]
|
|
26
|
+
value === target || Array.isArray(value) && value.includes(target)) {
|
|
26
27
|
throw new _Errors.InvalidStatementError(`Attempted to insert a statement into \`${parentWithType.type}.${key}\`.`);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -135,6 +136,7 @@ function getStatementParent(target) {
|
|
|
135
136
|
|
|
136
137
|
if ( // array insertions are already validated by the getAssertedIndex function
|
|
137
138
|
result.targetIndex == null && // $FlowExpectedError[prop-missing]
|
|
139
|
+
// $FlowFixMe[invalid-compare]
|
|
138
140
|
result.parent[result.key] !== target) {
|
|
139
141
|
throw new _Errors.InvalidStatementError(`Expected to find the target "${target.type}" on the "${result.parent.type}.${result.key}", but found a different node. ` + 'This likely means that you attempted to mutate around the target after it was deleted/replaced.');
|
|
140
142
|
}
|
|
@@ -128,14 +128,17 @@ function cloneJSDocCommentsToNewNode(oldNode, newNode) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
function setCommentsOnNode(node, comments) {
|
|
131
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
131
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
132
|
+
// $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
|
|
133
|
+
// $FlowExpectedError[cannot-write] - this property is secretly added by prettier.
|
|
132
134
|
node.comments = comments;
|
|
133
135
|
}
|
|
134
136
|
|
|
135
137
|
function getCommentsForNode(node) {
|
|
136
138
|
var _node$comments;
|
|
137
139
|
|
|
138
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
140
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
141
|
+
// $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
|
|
139
142
|
return (_node$comments = node.comments) != null ? _node$comments : [];
|
|
140
143
|
}
|
|
141
144
|
|
|
@@ -146,12 +149,12 @@ function isAttachedComment(comment) {
|
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
function isLeadingComment(comment) {
|
|
149
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
152
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
150
153
|
return comment.leading === true;
|
|
151
154
|
}
|
|
152
155
|
|
|
153
156
|
function isTrailingComment(comment) {
|
|
154
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
157
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
155
158
|
return comment.trailing === true;
|
|
156
159
|
}
|
|
157
160
|
|
|
@@ -147,14 +147,17 @@ export function setCommentsOnNode(
|
|
|
147
147
|
node: ESNode | DetachedNode<ESNode>,
|
|
148
148
|
comments: $ReadOnlyArray<Comment>,
|
|
149
149
|
): void {
|
|
150
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
150
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
151
|
+
// $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
|
|
152
|
+
// $FlowExpectedError[cannot-write] - this property is secretly added by prettier.
|
|
151
153
|
node.comments = comments;
|
|
152
154
|
}
|
|
153
155
|
|
|
154
156
|
export function getCommentsForNode(
|
|
155
157
|
node: ESNode | DetachedNode<ESNode>,
|
|
156
158
|
): $ReadOnlyArray<Comment> {
|
|
157
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
159
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
160
|
+
// $FlowExpectedError[incompatible-use] - this property is secretly added by prettier.
|
|
158
161
|
return node.comments ?? [];
|
|
159
162
|
}
|
|
160
163
|
|
|
@@ -165,11 +168,11 @@ export function isAttachedComment(comment: Comment): boolean {
|
|
|
165
168
|
}
|
|
166
169
|
|
|
167
170
|
export function isLeadingComment(comment: Comment): boolean {
|
|
168
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
171
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
169
172
|
return comment.leading === true;
|
|
170
173
|
}
|
|
171
174
|
export function isTrailingComment(comment: Comment): boolean {
|
|
172
|
-
// $FlowExpectedError - this property is secretly added by prettier.
|
|
175
|
+
// $FlowExpectedError[prop-missing] - this property is secretly added by prettier.
|
|
173
176
|
return comment.trailing === true;
|
|
174
177
|
}
|
|
175
178
|
|
|
@@ -33,6 +33,7 @@ function performModifyNodeInPlaceMutation(mutationContext, mutation) {
|
|
|
33
33
|
|
|
34
34
|
for (const [key, newPropValue] of Object.entries(newProps)) {
|
|
35
35
|
const prevPropValue = target[key]; // If the value did not change, skip.
|
|
36
|
+
// $FlowFixMe[invalid-compare]
|
|
36
37
|
|
|
37
38
|
if (prevPropValue === newPropValue) {
|
|
38
39
|
continue;
|
|
@@ -140,6 +140,7 @@ function getRemovalParent(node) {
|
|
|
140
140
|
case 'ObjectPattern':
|
|
141
141
|
return 'properties';
|
|
142
142
|
// $FlowFixMe[incompatible-type]
|
|
143
|
+
// $FlowFixMe[invalid-compare]
|
|
143
144
|
|
|
144
145
|
case 'OptionalCallExpression':
|
|
145
146
|
case 'CallExpression':
|
|
@@ -160,6 +161,7 @@ function getRemovalParent(node) {
|
|
|
160
161
|
case 'ObjectExpression':
|
|
161
162
|
return 'properties';
|
|
162
163
|
// $FlowFixMe[incompatible-type]
|
|
164
|
+
// $FlowFixMe[invalid-compare]
|
|
163
165
|
|
|
164
166
|
case 'OptionalCallExpression':
|
|
165
167
|
case 'CallExpression':
|
|
@@ -178,7 +180,7 @@ function getRemovalParent(node) {
|
|
|
178
180
|
const targetIndex = (() => {
|
|
179
181
|
// $FlowExpectedError[prop-missing]
|
|
180
182
|
const arr = node.parent[key];
|
|
181
|
-
const idx = arr.indexOf(node);
|
|
183
|
+
const idx = arr.indexOf(node); // $FlowFixMe[invalid-compare]
|
|
182
184
|
|
|
183
185
|
if (idx === -1) {
|
|
184
186
|
throw new _Errors.InvalidRemovalError(`Could not find target in array of \`${node.parent.type}.${key}\`.`);
|
|
@@ -216,6 +216,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
|
|
|
216
216
|
return 'properties';
|
|
217
217
|
|
|
218
218
|
// $FlowFixMe[incompatible-type]
|
|
219
|
+
// $FlowFixMe[invalid-compare]
|
|
219
220
|
case 'OptionalCallExpression':
|
|
220
221
|
case 'CallExpression':
|
|
221
222
|
case 'NewExpression':
|
|
@@ -247,6 +248,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
|
|
|
247
248
|
return 'properties';
|
|
248
249
|
|
|
249
250
|
// $FlowFixMe[incompatible-type]
|
|
251
|
+
// $FlowFixMe[invalid-compare]
|
|
250
252
|
case 'OptionalCallExpression':
|
|
251
253
|
case 'CallExpression':
|
|
252
254
|
case 'NewExpression':
|
|
@@ -275,6 +277,7 @@ function getRemovalParent(node: RemoveNodeMutation['node']): $ReadOnly<{
|
|
|
275
277
|
// $FlowExpectedError[prop-missing]
|
|
276
278
|
const arr = node.parent[key];
|
|
277
279
|
const idx = arr.indexOf(node);
|
|
280
|
+
// $FlowFixMe[invalid-compare]
|
|
278
281
|
if (idx === -1) {
|
|
279
282
|
throw new InvalidRemovalError(
|
|
280
283
|
`Could not find target in array of \`${node.parent.type}.${key}\`.`,
|
|
@@ -90,6 +90,7 @@ function getParentKey(target: ESNode): $ReadOnly<
|
|
|
90
90
|
for (const key of getVisitorKeys(parent)) {
|
|
91
91
|
const child = (parent: $FlowFixMe)[key];
|
|
92
92
|
if (isNode(child)) {
|
|
93
|
+
// $FlowFixMe[invalid-compare]
|
|
93
94
|
if (child === target) {
|
|
94
95
|
return {type: 'single', parent, key};
|
|
95
96
|
}
|
|
@@ -22,7 +22,8 @@ function getStatementParent(target) {
|
|
|
22
22
|
// $FlowExpectedError[prop-missing]
|
|
23
23
|
const value = parentWithType[key];
|
|
24
24
|
|
|
25
|
-
if (
|
|
25
|
+
if ( // $FlowFixMe[invalid-compare]
|
|
26
|
+
value === target || Array.isArray(value) && value.includes(target)) {
|
|
26
27
|
throw new _Errors.InvalidStatementError(`Attempted to insert a statement into \`${parentWithType.type}.${key}\`.`);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -135,6 +136,7 @@ function getStatementParent(target) {
|
|
|
135
136
|
|
|
136
137
|
if ( // array insertions are already validated by the getAssertedIndex function
|
|
137
138
|
result.targetIndex == null && // $FlowExpectedError[prop-missing]
|
|
139
|
+
// $FlowFixMe[invalid-compare]
|
|
138
140
|
result.parent[result.key] !== target) {
|
|
139
141
|
throw new _Errors.InvalidStatementError(`Expected to find the target "${target.type}" on the "${result.parent.type}.${result.key}", but found a different node. ` + 'This likely means that you attempted to mutate around the target after it was deleted/replaced.');
|
|
140
142
|
}
|
|
@@ -45,6 +45,7 @@ export function getStatementParent(
|
|
|
45
45
|
const value = parentWithType[key];
|
|
46
46
|
|
|
47
47
|
if (
|
|
48
|
+
// $FlowFixMe[invalid-compare]
|
|
48
49
|
value === target ||
|
|
49
50
|
(Array.isArray(value) && value.includes(target))
|
|
50
51
|
) {
|
|
@@ -136,6 +137,7 @@ export function getStatementParent(
|
|
|
136
137
|
// array insertions are already validated by the getAssertedIndex function
|
|
137
138
|
result.targetIndex == null &&
|
|
138
139
|
// $FlowExpectedError[prop-missing]
|
|
140
|
+
// $FlowFixMe[invalid-compare]
|
|
139
141
|
result.parent[result.key] !== target
|
|
140
142
|
) {
|
|
141
143
|
throw new InvalidStatementError(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-transform",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"description": "Tools built on top of Hermes-ESTree to enable codebase transformation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"@babel/code-frame": "^7.16.0",
|
|
13
13
|
"esquery": "^1.4.0",
|
|
14
14
|
"flow-enums-runtime": "^0.0.6",
|
|
15
|
-
"hermes-eslint": "0.32.
|
|
16
|
-
"hermes-estree": "0.32.
|
|
17
|
-
"hermes-parser": "0.32.
|
|
15
|
+
"hermes-eslint": "0.32.1",
|
|
16
|
+
"hermes-estree": "0.32.1",
|
|
17
|
+
"hermes-parser": "0.32.1",
|
|
18
18
|
"string-width": "4.2.3"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|