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,6 +8,10 @@
|
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
// lint directives to let us do some basic validation of generated files
|
|
12
|
+
/* eslint no-undef: 'error', no-unused-vars: ['error', {vars: "local"}], no-redeclare: 'error' */
|
|
13
|
+
/* global $NonMaybeType, $Partial, $ReadOnly, $ReadOnlyArray */
|
|
14
|
+
|
|
11
15
|
'use strict';
|
|
12
16
|
|
|
13
17
|
import type {
|
|
@@ -19,6 +23,7 @@ import type {
|
|
|
19
23
|
AssignmentExpression as AssignmentExpressionType,
|
|
20
24
|
AssignmentPattern as AssignmentPatternType,
|
|
21
25
|
AwaitExpression as AwaitExpressionType,
|
|
26
|
+
BigIntLiteralTypeAnnotation as BigIntLiteralTypeAnnotationType,
|
|
22
27
|
BinaryExpression as BinaryExpressionType,
|
|
23
28
|
BlockStatement as BlockStatementType,
|
|
24
29
|
BooleanLiteralTypeAnnotation as BooleanLiteralTypeAnnotationType,
|
|
@@ -202,6 +207,10 @@ export type AwaitExpressionProps = {
|
|
|
202
207
|
+argument: DetachedNode<AwaitExpressionType['argument']>,
|
|
203
208
|
};
|
|
204
209
|
|
|
210
|
+
export type BigIntLiteralTypeAnnotationProps = {
|
|
211
|
+
+raw: BigIntLiteralTypeAnnotationType['raw'],
|
|
212
|
+
};
|
|
213
|
+
|
|
205
214
|
export type BinaryExpressionProps = {
|
|
206
215
|
+left: DetachedNode<BinaryExpressionType['left']>,
|
|
207
216
|
+right: DetachedNode<BinaryExpressionType['right']>,
|
|
@@ -865,6 +874,7 @@ export type SpreadElementProps = {
|
|
|
865
874
|
|
|
866
875
|
export type StringLiteralTypeAnnotationProps = {
|
|
867
876
|
+value: StringLiteralTypeAnnotationType['value'],
|
|
877
|
+
+raw: StringLiteralTypeAnnotationType['raw'],
|
|
868
878
|
};
|
|
869
879
|
|
|
870
880
|
export type StringTypeAnnotationProps = {};
|
|
@@ -1106,6 +1116,21 @@ export function AwaitExpression({
|
|
|
1106
1116
|
return node;
|
|
1107
1117
|
}
|
|
1108
1118
|
|
|
1119
|
+
export function BigIntLiteralTypeAnnotation({
|
|
1120
|
+
parent,
|
|
1121
|
+
...props
|
|
1122
|
+
}: {
|
|
1123
|
+
...$ReadOnly<BigIntLiteralTypeAnnotationProps>,
|
|
1124
|
+
+parent?: ESNode,
|
|
1125
|
+
}): DetachedNode<BigIntLiteralTypeAnnotationType> {
|
|
1126
|
+
const node = detachedProps<BigIntLiteralTypeAnnotationType>(parent, {
|
|
1127
|
+
type: 'BigIntLiteralTypeAnnotation',
|
|
1128
|
+
...props,
|
|
1129
|
+
});
|
|
1130
|
+
setParentPointersInDirectChildren(node);
|
|
1131
|
+
return node;
|
|
1132
|
+
}
|
|
1133
|
+
|
|
1109
1134
|
export function BinaryExpression({
|
|
1110
1135
|
parent,
|
|
1111
1136
|
...props
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
7
|
+
exports.BigIntLiteral = BigIntLiteral;
|
|
7
8
|
exports.BlockComment = BlockComment;
|
|
8
9
|
exports.BooleanLiteral = BooleanLiteral;
|
|
9
10
|
exports.Identifier = Identifier;
|
|
@@ -16,81 +17,82 @@ exports.TemplateElement = TemplateElement;
|
|
|
16
17
|
|
|
17
18
|
var _detachedNode = require("../detachedNode");
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
function ArrowFunctionExpression(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
22
|
+
*
|
|
23
|
+
* This source code is licensed under the MIT license found in the
|
|
24
|
+
* LICENSE file in the root directory of this source tree.
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* @format
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
These are a number of special-case node creation functions that we can't auto-generate.
|
|
32
|
+
The list of exported functions here must be kept in sync with the `NODES_WITH_SPECIAL_HANDLING`
|
|
33
|
+
list in `scripts/genTransformNodeTypes` to ensure there's no duplicates
|
|
34
|
+
*/
|
|
35
|
+
function ArrowFunctionExpression({
|
|
36
|
+
parent,
|
|
37
|
+
...props
|
|
38
|
+
}) {
|
|
39
|
+
const node = (0, _detachedNode.detachedProps)(parent, {
|
|
39
40
|
type: 'ArrowFunctionExpression',
|
|
40
41
|
id: null,
|
|
41
42
|
// $FlowExpectedError[incompatible-use]
|
|
42
|
-
expression: props.body.type !== 'BlockStatement'
|
|
43
|
-
|
|
43
|
+
expression: props.body.type !== 'BlockStatement',
|
|
44
|
+
...props
|
|
45
|
+
});
|
|
44
46
|
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
45
47
|
return node;
|
|
46
48
|
} // pattern/flags are on a subobject in the estree spec, but are flat on the hermes types
|
|
47
49
|
// also the value is supposed to be a RegExp instance
|
|
48
50
|
|
|
49
51
|
|
|
50
|
-
function RegExpLiteral(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
function RegExpLiteral({
|
|
53
|
+
pattern,
|
|
54
|
+
flags,
|
|
55
|
+
parent
|
|
56
|
+
}) {
|
|
57
|
+
const value = new RegExp(pattern, flags);
|
|
55
58
|
return (0, _detachedNode.detachedProps)(parent, {
|
|
56
59
|
type: 'Literal',
|
|
57
|
-
value
|
|
60
|
+
value,
|
|
58
61
|
raw: value.toString(),
|
|
59
62
|
regex: {
|
|
60
|
-
pattern
|
|
61
|
-
flags
|
|
63
|
+
pattern,
|
|
64
|
+
flags
|
|
62
65
|
}
|
|
63
66
|
});
|
|
64
67
|
} // raw/cooked are on a subobject in the estree spec, but are flat on the hermes types
|
|
65
68
|
|
|
66
69
|
|
|
67
|
-
function TemplateElement(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
function TemplateElement({
|
|
71
|
+
tail,
|
|
72
|
+
parent,
|
|
73
|
+
...value
|
|
74
|
+
}) {
|
|
72
75
|
return (0, _detachedNode.detachedProps)(parent, {
|
|
73
76
|
type: 'TemplateElement',
|
|
74
|
-
tail
|
|
75
|
-
value
|
|
77
|
+
tail,
|
|
78
|
+
value
|
|
76
79
|
});
|
|
77
80
|
} // Identifier has a bunch of stuff that usually you don't want to provide - so we have
|
|
78
81
|
// this manual def to allow us to default some values
|
|
79
82
|
|
|
80
83
|
|
|
81
|
-
function Identifier(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var node = (0, _detachedNode.detachedProps)(parent, _objectSpread({
|
|
84
|
+
function Identifier({
|
|
85
|
+
parent,
|
|
86
|
+
optional = false,
|
|
87
|
+
typeAnnotation = null,
|
|
88
|
+
...props
|
|
89
|
+
}) {
|
|
90
|
+
const node = (0, _detachedNode.detachedProps)(parent, {
|
|
90
91
|
type: 'Identifier',
|
|
91
|
-
optional
|
|
92
|
-
typeAnnotation
|
|
93
|
-
|
|
92
|
+
optional,
|
|
93
|
+
typeAnnotation,
|
|
94
|
+
...props
|
|
95
|
+
});
|
|
94
96
|
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
95
97
|
return node;
|
|
96
98
|
} //
|
|
@@ -98,33 +100,49 @@ function Identifier(_ref4) {
|
|
|
98
100
|
//
|
|
99
101
|
|
|
100
102
|
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
function BigIntLiteral({
|
|
104
|
+
parent,
|
|
105
|
+
...props
|
|
106
|
+
}) {
|
|
107
|
+
var _props$raw;
|
|
108
|
+
|
|
109
|
+
const node = (0, _detachedNode.detachedProps)(parent, {
|
|
110
|
+
type: 'Literal',
|
|
111
|
+
...props,
|
|
112
|
+
raw: (_props$raw = props.raw) != null ? _props$raw : `${props.value}n`,
|
|
113
|
+
bigint: `${props.value}`
|
|
114
|
+
});
|
|
115
|
+
(0, _detachedNode.setParentPointersInDirectChildren)(node);
|
|
116
|
+
return node;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function BooleanLiteral({
|
|
120
|
+
parent,
|
|
121
|
+
value
|
|
122
|
+
}) {
|
|
104
123
|
return (0, _detachedNode.detachedProps)(parent, {
|
|
105
124
|
type: 'Literal',
|
|
106
125
|
raw: value ? 'true' : 'false',
|
|
107
|
-
value
|
|
126
|
+
value
|
|
108
127
|
});
|
|
109
128
|
}
|
|
110
129
|
|
|
111
|
-
function NumericLiteral(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
130
|
+
function NumericLiteral({
|
|
131
|
+
parent,
|
|
132
|
+
...props
|
|
133
|
+
}) {
|
|
134
|
+
var _props$raw2;
|
|
116
135
|
|
|
117
|
-
return (0, _detachedNode.detachedProps)(parent,
|
|
118
|
-
type: 'Literal'
|
|
119
|
-
|
|
120
|
-
raw: (_props$
|
|
121
|
-
})
|
|
136
|
+
return (0, _detachedNode.detachedProps)(parent, {
|
|
137
|
+
type: 'Literal',
|
|
138
|
+
...props,
|
|
139
|
+
raw: (_props$raw2 = props.raw) != null ? _props$raw2 : `${props.value}`
|
|
140
|
+
});
|
|
122
141
|
}
|
|
123
142
|
|
|
124
|
-
function NullLiteral(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
143
|
+
function NullLiteral({
|
|
144
|
+
parent
|
|
145
|
+
} = {}) {
|
|
128
146
|
return (0, _detachedNode.detachedProps)(parent, {
|
|
129
147
|
type: 'Literal',
|
|
130
148
|
value: null,
|
|
@@ -132,47 +150,50 @@ function NullLiteral() {
|
|
|
132
150
|
});
|
|
133
151
|
}
|
|
134
152
|
|
|
135
|
-
function StringLiteral(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
153
|
+
function StringLiteral({
|
|
154
|
+
parent,
|
|
155
|
+
raw: rawIn,
|
|
156
|
+
value
|
|
157
|
+
}) {
|
|
158
|
+
const hasSingleQuote = value.includes('"');
|
|
159
|
+
const hasDoubleQuote = value.includes("'");
|
|
160
|
+
let raw = rawIn;
|
|
142
161
|
|
|
143
162
|
if (raw == null) {
|
|
144
163
|
if (hasSingleQuote && hasDoubleQuote) {
|
|
145
|
-
raw =
|
|
164
|
+
raw = `'${value.replace(/'/g, "\\'")}'`;
|
|
146
165
|
} else if (hasSingleQuote) {
|
|
147
|
-
raw = "
|
|
166
|
+
raw = `"${value}"`;
|
|
148
167
|
} else {
|
|
149
|
-
raw =
|
|
168
|
+
raw = `'${value}'`;
|
|
150
169
|
}
|
|
151
170
|
}
|
|
152
171
|
|
|
153
172
|
return (0, _detachedNode.detachedProps)(parent, {
|
|
154
173
|
type: 'Literal',
|
|
155
|
-
raw
|
|
156
|
-
value
|
|
174
|
+
raw,
|
|
175
|
+
value
|
|
157
176
|
});
|
|
158
177
|
}
|
|
159
178
|
|
|
160
|
-
function LineComment(
|
|
161
|
-
|
|
179
|
+
function LineComment({
|
|
180
|
+
value
|
|
181
|
+
}) {
|
|
162
182
|
// $FlowExpectedError[prop-missing]
|
|
163
183
|
// $FlowExpectedError[incompatible-return]
|
|
164
184
|
return (0, _detachedNode.detachedProps)(undefined, {
|
|
165
185
|
type: 'Line',
|
|
166
|
-
value
|
|
186
|
+
value
|
|
167
187
|
});
|
|
168
188
|
}
|
|
169
189
|
|
|
170
|
-
function BlockComment(
|
|
171
|
-
|
|
190
|
+
function BlockComment({
|
|
191
|
+
value
|
|
192
|
+
}) {
|
|
172
193
|
// $FlowExpectedError[prop-missing]
|
|
173
194
|
// $FlowExpectedError[incompatible-return]
|
|
174
195
|
return (0, _detachedNode.detachedProps)(undefined, {
|
|
175
196
|
type: 'Block',
|
|
176
|
-
value
|
|
197
|
+
value
|
|
177
198
|
});
|
|
178
199
|
}
|
|
@@ -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.
|
|
@@ -20,6 +20,7 @@ import type {
|
|
|
20
20
|
RegExpLiteral as RegExpLiteralType,
|
|
21
21
|
TemplateElement as TemplateElementType,
|
|
22
22
|
Identifier as IdentifierType,
|
|
23
|
+
BigIntLiteral as BigIntLiteralType,
|
|
23
24
|
BooleanLiteral as BooleanLiteralType,
|
|
24
25
|
NumericLiteral as NumericLiteralType,
|
|
25
26
|
NullLiteral as NullLiteralType,
|
|
@@ -144,6 +145,31 @@ export function Identifier({
|
|
|
144
145
|
// Literals require a "raw" which is added by the estree transform, not hermes.
|
|
145
146
|
//
|
|
146
147
|
|
|
148
|
+
export type BigIntLiteralProps = {
|
|
149
|
+
+value: $FlowFixMe /* bigint | null */,
|
|
150
|
+
/**
|
|
151
|
+
* Only set this if you want to use a source-code representation like 1_1n, etc.
|
|
152
|
+
* By default "raw" will just be the exact number you've given.
|
|
153
|
+
*/
|
|
154
|
+
+raw?: NumericLiteralType['raw'],
|
|
155
|
+
};
|
|
156
|
+
export function BigIntLiteral({
|
|
157
|
+
parent,
|
|
158
|
+
...props
|
|
159
|
+
}: {
|
|
160
|
+
...$ReadOnly<BigIntLiteralProps>,
|
|
161
|
+
+parent?: ESNode,
|
|
162
|
+
}): DetachedNode<BigIntLiteralType> {
|
|
163
|
+
const node = detachedProps<BigIntLiteralType>(parent, {
|
|
164
|
+
type: 'Literal',
|
|
165
|
+
...props,
|
|
166
|
+
raw: props.raw ?? `${props.value}n`,
|
|
167
|
+
bigint: `${props.value}`,
|
|
168
|
+
});
|
|
169
|
+
setParentPointersInDirectChildren(node);
|
|
170
|
+
return node;
|
|
171
|
+
}
|
|
172
|
+
|
|
147
173
|
export type BooleanLiteralProps = {
|
|
148
174
|
+value: BooleanLiteralType['value'],
|
|
149
175
|
};
|
|
@@ -164,7 +190,7 @@ export function BooleanLiteral({
|
|
|
164
190
|
export type NumericLiteralProps = {
|
|
165
191
|
+value: NumericLiteralType['value'],
|
|
166
192
|
/**
|
|
167
|
-
* Only set this if you want to use a source-code representation like 1e100, 0x11, etc.
|
|
193
|
+
* Only set this if you want to use a source-code representation like 1e100, 0x11, 1_1, etc.
|
|
168
194
|
* By default "raw" will just be the exact number you've given.
|
|
169
195
|
*/
|
|
170
196
|
+raw?: NumericLiteralType['raw'],
|
package/dist/getVisitorKeys.js
CHANGED
|
@@ -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.
|
|
@@ -17,17 +17,15 @@ exports.isNode = isNode;
|
|
|
17
17
|
|
|
18
18
|
var _hermesEslint = require("hermes-eslint");
|
|
19
19
|
|
|
20
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
21
|
-
|
|
22
20
|
function isNode(thing) {
|
|
23
|
-
return
|
|
21
|
+
return typeof thing === 'object' && thing != null && typeof thing.type === 'string';
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
function getVisitorKeys(node) {
|
|
27
|
-
|
|
25
|
+
const keys = _hermesEslint.VisitorKeys[node.type];
|
|
28
26
|
|
|
29
27
|
if (keys == null) {
|
|
30
|
-
throw new Error(
|
|
28
|
+
throw new Error(`No visitor keys found for node type "${node.type}".`);
|
|
31
29
|
} // $FlowExpectedError[prop-missing]
|
|
32
30
|
|
|
33
31
|
|
package/dist/index.js
CHANGED
|
@@ -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.
|
|
@@ -9,33 +9,28 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
13
|
-
|
|
14
12
|
Object.defineProperty(exports, "__esModule", {
|
|
15
13
|
value: true
|
|
16
14
|
});
|
|
17
|
-
exports.t = void 0;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "traverse", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function get() {
|
|
27
|
-
return _traverse.traverse;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
15
|
+
exports.traverseWithContext = exports.traverse = exports.transform = exports.t = exports.SimpleTraverser = void 0;
|
|
16
|
+
|
|
17
|
+
var _SimpleTraverser = require("./traverse/SimpleTraverser");
|
|
18
|
+
|
|
19
|
+
exports.SimpleTraverser = _SimpleTraverser.SimpleTraverser;
|
|
30
20
|
|
|
31
21
|
var _traverse = require("./traverse/traverse");
|
|
32
22
|
|
|
23
|
+
exports.traverse = _traverse.traverse;
|
|
24
|
+
exports.traverseWithContext = _traverse.traverseWithContext;
|
|
25
|
+
|
|
33
26
|
var _transform = require("./transform/transform");
|
|
34
27
|
|
|
28
|
+
exports.transform = _transform.transform;
|
|
29
|
+
|
|
35
30
|
var _t = _interopRequireWildcard(require("./generated/node-types"));
|
|
36
31
|
|
|
37
32
|
exports.t = _t;
|
|
38
33
|
|
|
39
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
34
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
40
35
|
|
|
41
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
36
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
package/dist/index.js.flow
CHANGED
|
@@ -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.
|
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
export {
|
|
13
|
+
export type {TraversalContext, Visitor} from './traverse/traverse';
|
|
14
|
+
export type {TransformVisitor} from './transform/transform';
|
|
15
|
+
export type {DetachedNode} from './detachedNode';
|
|
16
|
+
|
|
17
|
+
export {SimpleTraverser} from './traverse/SimpleTraverser';
|
|
18
|
+
export {traverse, traverseWithContext} from './traverse/traverse';
|
|
14
19
|
export {transform} from './transform/transform';
|
|
15
20
|
export * as t from './generated/node-types';
|
package/dist/transform/Errors.js
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.UnexpectedTransformationState = exports.NodeIsMutatedError = exports.NodeIsDeletedError = exports.InvalidStatementError = exports.InvalidReplacementError = exports.InvalidRemovalError = exports.InvalidInsertionError = void 0;
|
|
9
7
|
|
|
10
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
-
|
|
12
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
13
|
-
|
|
14
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
15
|
-
|
|
16
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
17
|
-
|
|
18
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
19
|
-
|
|
20
|
-
function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
|
21
|
-
|
|
22
|
-
function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
|
23
|
-
|
|
24
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
25
|
-
|
|
26
|
-
function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
|
27
|
-
|
|
28
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
29
|
-
|
|
30
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
31
|
-
|
|
32
8
|
/**
|
|
33
|
-
* Copyright (c)
|
|
9
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
34
10
|
*
|
|
35
11
|
* This source code is licensed under the MIT license found in the
|
|
36
12
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -38,114 +14,30 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
38
14
|
*
|
|
39
15
|
* @format
|
|
40
16
|
*/
|
|
41
|
-
|
|
42
|
-
_inherits(NodeIsDeletedError, _Error);
|
|
43
|
-
|
|
44
|
-
var _super = _createSuper(NodeIsDeletedError);
|
|
45
|
-
|
|
46
|
-
function NodeIsDeletedError() {
|
|
47
|
-
_classCallCheck(this, NodeIsDeletedError);
|
|
48
|
-
|
|
49
|
-
return _super.apply(this, arguments);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return NodeIsDeletedError;
|
|
53
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
17
|
+
class NodeIsDeletedError extends Error {}
|
|
54
18
|
|
|
55
19
|
exports.NodeIsDeletedError = NodeIsDeletedError;
|
|
56
20
|
|
|
57
|
-
|
|
58
|
-
_inherits(NodeIsMutatedError, _Error2);
|
|
59
|
-
|
|
60
|
-
var _super2 = _createSuper(NodeIsMutatedError);
|
|
61
|
-
|
|
62
|
-
function NodeIsMutatedError() {
|
|
63
|
-
_classCallCheck(this, NodeIsMutatedError);
|
|
64
|
-
|
|
65
|
-
return _super2.apply(this, arguments);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return NodeIsMutatedError;
|
|
69
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
21
|
+
class NodeIsMutatedError extends Error {}
|
|
70
22
|
|
|
71
23
|
exports.NodeIsMutatedError = NodeIsMutatedError;
|
|
72
24
|
|
|
73
|
-
|
|
74
|
-
_inherits(InvalidInsertionError, _Error3);
|
|
75
|
-
|
|
76
|
-
var _super3 = _createSuper(InvalidInsertionError);
|
|
77
|
-
|
|
78
|
-
function InvalidInsertionError() {
|
|
79
|
-
_classCallCheck(this, InvalidInsertionError);
|
|
80
|
-
|
|
81
|
-
return _super3.apply(this, arguments);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return InvalidInsertionError;
|
|
85
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
25
|
+
class InvalidInsertionError extends Error {}
|
|
86
26
|
|
|
87
27
|
exports.InvalidInsertionError = InvalidInsertionError;
|
|
88
28
|
|
|
89
|
-
|
|
90
|
-
_inherits(UnexpectedTransformationState, _Error4);
|
|
91
|
-
|
|
92
|
-
var _super4 = _createSuper(UnexpectedTransformationState);
|
|
93
|
-
|
|
94
|
-
function UnexpectedTransformationState() {
|
|
95
|
-
_classCallCheck(this, UnexpectedTransformationState);
|
|
96
|
-
|
|
97
|
-
return _super4.apply(this, arguments);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return UnexpectedTransformationState;
|
|
101
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
29
|
+
class UnexpectedTransformationState extends Error {}
|
|
102
30
|
|
|
103
31
|
exports.UnexpectedTransformationState = UnexpectedTransformationState;
|
|
104
32
|
|
|
105
|
-
|
|
106
|
-
_inherits(InvalidStatementError, _Error5);
|
|
107
|
-
|
|
108
|
-
var _super5 = _createSuper(InvalidStatementError);
|
|
109
|
-
|
|
110
|
-
function InvalidStatementError() {
|
|
111
|
-
_classCallCheck(this, InvalidStatementError);
|
|
112
|
-
|
|
113
|
-
return _super5.apply(this, arguments);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return InvalidStatementError;
|
|
117
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
33
|
+
class InvalidStatementError extends Error {}
|
|
118
34
|
|
|
119
35
|
exports.InvalidStatementError = InvalidStatementError;
|
|
120
36
|
|
|
121
|
-
|
|
122
|
-
_inherits(InvalidRemovalError, _Error6);
|
|
123
|
-
|
|
124
|
-
var _super6 = _createSuper(InvalidRemovalError);
|
|
125
|
-
|
|
126
|
-
function InvalidRemovalError() {
|
|
127
|
-
_classCallCheck(this, InvalidRemovalError);
|
|
128
|
-
|
|
129
|
-
return _super6.apply(this, arguments);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return InvalidRemovalError;
|
|
133
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
37
|
+
class InvalidRemovalError extends Error {}
|
|
134
38
|
|
|
135
39
|
exports.InvalidRemovalError = InvalidRemovalError;
|
|
136
40
|
|
|
137
|
-
|
|
138
|
-
_inherits(InvalidReplacementError, _Error7);
|
|
139
|
-
|
|
140
|
-
var _super7 = _createSuper(InvalidReplacementError);
|
|
141
|
-
|
|
142
|
-
function InvalidReplacementError() {
|
|
143
|
-
_classCallCheck(this, InvalidReplacementError);
|
|
144
|
-
|
|
145
|
-
return _super7.apply(this, arguments);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return InvalidReplacementError;
|
|
149
|
-
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
41
|
+
class InvalidReplacementError extends Error {}
|
|
150
42
|
|
|
151
43
|
exports.InvalidReplacementError = InvalidReplacementError;
|