hermes-estree 0.28.1 → 0.29.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/generated/HermesESTreeSelectorTypes.js.flow +12 -7
- package/dist/src/generated/predicates.js +2944 -0
- package/dist/src/index.js +22 -0
- package/dist/src/predicates.js +250 -0
- package/dist/src/selectors.js +14 -0
- package/dist/src/types.js +39 -0
- package/dist/types.js.flow +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var _predicates = require("./predicates");
|
|
17
|
+
|
|
18
|
+
Object.keys(_predicates).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _predicates[key]) return;
|
|
21
|
+
exports[key] = _predicates[key];
|
|
22
|
+
});
|
|
@@ -0,0 +1,250 @@
|
|
|
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
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
'use strict';
|
|
10
|
+
/*::
|
|
11
|
+
import type {
|
|
12
|
+
ESNode,
|
|
13
|
+
Token,
|
|
14
|
+
MostTokens,
|
|
15
|
+
BlockComment,
|
|
16
|
+
LineComment,
|
|
17
|
+
AFunction,
|
|
18
|
+
PropertyDefinition,
|
|
19
|
+
PropertyDefinitionWithNonComputedName,
|
|
20
|
+
MethodDefinition,
|
|
21
|
+
MethodDefinitionConstructor,
|
|
22
|
+
MethodDefinitionWithNonComputedName,
|
|
23
|
+
MemberExpression,
|
|
24
|
+
MemberExpressionWithNonComputedName,
|
|
25
|
+
ObjectPropertyWithShorthandStaticName,
|
|
26
|
+
ObjectPropertyWithNonShorthandStaticName,
|
|
27
|
+
DestructuringObjectPropertyWithShorthandStaticName,
|
|
28
|
+
DestructuringObjectPropertyWithNonShorthandStaticName,
|
|
29
|
+
ClassMember,
|
|
30
|
+
ClassDeclaration,
|
|
31
|
+
ClassExpression,
|
|
32
|
+
Literal,
|
|
33
|
+
BigIntLiteral,
|
|
34
|
+
BooleanLiteral,
|
|
35
|
+
NullLiteral,
|
|
36
|
+
NumericLiteral,
|
|
37
|
+
RegExpLiteral,
|
|
38
|
+
StringLiteral,
|
|
39
|
+
Identifier,
|
|
40
|
+
EnumDefaultedMember,
|
|
41
|
+
Expression,
|
|
42
|
+
Statement,
|
|
43
|
+
} from './types';
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
Object.defineProperty(exports, "__esModule", {
|
|
47
|
+
value: true
|
|
48
|
+
});
|
|
49
|
+
var _exportNames = {
|
|
50
|
+
isClass: true,
|
|
51
|
+
isPropertyDefinitionWithNonComputedName: true,
|
|
52
|
+
isClassMember: true,
|
|
53
|
+
isClassMemberWithNonComputedName: true,
|
|
54
|
+
isComment: true,
|
|
55
|
+
isFunction: true,
|
|
56
|
+
isMethodDefinitionWithNonComputedName: true,
|
|
57
|
+
isMemberExpressionWithNonComputedProperty: true,
|
|
58
|
+
isOptionalMemberExpressionWithNonComputedProperty: true,
|
|
59
|
+
isObjectPropertyWithShorthand: true,
|
|
60
|
+
isObjectPropertyWithNonComputedName: true,
|
|
61
|
+
isBigIntLiteral: true,
|
|
62
|
+
isBooleanLiteral: true,
|
|
63
|
+
isNullLiteral: true,
|
|
64
|
+
isNumericLiteral: true,
|
|
65
|
+
isRegExpLiteral: true,
|
|
66
|
+
isStringLiteral: true,
|
|
67
|
+
isExpression: true,
|
|
68
|
+
isStatement: true
|
|
69
|
+
};
|
|
70
|
+
exports.isBigIntLiteral = isBigIntLiteral;
|
|
71
|
+
exports.isBooleanLiteral = isBooleanLiteral;
|
|
72
|
+
exports.isClass = isClass;
|
|
73
|
+
exports.isClassMember = isClassMember;
|
|
74
|
+
exports.isClassMemberWithNonComputedName = isClassMemberWithNonComputedName;
|
|
75
|
+
exports.isComment = isComment;
|
|
76
|
+
exports.isExpression = isExpression;
|
|
77
|
+
exports.isFunction = isFunction;
|
|
78
|
+
exports.isMemberExpressionWithNonComputedProperty = isMemberExpressionWithNonComputedProperty;
|
|
79
|
+
exports.isMethodDefinitionWithNonComputedName = isMethodDefinitionWithNonComputedName;
|
|
80
|
+
exports.isNullLiteral = isNullLiteral;
|
|
81
|
+
exports.isNumericLiteral = isNumericLiteral;
|
|
82
|
+
exports.isObjectPropertyWithNonComputedName = isObjectPropertyWithNonComputedName;
|
|
83
|
+
exports.isObjectPropertyWithShorthand = isObjectPropertyWithShorthand;
|
|
84
|
+
exports.isOptionalMemberExpressionWithNonComputedProperty = isOptionalMemberExpressionWithNonComputedProperty;
|
|
85
|
+
exports.isPropertyDefinitionWithNonComputedName = isPropertyDefinitionWithNonComputedName;
|
|
86
|
+
exports.isRegExpLiteral = isRegExpLiteral;
|
|
87
|
+
exports.isStatement = isStatement;
|
|
88
|
+
exports.isStringLiteral = isStringLiteral;
|
|
89
|
+
|
|
90
|
+
var _predicates = require("./generated/predicates");
|
|
91
|
+
|
|
92
|
+
Object.keys(_predicates).forEach(function (key) {
|
|
93
|
+
if (key === "default" || key === "__esModule") return;
|
|
94
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
95
|
+
if (key in exports && exports[key] === _predicates[key]) return;
|
|
96
|
+
exports[key] = _predicates[key];
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
function isClass(node
|
|
100
|
+
/*: ESNode */
|
|
101
|
+
)
|
|
102
|
+
/*: implies node is (ClassDeclaration | ClassExpression) */
|
|
103
|
+
{
|
|
104
|
+
return node.type === 'ClassDeclaration' || node.type === 'ClassExpression';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isPropertyDefinitionWithNonComputedName(node
|
|
108
|
+
/*: ESNode */
|
|
109
|
+
)
|
|
110
|
+
/*: implies node is PropertyDefinitionWithNonComputedName */
|
|
111
|
+
{
|
|
112
|
+
return node.type === 'PropertyDefinition' && node.computed === false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function isClassMember(node
|
|
116
|
+
/*: ESNode */
|
|
117
|
+
)
|
|
118
|
+
/*: implies node is ClassMember */
|
|
119
|
+
{
|
|
120
|
+
return node.type === 'PropertyDefinition' || node.type === 'MethodDefinition';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function isClassMemberWithNonComputedName(node
|
|
124
|
+
/*: ESNode */
|
|
125
|
+
)
|
|
126
|
+
/*: implies node is (PropertyDefinitionWithNonComputedName | MethodDefinitionConstructor | MethodDefinitionWithNonComputedName) */
|
|
127
|
+
{
|
|
128
|
+
return (node.type === 'PropertyDefinition' || node.type === 'MethodDefinition') && node.computed === false;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function isComment(node
|
|
132
|
+
/*: ESNode | Token */
|
|
133
|
+
)
|
|
134
|
+
/*: implies node is (MostTokens | BlockComment | LineComment) */
|
|
135
|
+
{
|
|
136
|
+
return node.type === 'Block' || node.type === 'Line';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function isFunction(node
|
|
140
|
+
/*: ESNode */
|
|
141
|
+
)
|
|
142
|
+
/*: implies node is AFunction */
|
|
143
|
+
{
|
|
144
|
+
return node.type === 'ArrowFunctionExpression' || node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression';
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function isMethodDefinitionWithNonComputedName(node
|
|
148
|
+
/*: ESNode */
|
|
149
|
+
)
|
|
150
|
+
/*: implies node is (MethodDefinitionConstructor | MethodDefinitionWithNonComputedName) */
|
|
151
|
+
{
|
|
152
|
+
return node.type === 'MethodDefinition' && node.computed === false;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function isMemberExpressionWithNonComputedProperty(node
|
|
156
|
+
/*: ESNode */
|
|
157
|
+
)
|
|
158
|
+
/*: implies node is MemberExpressionWithNonComputedName */
|
|
159
|
+
{
|
|
160
|
+
return node.type === 'MemberExpression' && node.computed === false;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function isOptionalMemberExpressionWithNonComputedProperty(node
|
|
164
|
+
/*: ESNode */
|
|
165
|
+
)
|
|
166
|
+
/*: implies node is MemberExpressionWithNonComputedName */
|
|
167
|
+
{
|
|
168
|
+
return node.type === 'MemberExpression' && node.computed === false;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function isObjectPropertyWithShorthand(node
|
|
172
|
+
/*: ESNode */
|
|
173
|
+
)
|
|
174
|
+
/*: implies node is (ObjectPropertyWithShorthandStaticName | DestructuringObjectPropertyWithShorthandStaticName) */
|
|
175
|
+
{
|
|
176
|
+
return node.type === 'Property' && node.shorthand === true;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function isObjectPropertyWithNonComputedName(node
|
|
180
|
+
/*: ESNode */
|
|
181
|
+
)
|
|
182
|
+
/*: implies node is (ObjectPropertyWithNonShorthandStaticName | ObjectPropertyWithShorthandStaticName | DestructuringObjectPropertyWithNonShorthandStaticName | DestructuringObjectPropertyWithShorthandStaticName) */
|
|
183
|
+
{
|
|
184
|
+
return node.type === 'Property' && node.computed === false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function isBigIntLiteral(node
|
|
188
|
+
/*: ESNode */
|
|
189
|
+
)
|
|
190
|
+
/*: implies node is BigIntLiteral */
|
|
191
|
+
{
|
|
192
|
+
return node.type === 'Literal' && node.literalType === 'bigint';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function isBooleanLiteral(node
|
|
196
|
+
/*: ESNode */
|
|
197
|
+
)
|
|
198
|
+
/*: implies node is BooleanLiteral */
|
|
199
|
+
{
|
|
200
|
+
return node.type === 'Literal' && node.literalType === 'boolean';
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function isNullLiteral(node
|
|
204
|
+
/*: ESNode */
|
|
205
|
+
)
|
|
206
|
+
/*: implies node is NullLiteral */
|
|
207
|
+
{
|
|
208
|
+
return node.type === 'Literal' && node.literalType === 'null';
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function isNumericLiteral(node
|
|
212
|
+
/*: ESNode */
|
|
213
|
+
)
|
|
214
|
+
/*: implies node is NumericLiteral */
|
|
215
|
+
{
|
|
216
|
+
return node.type === 'Literal' && node.literalType === 'numeric';
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function isRegExpLiteral(node
|
|
220
|
+
/*: ESNode */
|
|
221
|
+
)
|
|
222
|
+
/*: implies node is RegExpLiteral */
|
|
223
|
+
{
|
|
224
|
+
return node.type === 'Literal' && node.literalType === 'regexp';
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function isStringLiteral(node
|
|
228
|
+
/*: ESNode */
|
|
229
|
+
)
|
|
230
|
+
/*: implies node is StringLiteral */
|
|
231
|
+
{
|
|
232
|
+
return node.type === 'Literal' && node.literalType === 'string';
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function isExpression(node
|
|
236
|
+
/*: ESNode */
|
|
237
|
+
)
|
|
238
|
+
/*: implies node is Expression */
|
|
239
|
+
{
|
|
240
|
+
return node.type === 'ThisExpression' || node.type === 'ArrayExpression' || node.type === 'ObjectExpression' || // $FlowFixMe[incompatible-type]
|
|
241
|
+
node.type === 'ObjectExpression' || node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression' || node.type === 'YieldExpression' || node.type === 'Literal' || node.type === 'UnaryExpression' || node.type === 'UpdateExpression' || node.type === 'BinaryExpression' || node.type === 'AssignmentExpression' || node.type === 'LogicalExpression' || node.type === 'MemberExpression' || node.type === 'ConditionalExpression' || node.type === 'CallExpression' || node.type === 'NewExpression' || node.type === 'SequenceExpression' || node.type === 'TemplateLiteral' || node.type === 'TaggedTemplateExpression' || node.type === 'ClassExpression' || node.type === 'MetaProperty' || node.type === 'Identifier' || node.type === 'AwaitExpression' || node.type === 'ImportExpression' || node.type === 'ChainExpression' || node.type === 'TypeCastExpression' || node.type === 'AsExpression' || node.type === 'AsConstExpression' || node.type === 'JSXFragment' || node.type === 'JSXElement';
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function isStatement(node
|
|
245
|
+
/*: ESNode */
|
|
246
|
+
)
|
|
247
|
+
/*: implies node is Statement */
|
|
248
|
+
{
|
|
249
|
+
return node.type === 'BlockStatement' || node.type === 'BreakStatement' || node.type === 'ClassDeclaration' || node.type === 'ContinueStatement' || node.type === 'DebuggerStatement' || node.type === 'DeclareClass' || node.type === 'DeclareVariable' || node.type === 'DeclareFunction' || node.type === 'DeclareInterface' || node.type === 'DeclareModule' || node.type === 'DeclareOpaqueType' || node.type === 'DeclareTypeAlias' || node.type === 'DoWhileStatement' || node.type === 'EmptyStatement' || node.type === 'EnumDeclaration' || node.type === 'ExpressionStatement' || node.type === 'ForInStatement' || node.type === 'ForOfStatement' || node.type === 'ForStatement' || node.type === 'FunctionDeclaration' || node.type === 'IfStatement' || node.type === 'InterfaceDeclaration' || node.type === 'LabeledStatement' || node.type === 'OpaqueType' || node.type === 'ReturnStatement' || node.type === 'SwitchStatement' || node.type === 'ThrowStatement' || node.type === 'TryStatement' || node.type === 'TypeAlias' || node.type === 'VariableDeclaration' || node.type === 'WhileStatement' || node.type === 'WithStatement';
|
|
250
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* IMPORTANT NOTE
|
|
14
|
+
*
|
|
15
|
+
* This file intentionally uses interfaces and `+` for readonly.
|
|
16
|
+
*
|
|
17
|
+
* - `$ReadOnly` is an "evaluated" utility type in flow; meaning that flow does
|
|
18
|
+
* not actually calculate the resulting type until it is used. This creates
|
|
19
|
+
* a copy of the type at each usage site - ballooning memory and processing
|
|
20
|
+
* times.
|
|
21
|
+
* Usually this isn't a problem as a type might only be used one or two times
|
|
22
|
+
* - but in this giant circular-referencing graph that is the AST types, this
|
|
23
|
+
* causes check times for consumers to be awful.
|
|
24
|
+
*
|
|
25
|
+
* Thus instead we manually annotate properties with `+` to avoid the `$ReadOnly` type.
|
|
26
|
+
*
|
|
27
|
+
* - `...Type` spreads do not preserve the readonly-ness of the properties. If
|
|
28
|
+
* we used object literal types then we would have to `$ReadOnly` all spreads
|
|
29
|
+
* (see point 1). On the other hand extending an interface does preserve
|
|
30
|
+
* readonlyness of properties.
|
|
31
|
+
*
|
|
32
|
+
* Thus instead of object literals, we use interfaces.
|
|
33
|
+
*
|
|
34
|
+
*** Please ensure all properties are marked as readonly! ***
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
Object.defineProperty(exports, "__esModule", {
|
|
38
|
+
value: true
|
|
39
|
+
});
|
package/dist/types.js.flow
CHANGED
|
@@ -1047,7 +1047,7 @@ export interface ImportAttribute extends BaseNode {
|
|
|
1047
1047
|
+key: Identifier;
|
|
1048
1048
|
+value: StringLiteral;
|
|
1049
1049
|
|
|
1050
|
-
+parent: ImportDeclaration
|
|
1050
|
+
+parent: ImportDeclaration;
|
|
1051
1051
|
}
|
|
1052
1052
|
|
|
1053
1053
|
export interface ImportSpecifier extends BaseNode {
|
|
@@ -1062,7 +1062,7 @@ export interface ImportSpecifier extends BaseNode {
|
|
|
1062
1062
|
export interface ImportExpression extends BaseNode {
|
|
1063
1063
|
+type: 'ImportExpression';
|
|
1064
1064
|
+source: Expression;
|
|
1065
|
-
+
|
|
1065
|
+
+options: Expression | null;
|
|
1066
1066
|
}
|
|
1067
1067
|
|
|
1068
1068
|
export interface ImportDefaultSpecifier extends BaseNode {
|