hermes-transform 0.6.0 → 0.7.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/index.js.flow +2 -1
- package/dist/transform/MutationContext.js +2 -2
- package/dist/transform/MutationContext.js.flow +3 -2
- package/dist/transform/TransformContext.js +22 -32
- package/dist/transform/TransformContext.js.flow +72 -70
- package/dist/transform/comments/comments.js +112 -25
- package/dist/transform/comments/comments.js.flow +105 -28
- package/dist/transform/getTransformedAST.js +5 -12
- package/dist/transform/getTransformedAST.js.flow +13 -13
- package/dist/transform/mutations/{AddLeadingComments.js → AddComments.js} +11 -8
- package/dist/transform/mutations/AddComments.js.flow +50 -0
- package/dist/transform/mutations/CloneCommentsTo.js +1 -2
- package/dist/transform/mutations/CloneCommentsTo.js.flow +1 -2
- package/dist/transform/mutations/InsertStatement.js +1 -1
- package/dist/transform/mutations/InsertStatement.js.flow +1 -1
- package/dist/transform/mutations/utils/arrayUtils.js +14 -0
- package/dist/transform/mutations/utils/arrayUtils.js.flow +15 -0
- package/dist/transform/transform.js.flow +2 -2
- package/dist/traverse/traverse.js +27 -3
- package/dist/traverse/traverse.js.flow +62 -9
- package/package.json +4 -3
- package/dist/transform/mutations/AddLeadingComments.js.flow +0 -49
- package/dist/transform/mutations/AddTrailingComments.js +0 -40
- package/dist/transform/mutations/AddTrailingComments.js.flow +0 -49
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-transform",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Tools built on top of Hermes-ESTree to enable codebase transformation",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@babel/code-frame": "^7.16.0",
|
|
13
13
|
"esquery": "^1.4.0",
|
|
14
|
-
"
|
|
15
|
-
"hermes-
|
|
14
|
+
"flow-enums-runtime": "^0.0.6",
|
|
15
|
+
"hermes-eslint": "0.7.0",
|
|
16
|
+
"hermes-estree": "0.7.0"
|
|
16
17
|
},
|
|
17
18
|
"peerDependencies": {
|
|
18
19
|
"prettier": "^2.4.1"
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
* @flow strict-local
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {Comment, ESNode} from 'hermes-estree';
|
|
12
|
-
import type {DetachedNode} from '../../detachedNode';
|
|
13
|
-
import type {MutationContext} from '../MutationContext';
|
|
14
|
-
|
|
15
|
-
import {addLeadingComment, cloneComment} from '../comments/comments';
|
|
16
|
-
|
|
17
|
-
export type AddLeadingCommentsMutation = $ReadOnly<{
|
|
18
|
-
type: 'addLeadingComments',
|
|
19
|
-
comments: $ReadOnlyArray<Comment>,
|
|
20
|
-
node: ESNode | DetachedNode<ESNode>,
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
|
-
export function createAddLeadingCommentsMutation(
|
|
24
|
-
node: AddLeadingCommentsMutation['node'],
|
|
25
|
-
comments: AddLeadingCommentsMutation['comments'],
|
|
26
|
-
): ?AddLeadingCommentsMutation {
|
|
27
|
-
if (comments.length === 0) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
type: 'addLeadingComments',
|
|
33
|
-
comments,
|
|
34
|
-
node,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function performAddLeadingCommentsMutation(
|
|
39
|
-
mutationContext: MutationContext,
|
|
40
|
-
mutation: AddLeadingCommentsMutation,
|
|
41
|
-
): null {
|
|
42
|
-
for (const originalComment of mutation.comments) {
|
|
43
|
-
const comment = cloneComment(originalComment);
|
|
44
|
-
mutationContext.appendCommentToSource(comment);
|
|
45
|
-
addLeadingComment(mutation.node, comment);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createAddTrailingCommentsMutation = createAddTrailingCommentsMutation;
|
|
7
|
-
exports.performAddTrailingCommentsMutation = performAddTrailingCommentsMutation;
|
|
8
|
-
|
|
9
|
-
var _comments = require("../comments/comments");
|
|
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
|
-
function createAddTrailingCommentsMutation(node, comments) {
|
|
21
|
-
if (comments.length === 0) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
type: 'addTrailingComments',
|
|
27
|
-
comments,
|
|
28
|
-
node
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function performAddTrailingCommentsMutation(mutationContext, mutation) {
|
|
33
|
-
for (const originalComment of mutation.comments) {
|
|
34
|
-
const comment = (0, _comments.cloneComment)(originalComment);
|
|
35
|
-
mutationContext.appendCommentToSource(comment);
|
|
36
|
-
(0, _comments.addTrailingComment)(mutation.node, comment);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
* @flow strict-local
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type {Comment, ESNode} from 'hermes-estree';
|
|
12
|
-
import type {DetachedNode} from '../../detachedNode';
|
|
13
|
-
import type {MutationContext} from '../MutationContext';
|
|
14
|
-
|
|
15
|
-
import {addTrailingComment, cloneComment} from '../comments/comments';
|
|
16
|
-
|
|
17
|
-
export type AddTrailingCommentsMutation = $ReadOnly<{
|
|
18
|
-
type: 'addTrailingComments',
|
|
19
|
-
comments: $ReadOnlyArray<Comment>,
|
|
20
|
-
node: ESNode | DetachedNode<ESNode>,
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
|
-
export function createAddTrailingCommentsMutation(
|
|
24
|
-
node: AddTrailingCommentsMutation['node'],
|
|
25
|
-
comments: AddTrailingCommentsMutation['comments'],
|
|
26
|
-
): ?AddTrailingCommentsMutation {
|
|
27
|
-
if (comments.length === 0) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
type: 'addTrailingComments',
|
|
33
|
-
comments,
|
|
34
|
-
node,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function performAddTrailingCommentsMutation(
|
|
39
|
-
mutationContext: MutationContext,
|
|
40
|
-
mutation: AddTrailingCommentsMutation,
|
|
41
|
-
): null {
|
|
42
|
-
for (const originalComment of mutation.comments) {
|
|
43
|
-
const comment = cloneComment(originalComment);
|
|
44
|
-
mutationContext.appendCommentToSource(comment);
|
|
45
|
-
addTrailingComment(mutation.node, comment);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return null;
|
|
49
|
-
}
|