hermes-estree 0.5.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 +21 -0
- package/README.md +3 -0
- package/dist/generated/HermesESTreeSelectorTypes.js.flow +3138 -0
- package/dist/index.js +14 -0
- package/dist/index.js.flow +16 -0
- package/dist/selectors.js +14 -0
- package/dist/selectors.js.flow +28 -0
- package/dist/types.js +39 -0
- package/dist/types.js.flow +1431 -0
- package/package.json +14 -0
|
@@ -0,0 +1,1431 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* IMPORTANT NOTE
|
|
16
|
+
*
|
|
17
|
+
* This file intentionally uses interfaces and `+` for readonly.
|
|
18
|
+
*
|
|
19
|
+
* - `$ReadOnly` is an "evaluated" utility type in flow; meaning that flow does
|
|
20
|
+
* not actually calculate the resulting type until it is used. This creates
|
|
21
|
+
* a copy of the type at each usage site - ballooning memory and processing
|
|
22
|
+
* times.
|
|
23
|
+
* Usually this isn't a problem as a type might only be used one or two times
|
|
24
|
+
* - but in this giant circular-referencing graph that is the AST types, this
|
|
25
|
+
* causes check times for consumers to be awful.
|
|
26
|
+
*
|
|
27
|
+
* Thus instead we manually annotate properties with `+` to avoid the `$ReadOnly` type.
|
|
28
|
+
*
|
|
29
|
+
* - `...Type` spreads do not preserve the readonly-ness of the properties. If
|
|
30
|
+
* we used object literal types then we would have to `$ReadOnly` all spreads
|
|
31
|
+
* (see point 1). On the other hand extending an interface does preserve
|
|
32
|
+
* readonlyness of properties.
|
|
33
|
+
*
|
|
34
|
+
* Thus instead of object literals, we use interfaces.
|
|
35
|
+
*
|
|
36
|
+
*** Please ensure all properties are marked as readonly! ***
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
export type Range = [number, number];
|
|
40
|
+
|
|
41
|
+
export interface BaseToken {
|
|
42
|
+
+loc: SourceLocation;
|
|
43
|
+
+range: Range;
|
|
44
|
+
}
|
|
45
|
+
export interface BaseNode extends BaseToken {
|
|
46
|
+
// this is added by ESLint and is not part of the ESTree spec
|
|
47
|
+
+parent: ESNode;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/*
|
|
51
|
+
* Token and Comment are pseudo-nodes to represent pieces of source code
|
|
52
|
+
*
|
|
53
|
+
* NOTE:
|
|
54
|
+
* They are not included in the `ESNode` union below on purpose because they
|
|
55
|
+
* are not ever included as part of the standard AST tree.
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
export interface MostTokens extends BaseToken {
|
|
59
|
+
+type:
|
|
60
|
+
| 'Boolean'
|
|
61
|
+
| 'Identifier'
|
|
62
|
+
| 'JSXIdentifier'
|
|
63
|
+
| 'JSXText'
|
|
64
|
+
| 'Keyword'
|
|
65
|
+
| 'Null'
|
|
66
|
+
| 'Numeric'
|
|
67
|
+
| 'Punctuator'
|
|
68
|
+
| 'RegularExpression'
|
|
69
|
+
| 'String'
|
|
70
|
+
| 'Template'
|
|
71
|
+
// comment types
|
|
72
|
+
| 'Block'
|
|
73
|
+
| 'Line';
|
|
74
|
+
+value: string;
|
|
75
|
+
}
|
|
76
|
+
export interface RegexToken extends BaseToken {
|
|
77
|
+
+type: 'RegularExpression';
|
|
78
|
+
+value: string;
|
|
79
|
+
+regex: {
|
|
80
|
+
+pattern: string,
|
|
81
|
+
+flags: string,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export interface LineComment extends BaseToken {
|
|
85
|
+
+type: 'Line';
|
|
86
|
+
+value: string;
|
|
87
|
+
}
|
|
88
|
+
export interface BlockComment extends BaseToken {
|
|
89
|
+
+type: 'Block';
|
|
90
|
+
+value: string;
|
|
91
|
+
}
|
|
92
|
+
export type Comment = LineComment | BlockComment;
|
|
93
|
+
export type Token = MostTokens | RegexToken | Comment;
|
|
94
|
+
|
|
95
|
+
export interface SourceLocation {
|
|
96
|
+
+start: Position;
|
|
97
|
+
+end: Position;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface Position {
|
|
101
|
+
/** >= 1 */
|
|
102
|
+
+line: number;
|
|
103
|
+
/** >= 0 */
|
|
104
|
+
+column: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface Program extends BaseNode {
|
|
108
|
+
+type: 'Program';
|
|
109
|
+
+sourceType: 'script' | 'module';
|
|
110
|
+
+body: $ReadOnlyArray<Statement | ModuleDeclaration>;
|
|
111
|
+
+tokens: $ReadOnlyArray<Token>;
|
|
112
|
+
+comments: $ReadOnlyArray<Comment>;
|
|
113
|
+
+loc: SourceLocation;
|
|
114
|
+
// program is the only node without a parent - but typing it as such is _super_ annoying and difficult
|
|
115
|
+
+parent: ESNode;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Flow declares a "Node" type as part of its HTML typedefs.
|
|
119
|
+
// Because this file declares global types - we can't clash with it
|
|
120
|
+
export type ESNode =
|
|
121
|
+
| Identifier
|
|
122
|
+
| Literal
|
|
123
|
+
| Program
|
|
124
|
+
| AFunction
|
|
125
|
+
| SwitchCase
|
|
126
|
+
| CatchClause
|
|
127
|
+
| VariableDeclarator
|
|
128
|
+
| Statement
|
|
129
|
+
| Expression
|
|
130
|
+
| Property
|
|
131
|
+
| Super
|
|
132
|
+
| TemplateElement
|
|
133
|
+
| SpreadElement
|
|
134
|
+
| Pattern
|
|
135
|
+
| ClassBody
|
|
136
|
+
| AClass
|
|
137
|
+
| MethodDefinition
|
|
138
|
+
| ModuleDeclaration
|
|
139
|
+
| ModuleSpecifier
|
|
140
|
+
| ImportAttribute
|
|
141
|
+
// flow nodes
|
|
142
|
+
| TypeAnnotation
|
|
143
|
+
| TypeAnnotationType
|
|
144
|
+
| Variance
|
|
145
|
+
| FunctionTypeParam
|
|
146
|
+
| InferredPredicate
|
|
147
|
+
| ObjectTypeProperty
|
|
148
|
+
| ObjectTypeCallProperty
|
|
149
|
+
| ObjectTypeIndexer
|
|
150
|
+
| ObjectTypeSpreadProperty
|
|
151
|
+
| InterfaceExtends
|
|
152
|
+
| ClassProperty
|
|
153
|
+
| ClassPrivateProperty
|
|
154
|
+
| ClassImplements
|
|
155
|
+
| Decorator
|
|
156
|
+
| TypeParameterDeclaration
|
|
157
|
+
| TypeParameter
|
|
158
|
+
| TypeParameterInstantiation
|
|
159
|
+
| EnumDeclaration
|
|
160
|
+
| EnumNumberBody
|
|
161
|
+
| EnumStringBody
|
|
162
|
+
| EnumStringMember
|
|
163
|
+
| EnumDefaultedMember
|
|
164
|
+
| EnumNumberMember
|
|
165
|
+
| EnumBooleanBody
|
|
166
|
+
| EnumBooleanMember
|
|
167
|
+
| EnumSymbolBody
|
|
168
|
+
| DeclareClass
|
|
169
|
+
| DeclareVariable
|
|
170
|
+
| DeclareFunction
|
|
171
|
+
| DeclaredPredicate
|
|
172
|
+
| DeclareModule
|
|
173
|
+
| ObjectTypeInternalSlot
|
|
174
|
+
// JSX
|
|
175
|
+
| JSXNode;
|
|
176
|
+
|
|
177
|
+
interface BaseFunction extends BaseNode {
|
|
178
|
+
+params: $ReadOnlyArray<Pattern>;
|
|
179
|
+
+async: boolean;
|
|
180
|
+
|
|
181
|
+
+predicate: null | InferredPredicate;
|
|
182
|
+
+returnType: null | TypeAnnotation;
|
|
183
|
+
+typeParameters: null | TypeParameterDeclaration;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export type AFunction =
|
|
187
|
+
| FunctionDeclaration
|
|
188
|
+
| FunctionExpression
|
|
189
|
+
| ArrowFunctionExpression;
|
|
190
|
+
|
|
191
|
+
export type Statement =
|
|
192
|
+
| ExpressionStatement
|
|
193
|
+
| BlockStatement
|
|
194
|
+
| EmptyStatement
|
|
195
|
+
| DebuggerStatement
|
|
196
|
+
| WithStatement
|
|
197
|
+
| ReturnStatement
|
|
198
|
+
| LabeledStatement
|
|
199
|
+
| BreakStatement
|
|
200
|
+
| ContinueStatement
|
|
201
|
+
| IfStatement
|
|
202
|
+
| SwitchStatement
|
|
203
|
+
| ThrowStatement
|
|
204
|
+
| TryStatement
|
|
205
|
+
| WhileStatement
|
|
206
|
+
| DoWhileStatement
|
|
207
|
+
| ForStatement
|
|
208
|
+
| ForInStatement
|
|
209
|
+
| ForOfStatement
|
|
210
|
+
| TypeAlias
|
|
211
|
+
| OpaqueType
|
|
212
|
+
| InterfaceDeclaration
|
|
213
|
+
| Declaration
|
|
214
|
+
| DeclareTypeAlias
|
|
215
|
+
| DeclareOpaqueType
|
|
216
|
+
| DeclareInterface
|
|
217
|
+
| DeclareModule;
|
|
218
|
+
|
|
219
|
+
// nodes that can be the direct parent of a statement
|
|
220
|
+
export type StatementParentSingle =
|
|
221
|
+
| IfStatement
|
|
222
|
+
| LabeledStatement
|
|
223
|
+
| WithStatement
|
|
224
|
+
| WhileStatement
|
|
225
|
+
| DoWhileStatement
|
|
226
|
+
| ForStatement
|
|
227
|
+
| ForInStatement
|
|
228
|
+
| ForOfStatement;
|
|
229
|
+
// nodes that can be the parent of a statement that store the statements in an array
|
|
230
|
+
export type StatementParentArray = SwitchCase | Program | BlockStatement;
|
|
231
|
+
export type StatementParent = StatementParentSingle | StatementParentArray;
|
|
232
|
+
|
|
233
|
+
export interface EmptyStatement extends BaseNode {
|
|
234
|
+
+type: 'EmptyStatement';
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface BlockStatement extends BaseNode {
|
|
238
|
+
+type: 'BlockStatement';
|
|
239
|
+
+body: $ReadOnlyArray<Statement>;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface ExpressionStatement extends BaseNode {
|
|
243
|
+
+type: 'ExpressionStatement';
|
|
244
|
+
+expression: Expression;
|
|
245
|
+
+directive: string | null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface IfStatement extends BaseNode {
|
|
249
|
+
+type: 'IfStatement';
|
|
250
|
+
+test: Expression;
|
|
251
|
+
+consequent: Statement;
|
|
252
|
+
+alternate?: Statement | null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface LabeledStatement extends BaseNode {
|
|
256
|
+
+type: 'LabeledStatement';
|
|
257
|
+
+label: Identifier;
|
|
258
|
+
+body: Statement;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface BreakStatement extends BaseNode {
|
|
262
|
+
+type: 'BreakStatement';
|
|
263
|
+
+label?: Identifier | null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export interface ContinueStatement extends BaseNode {
|
|
267
|
+
+type: 'ContinueStatement';
|
|
268
|
+
+label?: Identifier | null;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export interface WithStatement extends BaseNode {
|
|
272
|
+
+type: 'WithStatement';
|
|
273
|
+
+object: Expression;
|
|
274
|
+
+body: Statement;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface SwitchStatement extends BaseNode {
|
|
278
|
+
+type: 'SwitchStatement';
|
|
279
|
+
+discriminant: Expression;
|
|
280
|
+
+cases: $ReadOnlyArray<SwitchCase>;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
export interface ReturnStatement extends BaseNode {
|
|
284
|
+
+type: 'ReturnStatement';
|
|
285
|
+
+argument?: Expression | null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface ThrowStatement extends BaseNode {
|
|
289
|
+
+type: 'ThrowStatement';
|
|
290
|
+
+argument: Expression;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface TryStatement extends BaseNode {
|
|
294
|
+
+type: 'TryStatement';
|
|
295
|
+
+block: BlockStatement;
|
|
296
|
+
+handler?: CatchClause | null;
|
|
297
|
+
+finalizer?: BlockStatement | null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export interface WhileStatement extends BaseNode {
|
|
301
|
+
+type: 'WhileStatement';
|
|
302
|
+
+test: Expression;
|
|
303
|
+
+body: Statement;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export interface DoWhileStatement extends BaseNode {
|
|
307
|
+
+type: 'DoWhileStatement';
|
|
308
|
+
+body: Statement;
|
|
309
|
+
+test: Expression;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
export interface ForStatement extends BaseNode {
|
|
313
|
+
+type: 'ForStatement';
|
|
314
|
+
+init?: VariableDeclaration | Expression | null;
|
|
315
|
+
+test?: Expression | null;
|
|
316
|
+
+update?: Expression | null;
|
|
317
|
+
+body: Statement;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
interface BaseForXStatement extends BaseNode {
|
|
321
|
+
+left: VariableDeclaration | Pattern;
|
|
322
|
+
+right: Expression;
|
|
323
|
+
+body: Statement;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface ForInStatement extends BaseForXStatement {
|
|
327
|
+
+type: 'ForInStatement';
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface ForOfStatement extends BaseForXStatement {
|
|
331
|
+
+type: 'ForOfStatement';
|
|
332
|
+
+await: boolean;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface DebuggerStatement extends BaseNode {
|
|
336
|
+
+type: 'DebuggerStatement';
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export type Declaration =
|
|
340
|
+
| FunctionDeclaration
|
|
341
|
+
| VariableDeclaration
|
|
342
|
+
| ClassDeclaration;
|
|
343
|
+
|
|
344
|
+
export interface FunctionDeclaration extends BaseFunction {
|
|
345
|
+
+type: 'FunctionDeclaration';
|
|
346
|
+
/** It is null when a function declaration is a part of the `export default function` statement */
|
|
347
|
+
+id: Identifier | null;
|
|
348
|
+
+body: BlockStatement;
|
|
349
|
+
+generator: boolean;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export interface VariableDeclaration extends BaseNode {
|
|
353
|
+
+type: 'VariableDeclaration';
|
|
354
|
+
+declarations: $ReadOnlyArray<VariableDeclarator>;
|
|
355
|
+
+kind: 'var' | 'let' | 'const';
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export interface VariableDeclarator extends BaseNode {
|
|
359
|
+
+type: 'VariableDeclarator';
|
|
360
|
+
+id: Pattern;
|
|
361
|
+
+init?: Expression | null;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export type Expression =
|
|
365
|
+
| ThisExpression
|
|
366
|
+
| ArrayExpression
|
|
367
|
+
| ObjectExpression
|
|
368
|
+
| FunctionExpression
|
|
369
|
+
| ArrowFunctionExpression
|
|
370
|
+
| YieldExpression
|
|
371
|
+
| Literal
|
|
372
|
+
| UnaryExpression
|
|
373
|
+
| UpdateExpression
|
|
374
|
+
| BinaryExpression
|
|
375
|
+
| AssignmentExpression
|
|
376
|
+
| LogicalExpression
|
|
377
|
+
| MemberExpression
|
|
378
|
+
| OptionalMemberExpression
|
|
379
|
+
| ConditionalExpression
|
|
380
|
+
| CallExpression
|
|
381
|
+
| OptionalCallExpression
|
|
382
|
+
| NewExpression
|
|
383
|
+
| SequenceExpression
|
|
384
|
+
| TemplateLiteral
|
|
385
|
+
| TaggedTemplateExpression
|
|
386
|
+
| ClassExpression
|
|
387
|
+
| MetaProperty
|
|
388
|
+
| Identifier
|
|
389
|
+
| AwaitExpression
|
|
390
|
+
| ImportExpression
|
|
391
|
+
| ChainExpression
|
|
392
|
+
| TypeCastExpression
|
|
393
|
+
| PrivateName;
|
|
394
|
+
|
|
395
|
+
export interface ThisExpression extends BaseNode {
|
|
396
|
+
+type: 'ThisExpression';
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export interface ArrayExpression extends BaseNode {
|
|
400
|
+
+type: 'ArrayExpression';
|
|
401
|
+
+elements: $ReadOnlyArray<Expression | SpreadElement>;
|
|
402
|
+
// this is not part of the ESTree spec, but hermes emits it
|
|
403
|
+
+trailingComma: boolean;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export interface ObjectExpression extends BaseNode {
|
|
407
|
+
+type: 'ObjectExpression';
|
|
408
|
+
+properties: $ReadOnlyArray<Property | SpreadElement>;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
interface PropertyBase extends BaseNode {
|
|
412
|
+
+key: Expression;
|
|
413
|
+
+shorthand: boolean;
|
|
414
|
+
+computed: boolean;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
export interface Property extends PropertyBase {
|
|
418
|
+
+type: 'Property';
|
|
419
|
+
+value: Expression | Pattern; // Could be an AssignmentProperty
|
|
420
|
+
+kind: 'init' | 'get' | 'set';
|
|
421
|
+
+method: boolean;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// this is a special type of property
|
|
425
|
+
// we can't use `interface ... extends` here because it's a sub-type
|
|
426
|
+
export interface AssignmentProperty extends PropertyBase {
|
|
427
|
+
+type: 'Property';
|
|
428
|
+
+value: Pattern;
|
|
429
|
+
+kind: 'init';
|
|
430
|
+
+method: false;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
export interface FunctionExpression extends BaseFunction {
|
|
434
|
+
+id?: Identifier | null;
|
|
435
|
+
+type: 'FunctionExpression';
|
|
436
|
+
+body: BlockStatement;
|
|
437
|
+
+generator: boolean;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
export interface SequenceExpression extends BaseNode {
|
|
441
|
+
+type: 'SequenceExpression';
|
|
442
|
+
+expressions: $ReadOnlyArray<Expression>;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export interface UnaryExpression extends BaseNode {
|
|
446
|
+
+type: 'UnaryExpression';
|
|
447
|
+
+operator: UnaryOperator;
|
|
448
|
+
+prefix: true;
|
|
449
|
+
+argument: Expression;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export interface BinaryExpression extends BaseNode {
|
|
453
|
+
+type: 'BinaryExpression';
|
|
454
|
+
+operator: BinaryOperator;
|
|
455
|
+
+left: Expression;
|
|
456
|
+
+right: Expression;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export interface AssignmentExpression extends BaseNode {
|
|
460
|
+
+type: 'AssignmentExpression';
|
|
461
|
+
+operator: AssignmentOperator;
|
|
462
|
+
+left: Pattern | MemberExpression;
|
|
463
|
+
+right: Expression;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
export interface UpdateExpression extends BaseNode {
|
|
467
|
+
+type: 'UpdateExpression';
|
|
468
|
+
+operator: UpdateOperator;
|
|
469
|
+
+argument: Expression;
|
|
470
|
+
+prefix: boolean;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
export interface LogicalExpression extends BaseNode {
|
|
474
|
+
+type: 'LogicalExpression';
|
|
475
|
+
+operator: LogicalOperator;
|
|
476
|
+
+left: Expression;
|
|
477
|
+
+right: Expression;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
export interface ConditionalExpression extends BaseNode {
|
|
481
|
+
+type: 'ConditionalExpression';
|
|
482
|
+
+test: Expression;
|
|
483
|
+
+alternate: Expression;
|
|
484
|
+
+consequent: Expression;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
interface BaseCallExpression extends BaseNode {
|
|
488
|
+
+callee: Expression | Super;
|
|
489
|
+
+arguments: $ReadOnlyArray<Expression | SpreadElement>;
|
|
490
|
+
+typeArguments: null | TypeParameterInstantiation;
|
|
491
|
+
}
|
|
492
|
+
export interface CallExpression extends BaseCallExpression {
|
|
493
|
+
+type: 'CallExpression';
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export interface NewExpression extends BaseCallExpression {
|
|
497
|
+
+type: 'NewExpression';
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
interface BaseMemberExpression extends BaseNode {
|
|
501
|
+
+object: Expression | Super;
|
|
502
|
+
+property: Expression;
|
|
503
|
+
+computed: boolean;
|
|
504
|
+
}
|
|
505
|
+
export interface MemberExpression extends BaseMemberExpression {
|
|
506
|
+
+type: 'MemberExpression';
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
export type ChainElement = CallExpression | MemberExpression;
|
|
510
|
+
|
|
511
|
+
export interface ChainExpression extends BaseNode {
|
|
512
|
+
+type: 'ChainExpression';
|
|
513
|
+
+expression: ChainElement;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export type Pattern =
|
|
517
|
+
| Identifier
|
|
518
|
+
| ObjectPattern
|
|
519
|
+
| ArrayPattern
|
|
520
|
+
| RestElement
|
|
521
|
+
| AssignmentPattern
|
|
522
|
+
| MemberExpression;
|
|
523
|
+
|
|
524
|
+
export interface SwitchCase extends BaseNode {
|
|
525
|
+
+type: 'SwitchCase';
|
|
526
|
+
+test?: Expression | null;
|
|
527
|
+
+consequent: $ReadOnlyArray<Statement>;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export interface CatchClause extends BaseNode {
|
|
531
|
+
+type: 'CatchClause';
|
|
532
|
+
+param: Pattern | null;
|
|
533
|
+
+body: BlockStatement;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
export interface Identifier extends BaseNode {
|
|
537
|
+
+type: 'Identifier';
|
|
538
|
+
+name: string;
|
|
539
|
+
|
|
540
|
+
+typeAnnotation: TypeAnnotation | null;
|
|
541
|
+
// only applies to function arguments
|
|
542
|
+
+optional: boolean;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
export type Literal =
|
|
546
|
+
| BigIntLiteral
|
|
547
|
+
| BigIntLiteralLegacy
|
|
548
|
+
| BooleanLiteral
|
|
549
|
+
| NullLiteral
|
|
550
|
+
| NumericLiteral
|
|
551
|
+
| RegExpLiteral
|
|
552
|
+
| StringLiteral;
|
|
553
|
+
|
|
554
|
+
export interface BigIntLiteral extends BaseNode {
|
|
555
|
+
+type: 'Literal';
|
|
556
|
+
+value: null /* | bigint */;
|
|
557
|
+
+bigint: string;
|
|
558
|
+
+raw: string;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
export interface BooleanLiteral extends BaseNode {
|
|
562
|
+
+type: 'Literal';
|
|
563
|
+
+value: boolean;
|
|
564
|
+
+raw: 'true' | 'false';
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
export interface NullLiteral extends BaseNode {
|
|
568
|
+
+type: 'Literal';
|
|
569
|
+
+value: null;
|
|
570
|
+
+raw: 'null';
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
export interface NumericLiteral extends BaseNode {
|
|
574
|
+
+type: 'Literal';
|
|
575
|
+
+value: number;
|
|
576
|
+
+raw: string;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export interface RegExpLiteral extends BaseNode {
|
|
580
|
+
+type: 'Literal';
|
|
581
|
+
+value: RegExp | null;
|
|
582
|
+
+regex: interface {
|
|
583
|
+
+pattern: string,
|
|
584
|
+
+flags: string,
|
|
585
|
+
};
|
|
586
|
+
+raw: string;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
export interface StringLiteral extends BaseNode {
|
|
590
|
+
+type: 'Literal';
|
|
591
|
+
+value: string;
|
|
592
|
+
+raw: string;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
export type UnaryOperator =
|
|
596
|
+
| '-'
|
|
597
|
+
| '+'
|
|
598
|
+
| '!'
|
|
599
|
+
| '~'
|
|
600
|
+
| 'typeof'
|
|
601
|
+
| 'void'
|
|
602
|
+
| 'delete';
|
|
603
|
+
|
|
604
|
+
export type BinaryOperator =
|
|
605
|
+
| '=='
|
|
606
|
+
| '!='
|
|
607
|
+
| '==='
|
|
608
|
+
| '!=='
|
|
609
|
+
| '<'
|
|
610
|
+
| '<='
|
|
611
|
+
| '>'
|
|
612
|
+
| '>='
|
|
613
|
+
| '<<'
|
|
614
|
+
| '>>'
|
|
615
|
+
| '>>>'
|
|
616
|
+
| '+'
|
|
617
|
+
| '-'
|
|
618
|
+
| '*'
|
|
619
|
+
| '/'
|
|
620
|
+
| '%'
|
|
621
|
+
| '**'
|
|
622
|
+
| '|'
|
|
623
|
+
| '^'
|
|
624
|
+
| '&'
|
|
625
|
+
| 'in'
|
|
626
|
+
| 'instanceof';
|
|
627
|
+
|
|
628
|
+
export type LogicalOperator = '||' | '&&';
|
|
629
|
+
|
|
630
|
+
export type AssignmentOperator =
|
|
631
|
+
| '='
|
|
632
|
+
| '+='
|
|
633
|
+
| '-='
|
|
634
|
+
| '*='
|
|
635
|
+
| '/='
|
|
636
|
+
| '%='
|
|
637
|
+
| '**='
|
|
638
|
+
| '<<='
|
|
639
|
+
| '>>='
|
|
640
|
+
| '>>>='
|
|
641
|
+
| '|='
|
|
642
|
+
| '^='
|
|
643
|
+
| '&=';
|
|
644
|
+
|
|
645
|
+
export type UpdateOperator = '++' | '--';
|
|
646
|
+
|
|
647
|
+
export interface Super extends BaseNode {
|
|
648
|
+
+type: 'Super';
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
export interface SpreadElement extends BaseNode {
|
|
652
|
+
+type: 'SpreadElement';
|
|
653
|
+
+argument: Expression;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
export interface ArrowFunctionExpression extends BaseFunction {
|
|
657
|
+
+type: 'ArrowFunctionExpression';
|
|
658
|
+
+expression: boolean;
|
|
659
|
+
+body: BlockStatement | Expression;
|
|
660
|
+
// hermes emits this - but it's always null
|
|
661
|
+
+id: null;
|
|
662
|
+
// note - arrow functions cannot be generators
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
export interface YieldExpression extends BaseNode {
|
|
666
|
+
+type: 'YieldExpression';
|
|
667
|
+
+argument?: Expression | null;
|
|
668
|
+
+delegate: boolean;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
export interface TemplateLiteral extends BaseNode {
|
|
672
|
+
+type: 'TemplateLiteral';
|
|
673
|
+
+quasis: $ReadOnlyArray<TemplateElement>;
|
|
674
|
+
+expressions: $ReadOnlyArray<Expression>;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
export interface TaggedTemplateExpression extends BaseNode {
|
|
678
|
+
+type: 'TaggedTemplateExpression';
|
|
679
|
+
+tag: Expression;
|
|
680
|
+
+quasi: TemplateLiteral;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
export interface TemplateElement extends BaseNode {
|
|
684
|
+
+type: 'TemplateElement';
|
|
685
|
+
+tail: boolean;
|
|
686
|
+
+value: interface {
|
|
687
|
+
+cooked: string,
|
|
688
|
+
+raw: string,
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
export interface ObjectPattern extends BaseNode {
|
|
693
|
+
+type: 'ObjectPattern';
|
|
694
|
+
+properties: $ReadOnlyArray<AssignmentProperty | RestElement>;
|
|
695
|
+
// if used as a VariableDeclarator.id
|
|
696
|
+
+typeAnnotation: TypeAnnotation | null;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
export interface ArrayPattern extends BaseNode {
|
|
700
|
+
+type: 'ArrayPattern';
|
|
701
|
+
+elements: $ReadOnlyArray<Pattern>;
|
|
702
|
+
|
|
703
|
+
+typeAnnotation: TypeAnnotation | null;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
export interface RestElement extends BaseNode {
|
|
707
|
+
+type: 'RestElement';
|
|
708
|
+
+argument: Pattern;
|
|
709
|
+
// the Pattern owns the typeAnnotation
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
export interface AssignmentPattern extends BaseNode {
|
|
713
|
+
+type: 'AssignmentPattern';
|
|
714
|
+
+left: Pattern;
|
|
715
|
+
+right: Expression;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
export type AClass = ClassDeclaration | ClassExpression;
|
|
719
|
+
interface BaseClass extends BaseNode {
|
|
720
|
+
+superClass?: Expression | null;
|
|
721
|
+
+body: ClassBody;
|
|
722
|
+
|
|
723
|
+
+typeParameters: null | TypeParameterDeclaration;
|
|
724
|
+
+superTypeParameters: null | TypeParameterDeclaration;
|
|
725
|
+
+implements: $ReadOnlyArray<ClassImplements>;
|
|
726
|
+
+decorators: $ReadOnlyArray<Decorator>;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
export interface ClassBody extends BaseNode {
|
|
730
|
+
+type: 'ClassBody';
|
|
731
|
+
+body: $ReadOnlyArray<
|
|
732
|
+
ClassProperty | ClassPrivateProperty | MethodDefinition,
|
|
733
|
+
>;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
export interface MethodDefinition extends BaseNode {
|
|
737
|
+
+type: 'MethodDefinition';
|
|
738
|
+
+key: Expression;
|
|
739
|
+
+value: FunctionExpression;
|
|
740
|
+
+kind: 'constructor' | 'method' | 'get' | 'set';
|
|
741
|
+
+computed: boolean;
|
|
742
|
+
+static: boolean;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
export interface ClassDeclaration extends BaseClass {
|
|
746
|
+
+type: 'ClassDeclaration';
|
|
747
|
+
/** It is null when a class declaration is a part of the `export default class` statement */
|
|
748
|
+
+id: Identifier | null;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
export interface ClassExpression extends BaseClass {
|
|
752
|
+
+type: 'ClassExpression';
|
|
753
|
+
+id?: Identifier | null;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
export interface MetaProperty extends BaseNode {
|
|
757
|
+
+type: 'MetaProperty';
|
|
758
|
+
+meta: Identifier;
|
|
759
|
+
+property: Identifier;
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
export type ModuleDeclaration =
|
|
763
|
+
| ImportDeclaration
|
|
764
|
+
| ExportNamedDeclaration
|
|
765
|
+
| ExportDefaultDeclaration
|
|
766
|
+
| ExportAllDeclaration
|
|
767
|
+
| DeclareExportDeclaration
|
|
768
|
+
| DeclareExportAllDeclaration
|
|
769
|
+
| DeclareModuleExports;
|
|
770
|
+
|
|
771
|
+
export type ModuleSpecifier =
|
|
772
|
+
| ImportSpecifier
|
|
773
|
+
| ImportDefaultSpecifier
|
|
774
|
+
| ImportNamespaceSpecifier
|
|
775
|
+
| ExportSpecifier
|
|
776
|
+
| ExportNamespaceSpecifier;
|
|
777
|
+
|
|
778
|
+
export interface ImportDeclaration extends BaseNode {
|
|
779
|
+
+type: 'ImportDeclaration';
|
|
780
|
+
+specifiers: $ReadOnlyArray<
|
|
781
|
+
ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier,
|
|
782
|
+
>;
|
|
783
|
+
+source: StringLiteral;
|
|
784
|
+
+assertions: $ReadOnlyArray<ImportAttribute>;
|
|
785
|
+
|
|
786
|
+
+importKind: 'value' | 'type' | 'typeof';
|
|
787
|
+
}
|
|
788
|
+
export interface ImportAttribute extends BaseNode {
|
|
789
|
+
+type: 'ImportAttribute';
|
|
790
|
+
+key: Identifier;
|
|
791
|
+
+value: StringLiteral;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
export interface ImportSpecifier extends BaseNode {
|
|
795
|
+
+type: 'ImportSpecifier';
|
|
796
|
+
+imported: Identifier;
|
|
797
|
+
+local: Identifier;
|
|
798
|
+
+importKind: null | 'type' | 'typeof';
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
export interface ImportExpression extends BaseNode {
|
|
802
|
+
+type: 'ImportExpression';
|
|
803
|
+
+source: Expression;
|
|
804
|
+
+attributes: $ReadOnlyArray<ImportAttribute> | null;
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
export interface ImportDefaultSpecifier extends BaseNode {
|
|
808
|
+
+type: 'ImportDefaultSpecifier';
|
|
809
|
+
+local: Identifier;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
export interface ImportNamespaceSpecifier extends BaseNode {
|
|
813
|
+
+type: 'ImportNamespaceSpecifier';
|
|
814
|
+
+local: Identifier;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
export interface ExportNamedDeclaration extends BaseNode {
|
|
818
|
+
+type: 'ExportNamedDeclaration';
|
|
819
|
+
+declaration?: Declaration | null;
|
|
820
|
+
+specifiers: $ReadOnlyArray<ExportSpecifier | ExportNamespaceSpecifier>;
|
|
821
|
+
+source?: Literal | null;
|
|
822
|
+
+exportKind: 'value' | 'type';
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
export interface ExportSpecifier extends BaseNode {
|
|
826
|
+
+type: 'ExportSpecifier';
|
|
827
|
+
+exported: Identifier;
|
|
828
|
+
+local: Identifier;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
export interface ExportDefaultDeclaration extends BaseNode {
|
|
832
|
+
+type: 'ExportDefaultDeclaration';
|
|
833
|
+
+declaration: Declaration | Expression;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
export interface ExportAllDeclaration extends BaseNode {
|
|
837
|
+
+type: 'ExportAllDeclaration';
|
|
838
|
+
+source: Literal;
|
|
839
|
+
+exportKind: 'value' | 'type';
|
|
840
|
+
// uncomment this when hermes stops using ExportNamespaceSpecifier
|
|
841
|
+
// +exported: Identifier;
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
export interface AwaitExpression extends BaseNode {
|
|
845
|
+
+type: 'AwaitExpression';
|
|
846
|
+
+argument: Expression;
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/***********************
|
|
850
|
+
* Flow specific nodes *
|
|
851
|
+
***********************/
|
|
852
|
+
|
|
853
|
+
export type TypeAnnotationType =
|
|
854
|
+
| NumberTypeAnnotation
|
|
855
|
+
| StringTypeAnnotation
|
|
856
|
+
| BooleanTypeAnnotation
|
|
857
|
+
| NullLiteralTypeAnnotation
|
|
858
|
+
| AnyTypeAnnotation
|
|
859
|
+
| EmptyTypeAnnotation
|
|
860
|
+
| SymbolTypeAnnotation
|
|
861
|
+
| ThisTypeAnnotation
|
|
862
|
+
| MixedTypeAnnotation
|
|
863
|
+
| VoidTypeAnnotation
|
|
864
|
+
| StringLiteralTypeAnnotation
|
|
865
|
+
| NumberLiteralTypeAnnotation
|
|
866
|
+
| BooleanLiteralTypeAnnotation
|
|
867
|
+
| ArrayTypeAnnotation
|
|
868
|
+
| NullableTypeAnnotation
|
|
869
|
+
| ExistsTypeAnnotation
|
|
870
|
+
| GenericTypeAnnotation
|
|
871
|
+
| QualifiedTypeIdentifier
|
|
872
|
+
| TypeofTypeAnnotation
|
|
873
|
+
| TupleTypeAnnotation
|
|
874
|
+
| InterfaceTypeAnnotation
|
|
875
|
+
| UnionTypeAnnotation
|
|
876
|
+
| IntersectionTypeAnnotation
|
|
877
|
+
| FunctionTypeAnnotation
|
|
878
|
+
| ObjectTypeAnnotation
|
|
879
|
+
| IndexedAccessType
|
|
880
|
+
| OptionalIndexedAccessType;
|
|
881
|
+
|
|
882
|
+
export interface Variance extends BaseNode {
|
|
883
|
+
+type: 'Variance';
|
|
884
|
+
+kind: 'plus' | 'minus';
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
interface BaseTypeAlias extends BaseNode {
|
|
888
|
+
+id: Identifier;
|
|
889
|
+
+typeParameters: null | TypeParameterDeclaration;
|
|
890
|
+
+right: TypeAnnotationType;
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
export interface TypeAnnotation extends BaseNode {
|
|
894
|
+
+type: 'TypeAnnotation';
|
|
895
|
+
+typeAnnotation: TypeAnnotationType;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
export interface TypeAlias extends BaseTypeAlias {
|
|
899
|
+
+type: 'TypeAlias';
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
interface BaseOpaqueType extends BaseNode {
|
|
903
|
+
+id: Identifier;
|
|
904
|
+
+supertype: TypeAnnotationType | null;
|
|
905
|
+
+typeParameters: TypeParameterDeclaration | null;
|
|
906
|
+
}
|
|
907
|
+
export interface OpaqueType extends BaseOpaqueType {
|
|
908
|
+
+type: 'OpaqueType';
|
|
909
|
+
+impltype: TypeAnnotationType;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
export interface NumberTypeAnnotation extends BaseNode {
|
|
913
|
+
+type: 'NumberTypeAnnotation';
|
|
914
|
+
}
|
|
915
|
+
export interface StringTypeAnnotation extends BaseNode {
|
|
916
|
+
+type: 'StringTypeAnnotation';
|
|
917
|
+
}
|
|
918
|
+
export interface BooleanTypeAnnotation extends BaseNode {
|
|
919
|
+
+type: 'BooleanTypeAnnotation';
|
|
920
|
+
}
|
|
921
|
+
export interface NullLiteralTypeAnnotation extends BaseNode {
|
|
922
|
+
+type: 'NullLiteralTypeAnnotation';
|
|
923
|
+
}
|
|
924
|
+
export interface AnyTypeAnnotation extends BaseNode {
|
|
925
|
+
+type: 'AnyTypeAnnotation';
|
|
926
|
+
}
|
|
927
|
+
export interface EmptyTypeAnnotation extends BaseNode {
|
|
928
|
+
+type: 'EmptyTypeAnnotation';
|
|
929
|
+
}
|
|
930
|
+
export interface SymbolTypeAnnotation extends BaseNode {
|
|
931
|
+
+type: 'SymbolTypeAnnotation';
|
|
932
|
+
}
|
|
933
|
+
export interface ThisTypeAnnotation extends BaseNode {
|
|
934
|
+
+type: 'ThisTypeAnnotation';
|
|
935
|
+
}
|
|
936
|
+
export interface MixedTypeAnnotation extends BaseNode {
|
|
937
|
+
+type: 'MixedTypeAnnotation';
|
|
938
|
+
}
|
|
939
|
+
export interface VoidTypeAnnotation extends BaseNode {
|
|
940
|
+
+type: 'VoidTypeAnnotation';
|
|
941
|
+
}
|
|
942
|
+
export interface StringLiteralTypeAnnotation extends BaseNode {
|
|
943
|
+
+type: 'StringLiteralTypeAnnotation';
|
|
944
|
+
+value: string;
|
|
945
|
+
}
|
|
946
|
+
export interface NumberLiteralTypeAnnotation extends BaseNode {
|
|
947
|
+
+type: 'NumberLiteralTypeAnnotation';
|
|
948
|
+
+value: number;
|
|
949
|
+
+raw: string;
|
|
950
|
+
}
|
|
951
|
+
export interface BooleanLiteralTypeAnnotation extends BaseNode {
|
|
952
|
+
+type: 'BooleanLiteralTypeAnnotation';
|
|
953
|
+
+value: boolean;
|
|
954
|
+
+raw: string;
|
|
955
|
+
}
|
|
956
|
+
export interface ArrayTypeAnnotation extends BaseNode {
|
|
957
|
+
+type: 'ArrayTypeAnnotation';
|
|
958
|
+
+elementType: TypeAnnotationType;
|
|
959
|
+
}
|
|
960
|
+
export interface NullableTypeAnnotation extends BaseNode {
|
|
961
|
+
+type: 'NullableTypeAnnotation';
|
|
962
|
+
+typeAnnotation: TypeAnnotationType;
|
|
963
|
+
}
|
|
964
|
+
export interface ExistsTypeAnnotation extends BaseNode {
|
|
965
|
+
+type: 'ExistsTypeAnnotation';
|
|
966
|
+
}
|
|
967
|
+
export interface GenericTypeAnnotation extends BaseNode {
|
|
968
|
+
+type: 'GenericTypeAnnotation';
|
|
969
|
+
+id: Identifier;
|
|
970
|
+
+typeParameters: null | TypeParameterInstantiation;
|
|
971
|
+
}
|
|
972
|
+
export interface QualifiedTypeIdentifier extends BaseNode {
|
|
973
|
+
+type: 'QualifiedTypeIdentifier';
|
|
974
|
+
+id: Identifier;
|
|
975
|
+
+qualification: QualifiedTypeIdentifier | Identifier;
|
|
976
|
+
}
|
|
977
|
+
export interface TypeofTypeAnnotation extends BaseNode {
|
|
978
|
+
+type: 'TypeofTypeAnnotation';
|
|
979
|
+
+argument: GenericTypeAnnotation | QualifiedTypeIdentifier;
|
|
980
|
+
}
|
|
981
|
+
export interface TupleTypeAnnotation extends BaseNode {
|
|
982
|
+
+type: 'TupleTypeAnnotation';
|
|
983
|
+
+types: TypeAnnotationType;
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// type T = { [[foo]]: number };
|
|
987
|
+
export interface ObjectTypeInternalSlot extends BaseNode {
|
|
988
|
+
+type: 'ObjectTypeInternalSlot';
|
|
989
|
+
+id: Identifier;
|
|
990
|
+
+optional: boolean;
|
|
991
|
+
+static: boolean;
|
|
992
|
+
+method: boolean;
|
|
993
|
+
+value: TypeAnnotation;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
export interface InterfaceTypeAnnotation extends BaseInterfaceNode {
|
|
997
|
+
+type: 'InterfaceTypeAnnotation';
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
export interface UnionTypeAnnotation extends BaseNode {
|
|
1001
|
+
+type: 'UnionTypeAnnotation';
|
|
1002
|
+
+types: $ReadOnlyArray<TypeAnnotationType>;
|
|
1003
|
+
}
|
|
1004
|
+
export interface IntersectionTypeAnnotation extends BaseNode {
|
|
1005
|
+
+type: 'IntersectionTypeAnnotation';
|
|
1006
|
+
+types: $ReadOnlyArray<TypeAnnotationType>;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
export interface FunctionTypeAnnotation extends BaseNode {
|
|
1010
|
+
+type: 'FunctionTypeAnnotation';
|
|
1011
|
+
+params: $ReadOnlyArray<FunctionTypeParam>;
|
|
1012
|
+
+returnType: TypeAnnotationType;
|
|
1013
|
+
+rest: null | FunctionTypeParam;
|
|
1014
|
+
+typeParameters: null | TypeParameterDeclaration;
|
|
1015
|
+
+this: TypeAnnotationType | null;
|
|
1016
|
+
}
|
|
1017
|
+
export interface FunctionTypeParam extends BaseNode {
|
|
1018
|
+
+type: 'FunctionTypeParam';
|
|
1019
|
+
+name: Identifier | null;
|
|
1020
|
+
+typeAnnotation: TypeAnnotationType;
|
|
1021
|
+
+optional: boolean;
|
|
1022
|
+
}
|
|
1023
|
+
export interface InferredPredicate extends BaseNode {
|
|
1024
|
+
+type: 'InferredPredicate';
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
export interface ObjectTypeAnnotation extends BaseNode {
|
|
1028
|
+
+type: 'ObjectTypeAnnotation';
|
|
1029
|
+
+inexact: false;
|
|
1030
|
+
+exact: boolean;
|
|
1031
|
+
+properties: $ReadOnlyArray<ObjectTypeProperty | ObjectTypeSpreadProperty>;
|
|
1032
|
+
+indexers: $ReadOnlyArray<ObjectTypeIndexer>;
|
|
1033
|
+
+callProperties: $ReadOnlyArray<ObjectTypeCallProperty>;
|
|
1034
|
+
+internalSlots: $ReadOnlyArray<ObjectTypeInternalSlot>;
|
|
1035
|
+
}
|
|
1036
|
+
export interface ObjectTypeProperty extends BaseNode {
|
|
1037
|
+
+type: 'ObjectTypeProperty';
|
|
1038
|
+
+key: Identifier;
|
|
1039
|
+
+value: TypeAnnotationType;
|
|
1040
|
+
+method: boolean;
|
|
1041
|
+
+optional: boolean;
|
|
1042
|
+
+static: false; // can't be static
|
|
1043
|
+
+proto: false; // ???
|
|
1044
|
+
+variance: Variance | null;
|
|
1045
|
+
+kind: 'init';
|
|
1046
|
+
}
|
|
1047
|
+
export interface ObjectTypeCallProperty extends BaseNode {
|
|
1048
|
+
+type: 'ObjectTypeCallProperty';
|
|
1049
|
+
+value: FunctionTypeAnnotation;
|
|
1050
|
+
+static: false; // can't be static
|
|
1051
|
+
}
|
|
1052
|
+
export interface ObjectTypeIndexer extends BaseNode {
|
|
1053
|
+
+type: 'ObjectTypeIndexer';
|
|
1054
|
+
+id: null | Identifier;
|
|
1055
|
+
+key: TypeAnnotationType;
|
|
1056
|
+
+value: TypeAnnotationType;
|
|
1057
|
+
+static: false; // can't be static
|
|
1058
|
+
+variance: null | Variance;
|
|
1059
|
+
}
|
|
1060
|
+
export interface ObjectTypeSpreadProperty extends BaseNode {
|
|
1061
|
+
+type: 'ObjectTypeSpreadProperty';
|
|
1062
|
+
+argument: TypeAnnotationType;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
export interface IndexedAccessType extends BaseNode {
|
|
1066
|
+
+type: 'IndexedAccessType';
|
|
1067
|
+
+objectType: TypeAnnotation;
|
|
1068
|
+
+indexType: TypeAnnotation;
|
|
1069
|
+
}
|
|
1070
|
+
export interface OptionalIndexedAccessType extends BaseNode {
|
|
1071
|
+
+type: 'OptionalIndexedAccessType';
|
|
1072
|
+
+objectType: TypeAnnotation;
|
|
1073
|
+
+indexType: TypeAnnotation;
|
|
1074
|
+
+optional: boolean;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
export interface TypeCastExpression extends BaseNode {
|
|
1078
|
+
+type: 'TypeCastExpression';
|
|
1079
|
+
+expression: Expression;
|
|
1080
|
+
+typeAnnotation: TypeAnnotation;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
interface BaseInterfaceNode extends BaseNode {
|
|
1084
|
+
+body: ObjectTypeAnnotation;
|
|
1085
|
+
+extends: $ReadOnlyArray<InterfaceExtends>;
|
|
1086
|
+
}
|
|
1087
|
+
interface BaseInterfaceDeclaration extends BaseInterfaceNode {
|
|
1088
|
+
+id: Identifier;
|
|
1089
|
+
+typeParameters: null | TypeParameterDeclaration;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
export interface InterfaceDeclaration extends BaseInterfaceDeclaration {
|
|
1093
|
+
+type: 'InterfaceDeclaration';
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
export interface InterfaceExtends extends BaseNode {
|
|
1097
|
+
+type: 'InterfaceExtends';
|
|
1098
|
+
+id: Identifier;
|
|
1099
|
+
+typeParameters: null | TypeParameterDeclaration;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
interface ClassPropertyBase extends BaseNode {
|
|
1103
|
+
+key: Identifier;
|
|
1104
|
+
+value: null | Literal;
|
|
1105
|
+
+typeAnnotation: null | TypeAnnotationType;
|
|
1106
|
+
+static: boolean;
|
|
1107
|
+
+variance: null | Variance;
|
|
1108
|
+
+declare: boolean;
|
|
1109
|
+
// hermes always emit this as false
|
|
1110
|
+
+optional: false;
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
export interface ClassImplements extends BaseNode {
|
|
1114
|
+
+type: 'ClassImplements';
|
|
1115
|
+
+id: Identifier;
|
|
1116
|
+
+typeParameters: null | TypeParameterDeclaration;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
export interface Decorator extends BaseNode {
|
|
1120
|
+
+type: 'Decorator';
|
|
1121
|
+
+expression: Expression;
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
export interface TypeParameterDeclaration extends BaseNode {
|
|
1125
|
+
+type: 'TypeParameterDeclaration';
|
|
1126
|
+
+params: $ReadOnlyArray<TypeParameter>;
|
|
1127
|
+
}
|
|
1128
|
+
export interface TypeParameter extends BaseNode {
|
|
1129
|
+
+type: 'TypeParameter';
|
|
1130
|
+
+name: string;
|
|
1131
|
+
+bound: null | TypeAnnotation;
|
|
1132
|
+
+variance: null | Variance;
|
|
1133
|
+
+default: null | TypeAnnotationType;
|
|
1134
|
+
}
|
|
1135
|
+
export interface TypeParameterInstantiation extends BaseNode {
|
|
1136
|
+
+type: 'TypeParameterInstantiation';
|
|
1137
|
+
+params: $ReadOnlyArray<TypeAnnotationType>;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
export interface EnumDeclaration extends BaseNode {
|
|
1141
|
+
+type: 'EnumDeclaration';
|
|
1142
|
+
+id: Identifier;
|
|
1143
|
+
+body: EnumNumberBody | EnumStringBody | EnumBooleanBody | EnumSymbolBody;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
interface BaseEnumBody extends BaseNode {
|
|
1147
|
+
+hasUnknownMembers: boolean;
|
|
1148
|
+
}
|
|
1149
|
+
interface BaseInferrableEnumBody extends BaseEnumBody {
|
|
1150
|
+
+explicitType: boolean;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
export interface EnumNumberBody extends BaseInferrableEnumBody {
|
|
1154
|
+
+type: 'EnumNumberBody';
|
|
1155
|
+
// enum number members cannot be defaulted
|
|
1156
|
+
+members: $ReadOnlyArray<EnumNumberMember>;
|
|
1157
|
+
+explicitType: boolean;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
export interface EnumNumberMember extends BaseNode {
|
|
1161
|
+
+type: 'EnumNumberMember';
|
|
1162
|
+
+id: Identifier;
|
|
1163
|
+
+init: NumericLiteral;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
export interface EnumStringBody extends BaseInferrableEnumBody {
|
|
1167
|
+
+type: 'EnumStringBody';
|
|
1168
|
+
+members: $ReadOnlyArray<EnumStringMember | EnumDefaultedMember>;
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
export interface EnumStringMember extends BaseNode {
|
|
1172
|
+
+type: 'EnumStringMember';
|
|
1173
|
+
+id: Identifier;
|
|
1174
|
+
+init: StringLiteral;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
export interface EnumBooleanBody extends BaseInferrableEnumBody {
|
|
1178
|
+
+type: 'EnumBooleanBody';
|
|
1179
|
+
// enum boolean members cannot be defaulted
|
|
1180
|
+
+members: $ReadOnlyArray<EnumBooleanMember>;
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
export interface EnumBooleanMember extends BaseNode {
|
|
1184
|
+
+type: 'EnumBooleanMember';
|
|
1185
|
+
+id: Identifier;
|
|
1186
|
+
+init: BooleanLiteral;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
export interface EnumSymbolBody extends BaseEnumBody {
|
|
1190
|
+
+type: 'EnumSymbolBody';
|
|
1191
|
+
// enum symbol members can only be defaulted
|
|
1192
|
+
+members: $ReadOnlyArray<EnumDefaultedMember>;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
export interface EnumDefaultedMember extends BaseNode {
|
|
1196
|
+
+type: 'EnumDefaultedMember';
|
|
1197
|
+
+id: Identifier;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
/*****************
|
|
1201
|
+
* Declare nodes *
|
|
1202
|
+
*****************/
|
|
1203
|
+
|
|
1204
|
+
export interface DeclareClass extends BaseNode {
|
|
1205
|
+
+type: 'DeclareClass';
|
|
1206
|
+
+id: Identifier;
|
|
1207
|
+
+typeParameters: null | TypeParameterDeclaration;
|
|
1208
|
+
+extends: $ReadOnlyArray<InterfaceExtends>;
|
|
1209
|
+
+implements: $ReadOnlyArray<ClassImplements>;
|
|
1210
|
+
+body: ObjectTypeAnnotation;
|
|
1211
|
+
+mixins: $ReadOnlyArray<InterfaceExtends>;
|
|
1212
|
+
}
|
|
1213
|
+
|
|
1214
|
+
export interface DeclareVariable extends BaseNode {
|
|
1215
|
+
+type: 'DeclareVariable';
|
|
1216
|
+
+id: Identifier;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
export interface DeclareFunction extends BaseNode {
|
|
1220
|
+
+type: 'DeclareFunction';
|
|
1221
|
+
+id: Identifier;
|
|
1222
|
+
+predicate: InferredPredicate | null;
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
export interface DeclareModule extends BaseNode {
|
|
1226
|
+
+type: 'DeclareModule';
|
|
1227
|
+
+id: StringLiteral | Identifier;
|
|
1228
|
+
+body: BlockStatement;
|
|
1229
|
+
+kind: 'CommonJS' | 'ES';
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
export interface DeclareInterface extends BaseInterfaceDeclaration {
|
|
1233
|
+
+type: 'DeclareInterface';
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
export interface DeclareTypeAlias extends BaseTypeAlias {
|
|
1237
|
+
+type: 'DeclareTypeAlias';
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
export interface DeclareOpaqueType extends BaseOpaqueType {
|
|
1241
|
+
+type: 'DeclareOpaqueType';
|
|
1242
|
+
+impltype: null;
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
export interface DeclareExportAllDeclaration extends BaseNode {
|
|
1246
|
+
+type: 'DeclareExportAllDeclaration';
|
|
1247
|
+
+source: StringLiteral;
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
export interface DeclareExportDeclaration extends BaseNode {
|
|
1251
|
+
+type: 'DeclareExportDeclaration';
|
|
1252
|
+
+specifiers: $ReadOnlyArray<ExportSpecifier>;
|
|
1253
|
+
+declaration:
|
|
1254
|
+
| TypeAnnotationType
|
|
1255
|
+
| DeclareClass
|
|
1256
|
+
| DeclareFunction
|
|
1257
|
+
| DeclareOpaqueType
|
|
1258
|
+
| DeclareInterface
|
|
1259
|
+
| null;
|
|
1260
|
+
+source: StringLiteral | null;
|
|
1261
|
+
+default: boolean;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
export interface DeclareModuleExports extends BaseNode {
|
|
1265
|
+
+type: 'DeclareModuleExports';
|
|
1266
|
+
+typeAnnotation: TypeAnnotation;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
export interface DeclaredPredicate extends BaseNode {
|
|
1270
|
+
+type: 'DeclaredPredicate';
|
|
1271
|
+
+value: Expression;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
/**********************
|
|
1275
|
+
* JSX specific nodes *
|
|
1276
|
+
**********************/
|
|
1277
|
+
|
|
1278
|
+
export type JSXChild =
|
|
1279
|
+
| JSXElement
|
|
1280
|
+
| JSXExpression
|
|
1281
|
+
| JSXFragment
|
|
1282
|
+
| JSXText
|
|
1283
|
+
| JSXSpreadChild;
|
|
1284
|
+
export type JSXExpression = JSXEmptyExpression | JSXExpressionContainer;
|
|
1285
|
+
export type JSXTagNameExpression =
|
|
1286
|
+
| JSXIdentifier
|
|
1287
|
+
| JSXMemberExpression
|
|
1288
|
+
| JSXNamespacedName;
|
|
1289
|
+
|
|
1290
|
+
export type JSXNode =
|
|
1291
|
+
| JSXAttribute
|
|
1292
|
+
| JSXClosingElement
|
|
1293
|
+
| JSXClosingFragment
|
|
1294
|
+
| JSXElement
|
|
1295
|
+
| JSXEmptyExpression
|
|
1296
|
+
| JSXExpressionContainer
|
|
1297
|
+
| JSXFragment
|
|
1298
|
+
| JSXIdentifier
|
|
1299
|
+
| JSXMemberExpression
|
|
1300
|
+
| JSXNamespacedName
|
|
1301
|
+
| JSXOpeningElement
|
|
1302
|
+
| JSXOpeningFragment
|
|
1303
|
+
| JSXSpreadAttribute
|
|
1304
|
+
| JSXText
|
|
1305
|
+
| JSXSpreadChild;
|
|
1306
|
+
|
|
1307
|
+
export interface JSXAttribute extends BaseNode {
|
|
1308
|
+
+type: 'JSXAttribute';
|
|
1309
|
+
+name: JSXIdentifier;
|
|
1310
|
+
+value: Literal | JSXExpression | null;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
export interface JSXClosingElement extends BaseNode {
|
|
1314
|
+
+type: 'JSXClosingElement';
|
|
1315
|
+
+name: JSXTagNameExpression;
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
export interface JSXClosingFragment extends BaseNode {
|
|
1319
|
+
+type: 'JSXClosingFragment';
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
export interface JSXElement extends BaseNode {
|
|
1323
|
+
+type: 'JSXElement';
|
|
1324
|
+
+openingElement: JSXOpeningElement;
|
|
1325
|
+
+closingElement: JSXClosingElement | null;
|
|
1326
|
+
+children: $ReadOnlyArray<JSXChild>;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
export interface JSXEmptyExpression extends BaseNode {
|
|
1330
|
+
+type: 'JSXEmptyExpression';
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
export interface JSXExpressionContainer extends BaseNode {
|
|
1334
|
+
+type: 'JSXExpressionContainer';
|
|
1335
|
+
+expression: Expression;
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
export interface JSXFragment extends BaseNode {
|
|
1339
|
+
+type: 'JSXFragment';
|
|
1340
|
+
+openingFragment: JSXOpeningFragment;
|
|
1341
|
+
+closingFragment: JSXClosingFragment;
|
|
1342
|
+
+children: $ReadOnlyArray<JSXChild>;
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
export interface JSXIdentifier extends BaseNode {
|
|
1346
|
+
+type: 'JSXIdentifier';
|
|
1347
|
+
+name: string;
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
export interface JSXMemberExpression extends BaseNode {
|
|
1351
|
+
+type: 'JSXMemberExpression';
|
|
1352
|
+
+object: JSXTagNameExpression;
|
|
1353
|
+
+property: JSXIdentifier;
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
export interface JSXNamespacedName extends BaseNode {
|
|
1357
|
+
+type: 'JSXNamespacedName';
|
|
1358
|
+
+namespace: JSXIdentifier;
|
|
1359
|
+
+name: JSXIdentifier;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
export interface JSXOpeningElement extends BaseNode {
|
|
1363
|
+
+type: 'JSXOpeningElement';
|
|
1364
|
+
+selfClosing: boolean;
|
|
1365
|
+
+name: JSXTagNameExpression;
|
|
1366
|
+
+attributes: $ReadOnlyArray<JSXAttribute | JSXSpreadAttribute>;
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
export interface JSXOpeningFragment extends BaseNode {
|
|
1370
|
+
+type: 'JSXOpeningFragment';
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
export interface JSXSpreadAttribute extends BaseNode {
|
|
1374
|
+
+type: 'JSXSpreadAttribute';
|
|
1375
|
+
+argument: Expression;
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
export interface JSXText extends BaseNode {
|
|
1379
|
+
+type: 'JSXText';
|
|
1380
|
+
+value: string;
|
|
1381
|
+
+raw: string;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
export interface JSXSpreadChild extends BaseNode {
|
|
1385
|
+
+type: 'JSXSpreadChild';
|
|
1386
|
+
+expression: Expression;
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
/******************************************************
|
|
1390
|
+
* Deprecated spec nodes awaiting migration by Hermes *
|
|
1391
|
+
******************************************************/
|
|
1392
|
+
|
|
1393
|
+
// `ChainExpression` is the new standard for optional chaining
|
|
1394
|
+
export interface OptionalCallExpression extends BaseCallExpression {
|
|
1395
|
+
+type: 'OptionalCallExpression';
|
|
1396
|
+
+optional: boolean;
|
|
1397
|
+
}
|
|
1398
|
+
export interface OptionalMemberExpression extends BaseMemberExpression {
|
|
1399
|
+
+type: 'OptionalMemberExpression';
|
|
1400
|
+
+optional: boolean;
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
// `ExportAllDeclaration` is the new standard for `export * as y from 'z'`
|
|
1404
|
+
export interface ExportNamespaceSpecifier extends BaseNode {
|
|
1405
|
+
+type: 'ExportNamespaceSpecifier';
|
|
1406
|
+
+exported: Identifier;
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
// `Literal` is the new standard for bigints (see the BigIntLiteral interface)
|
|
1410
|
+
export interface BigIntLiteralLegacy extends BaseNode {
|
|
1411
|
+
+type: 'BigIntLiteral';
|
|
1412
|
+
+value: null /* | bigint */;
|
|
1413
|
+
+bigint: string;
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
// `PropertyDefinition` is the new standard for all class properties
|
|
1417
|
+
export interface ClassProperty extends ClassPropertyBase {
|
|
1418
|
+
+type: 'ClassProperty';
|
|
1419
|
+
+computed: false; // flow itself doesn't support computed ClassProperties, even though they might parse fine.
|
|
1420
|
+
}
|
|
1421
|
+
export interface ClassPrivateProperty extends ClassPropertyBase {
|
|
1422
|
+
+type: 'ClassPrivateProperty';
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
// `PrivateIdentifier` is the new standard for #private identifiers
|
|
1426
|
+
export interface PrivateName extends BaseNode {
|
|
1427
|
+
+type: 'PrivateName';
|
|
1428
|
+
+id: Identifier;
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
export {};
|