hermes-transform 0.5.0 → 0.6.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 +1761 -9
- package/dist/generated/TransformReplaceSignatures.js.flow +936 -774
- package/dist/generated/node-types.js +1117 -1132
- package/dist/generated/node-types.js.flow +26 -1
- 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 +7 -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 +1 -1
- package/dist/transform/TransformContext.js +106 -54
- package/dist/transform/TransformContext.js.flow +255 -121
- package/dist/transform/comments/comments.js +25 -25
- package/dist/transform/comments/comments.js.flow +1 -1
- 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 +85 -101
- package/dist/transform/getTransformedAST.js.flow +7 -2
- package/dist/transform/mutations/AddLeadingComments.js +15 -22
- package/dist/transform/mutations/AddLeadingComments.js.flow +1 -1
- package/dist/transform/mutations/AddTrailingComments.js +15 -22
- package/dist/transform/mutations/AddTrailingComments.js.flow +1 -1
- package/dist/transform/mutations/CloneCommentsTo.js +16 -23
- package/dist/transform/mutations/CloneCommentsTo.js.flow +1 -1
- package/dist/transform/mutations/InsertStatement.js +27 -30
- package/dist/transform/mutations/InsertStatement.js.flow +1 -1
- package/dist/transform/mutations/RemoveComment.js +25 -43
- package/dist/transform/mutations/RemoveComment.js.flow +1 -1
- package/dist/transform/mutations/RemoveNode.js +185 -0
- package/dist/transform/mutations/RemoveNode.js.flow +279 -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 +2 -14
- package/dist/transform/mutations/utils/arrayUtils.js.flow +1 -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 +20 -24
- package/dist/transform/transform.js.flow +12 -8
- 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 +39 -51
- package/dist/traverse/traverse.js.flow +1 -1
- package/package.json +4 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -8,20 +8,21 @@
|
|
|
8
8
|
*/
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const {
|
|
12
|
+
isNonEmptyArray
|
|
13
|
+
} = require('../common/util.js');
|
|
13
14
|
/**
|
|
14
15
|
* @typedef {import("./types/estree").Node} Node
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
function locStart(node, opts) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const {
|
|
21
|
+
ignoreDecorators
|
|
22
|
+
} = opts || {}; // Handle nodes with decorators. They should start at the first decorator
|
|
22
23
|
|
|
23
24
|
if (!ignoreDecorators) {
|
|
24
|
-
|
|
25
|
+
const decorators = node.declaration && node.declaration.decorators || node.decorators;
|
|
25
26
|
|
|
26
27
|
if (isNonEmptyArray(decorators)) {
|
|
27
28
|
return locStart(decorators[0]);
|
|
@@ -36,6 +37,6 @@ function locEnd(node) {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
module.exports = {
|
|
39
|
-
locStart
|
|
40
|
-
locEnd
|
|
40
|
+
locStart,
|
|
41
|
+
locEnd
|
|
41
42
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
'use strict';
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
const handleComments = require('./comments.js');
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const {
|
|
14
|
+
isBlockComment,
|
|
15
|
+
isLineComment
|
|
16
|
+
} = require('./utils.js');
|
|
16
17
|
|
|
17
18
|
function canAttachComment(node) {
|
|
18
19
|
return node.type && !isBlockComment(node) && !isLineComment(node) && node.type !== 'EmptyStatement' && node.type !== 'TemplateElement' && node.type !== 'Import' && // `babel-ts` don't have similar node for `class Foo { bar() /* bat */; }`
|
|
@@ -20,7 +21,7 @@ function canAttachComment(node) {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
module.exports = {
|
|
23
|
-
canAttachComment
|
|
24
|
+
canAttachComment,
|
|
24
25
|
handleComments: {
|
|
25
26
|
avoidAstMutation: true,
|
|
26
27
|
ownLine: handleComments.handleOwnLineComment,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -12,18 +12,6 @@
|
|
|
12
12
|
* @returns {boolean}
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
16
|
-
|
|
17
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
18
|
-
|
|
19
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
-
|
|
21
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
22
|
-
|
|
23
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
24
|
-
|
|
25
|
-
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; }
|
|
26
|
-
|
|
27
15
|
function isBlockComment(comment) {
|
|
28
16
|
return comment.type === 'Block' || comment.type === 'CommentBlock' || // `meriyah`
|
|
29
17
|
comment.type === 'MultiLine';
|
|
@@ -57,24 +45,24 @@ function isMemberExpression(node) {
|
|
|
57
45
|
return node && (node.type === 'MemberExpression' || node.type === 'OptionalMemberExpression');
|
|
58
46
|
}
|
|
59
47
|
|
|
60
|
-
|
|
48
|
+
const functionParametersCache = new WeakMap();
|
|
61
49
|
|
|
62
50
|
function getFunctionParameters(node) {
|
|
63
51
|
if (functionParametersCache.has(node)) {
|
|
64
52
|
return functionParametersCache.get(node);
|
|
65
53
|
}
|
|
66
54
|
|
|
67
|
-
|
|
55
|
+
const parameters = [];
|
|
68
56
|
|
|
69
|
-
if (node
|
|
70
|
-
parameters.push(node
|
|
57
|
+
if (node.this) {
|
|
58
|
+
parameters.push(node.this);
|
|
71
59
|
} // `params` vs `parameters` - see https://github.com/babel/babel/issues/9231
|
|
72
60
|
|
|
73
61
|
|
|
74
62
|
if (Array.isArray(node.parameters)) {
|
|
75
|
-
parameters.push
|
|
63
|
+
parameters.push(...node.parameters);
|
|
76
64
|
} else if (Array.isArray(node.params)) {
|
|
77
|
-
parameters.push
|
|
65
|
+
parameters.push(...node.params);
|
|
78
66
|
}
|
|
79
67
|
|
|
80
68
|
if (node.rest) {
|
|
@@ -85,14 +73,14 @@ function getFunctionParameters(node) {
|
|
|
85
73
|
return parameters;
|
|
86
74
|
}
|
|
87
75
|
|
|
88
|
-
|
|
76
|
+
const callArgumentsCache = new WeakMap();
|
|
89
77
|
|
|
90
78
|
function getCallArguments(node) {
|
|
91
79
|
if (callArgumentsCache.has(node)) {
|
|
92
80
|
return callArgumentsCache.get(node);
|
|
93
81
|
}
|
|
94
82
|
|
|
95
|
-
|
|
83
|
+
let args = node.arguments;
|
|
96
84
|
|
|
97
85
|
if (node.type === 'ImportExpression') {
|
|
98
86
|
args = [node.source];
|
|
@@ -119,13 +107,13 @@ function isObjectProperty(node) {
|
|
|
119
107
|
}
|
|
120
108
|
|
|
121
109
|
module.exports = {
|
|
122
|
-
getFunctionParameters
|
|
123
|
-
getCallArguments
|
|
124
|
-
isBlockComment
|
|
125
|
-
isCallLikeExpression
|
|
126
|
-
isLineComment
|
|
127
|
-
isPrettierIgnoreComment
|
|
128
|
-
isCallExpression
|
|
129
|
-
isMemberExpression
|
|
130
|
-
isObjectProperty
|
|
110
|
+
getFunctionParameters,
|
|
111
|
+
getCallArguments,
|
|
112
|
+
isBlockComment,
|
|
113
|
+
isCallLikeExpression,
|
|
114
|
+
isLineComment,
|
|
115
|
+
isPrettierIgnoreComment,
|
|
116
|
+
isCallExpression,
|
|
117
|
+
isMemberExpression,
|
|
118
|
+
isObjectProperty
|
|
131
119
|
};
|