1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | export interface BaseNodeWithoutComments {
|
25 |
|
26 |
|
27 |
|
28 | type: string;
|
29 | loc?: SourceLocation | null | undefined;
|
30 | range?: [number, number] | undefined;
|
31 | }
|
32 |
|
33 | export interface BaseNode extends BaseNodeWithoutComments {
|
34 | leadingComments?: Comment[] | undefined;
|
35 | trailingComments?: Comment[] | undefined;
|
36 | }
|
37 |
|
38 | export interface NodeMap {
|
39 | AssignmentProperty: AssignmentProperty;
|
40 | CatchClause: CatchClause;
|
41 | Class: Class;
|
42 | ClassBody: ClassBody;
|
43 | Expression: Expression;
|
44 | Function: Function;
|
45 | Identifier: Identifier;
|
46 | Literal: Literal;
|
47 | MethodDefinition: MethodDefinition;
|
48 | ModuleDeclaration: ModuleDeclaration;
|
49 | ModuleSpecifier: ModuleSpecifier;
|
50 | Pattern: Pattern;
|
51 | PrivateIdentifier: PrivateIdentifier;
|
52 | Program: Program;
|
53 | Property: Property;
|
54 | PropertyDefinition: PropertyDefinition;
|
55 | SpreadElement: SpreadElement;
|
56 | Statement: Statement;
|
57 | Super: Super;
|
58 | SwitchCase: SwitchCase;
|
59 | TemplateElement: TemplateElement;
|
60 | VariableDeclarator: VariableDeclarator;
|
61 | }
|
62 |
|
63 | export type Node = NodeMap[keyof NodeMap];
|
64 |
|
65 | export interface Comment extends BaseNodeWithoutComments {
|
66 | type: 'Line' | 'Block';
|
67 | value: string;
|
68 | }
|
69 |
|
70 | export interface SourceLocation {
|
71 | source?: string | null | undefined;
|
72 | start: Position;
|
73 | end: Position;
|
74 | }
|
75 |
|
76 | export interface Position {
|
77 |
|
78 | line: number;
|
79 |
|
80 | column: number;
|
81 | }
|
82 |
|
83 | export interface Program extends BaseNode {
|
84 | type: 'Program';
|
85 | sourceType: 'script' | 'module';
|
86 | body: Array<Directive | Statement | ModuleDeclaration>;
|
87 | comments?: Comment[] | undefined;
|
88 | }
|
89 |
|
90 | export interface Directive extends BaseNode {
|
91 | type: 'ExpressionStatement';
|
92 | expression: Literal;
|
93 | directive: string;
|
94 | }
|
95 |
|
96 | export interface BaseFunction extends BaseNode {
|
97 | params: Pattern[];
|
98 | generator?: boolean | undefined;
|
99 | async?: boolean | undefined;
|
100 |
|
101 |
|
102 |
|
103 | body: BlockStatement | Expression;
|
104 | }
|
105 |
|
106 | export type Function = FunctionDeclaration | FunctionExpression | ArrowFunctionExpression;
|
107 |
|
108 | export type Statement =
|
109 | | ExpressionStatement
|
110 | | BlockStatement
|
111 | | StaticBlock
|
112 | | EmptyStatement
|
113 | | DebuggerStatement
|
114 | | WithStatement
|
115 | | ReturnStatement
|
116 | | LabeledStatement
|
117 | | BreakStatement
|
118 | | ContinueStatement
|
119 | | IfStatement
|
120 | | SwitchStatement
|
121 | | ThrowStatement
|
122 | | TryStatement
|
123 | | WhileStatement
|
124 | | DoWhileStatement
|
125 | | ForStatement
|
126 | | ForInStatement
|
127 | | ForOfStatement
|
128 | | Declaration;
|
129 |
|
130 | export interface BaseStatement extends BaseNode {}
|
131 |
|
132 | export interface EmptyStatement extends BaseStatement {
|
133 | type: 'EmptyStatement';
|
134 | }
|
135 |
|
136 | export interface BlockStatement extends BaseStatement {
|
137 | type: 'BlockStatement';
|
138 | body: Statement[];
|
139 | innerComments?: Comment[] | undefined;
|
140 | }
|
141 |
|
142 | export interface StaticBlock extends Omit<BlockStatement, 'type'> {
|
143 | type: 'StaticBlock';
|
144 | }
|
145 |
|
146 | export interface ExpressionStatement extends BaseStatement {
|
147 | type: 'ExpressionStatement';
|
148 | expression: Expression;
|
149 | }
|
150 |
|
151 | export interface IfStatement extends BaseStatement {
|
152 | type: 'IfStatement';
|
153 | test: Expression;
|
154 | consequent: Statement;
|
155 | alternate?: Statement | null | undefined;
|
156 | }
|
157 |
|
158 | export interface LabeledStatement extends BaseStatement {
|
159 | type: 'LabeledStatement';
|
160 | label: Identifier;
|
161 | body: Statement;
|
162 | }
|
163 |
|
164 | export interface BreakStatement extends BaseStatement {
|
165 | type: 'BreakStatement';
|
166 | label?: Identifier | null | undefined;
|
167 | }
|
168 |
|
169 | export interface ContinueStatement extends BaseStatement {
|
170 | type: 'ContinueStatement';
|
171 | label?: Identifier | null | undefined;
|
172 | }
|
173 |
|
174 | export interface WithStatement extends BaseStatement {
|
175 | type: 'WithStatement';
|
176 | object: Expression;
|
177 | body: Statement;
|
178 | }
|
179 |
|
180 | export interface SwitchStatement extends BaseStatement {
|
181 | type: 'SwitchStatement';
|
182 | discriminant: Expression;
|
183 | cases: SwitchCase[];
|
184 | }
|
185 |
|
186 | export interface ReturnStatement extends BaseStatement {
|
187 | type: 'ReturnStatement';
|
188 | argument?: Expression | null | undefined;
|
189 | }
|
190 |
|
191 | export interface ThrowStatement extends BaseStatement {
|
192 | type: 'ThrowStatement';
|
193 | argument: Expression;
|
194 | }
|
195 |
|
196 | export interface TryStatement extends BaseStatement {
|
197 | type: 'TryStatement';
|
198 | block: BlockStatement;
|
199 | handler?: CatchClause | null | undefined;
|
200 | finalizer?: BlockStatement | null | undefined;
|
201 | }
|
202 |
|
203 | export interface WhileStatement extends BaseStatement {
|
204 | type: 'WhileStatement';
|
205 | test: Expression;
|
206 | body: Statement;
|
207 | }
|
208 |
|
209 | export interface DoWhileStatement extends BaseStatement {
|
210 | type: 'DoWhileStatement';
|
211 | body: Statement;
|
212 | test: Expression;
|
213 | }
|
214 |
|
215 | export interface ForStatement extends BaseStatement {
|
216 | type: 'ForStatement';
|
217 | init?: VariableDeclaration | Expression | null | undefined;
|
218 | test?: Expression | null | undefined;
|
219 | update?: Expression | null | undefined;
|
220 | body: Statement;
|
221 | }
|
222 |
|
223 | export interface BaseForXStatement extends BaseStatement {
|
224 | left: VariableDeclaration | Pattern;
|
225 | right: Expression;
|
226 | body: Statement;
|
227 | }
|
228 |
|
229 | export interface ForInStatement extends BaseForXStatement {
|
230 | type: 'ForInStatement';
|
231 | }
|
232 |
|
233 | export interface DebuggerStatement extends BaseStatement {
|
234 | type: 'DebuggerStatement';
|
235 | }
|
236 |
|
237 | export type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration;
|
238 |
|
239 | export interface BaseDeclaration extends BaseStatement {}
|
240 |
|
241 | export interface FunctionDeclaration extends BaseFunction, BaseDeclaration {
|
242 | type: 'FunctionDeclaration';
|
243 |
|
244 | id: Identifier | null;
|
245 | body: BlockStatement;
|
246 | }
|
247 |
|
248 | export interface VariableDeclaration extends BaseDeclaration {
|
249 | type: 'VariableDeclaration';
|
250 | declarations: VariableDeclarator[];
|
251 | kind: 'var' | 'let' | 'const';
|
252 | }
|
253 |
|
254 | export interface VariableDeclarator extends BaseNode {
|
255 | type: 'VariableDeclarator';
|
256 | id: Pattern;
|
257 | init?: Expression | null | undefined;
|
258 | }
|
259 |
|
260 | export interface ExpressionMap {
|
261 | ArrayExpression: ArrayExpression;
|
262 | ArrowFunctionExpression: ArrowFunctionExpression;
|
263 | AssignmentExpression: AssignmentExpression;
|
264 | AwaitExpression: AwaitExpression;
|
265 | BinaryExpression: BinaryExpression;
|
266 | CallExpression: CallExpression;
|
267 | ChainExpression: ChainExpression;
|
268 | ClassExpression: ClassExpression;
|
269 | ConditionalExpression: ConditionalExpression;
|
270 | FunctionExpression: FunctionExpression;
|
271 | Identifier: Identifier;
|
272 | ImportExpression: ImportExpression;
|
273 | Literal: Literal;
|
274 | LogicalExpression: LogicalExpression;
|
275 | MemberExpression: MemberExpression;
|
276 | MetaProperty: MetaProperty;
|
277 | NewExpression: NewExpression;
|
278 | ObjectExpression: ObjectExpression;
|
279 | SequenceExpression: SequenceExpression;
|
280 | TaggedTemplateExpression: TaggedTemplateExpression;
|
281 | TemplateLiteral: TemplateLiteral;
|
282 | ThisExpression: ThisExpression;
|
283 | UnaryExpression: UnaryExpression;
|
284 | UpdateExpression: UpdateExpression;
|
285 | YieldExpression: YieldExpression;
|
286 | }
|
287 |
|
288 | export type Expression = ExpressionMap[keyof ExpressionMap];
|
289 |
|
290 | export interface BaseExpression extends BaseNode {}
|
291 |
|
292 | export type ChainElement = SimpleCallExpression | MemberExpression;
|
293 |
|
294 | export interface ChainExpression extends BaseExpression {
|
295 | type: 'ChainExpression';
|
296 | expression: ChainElement;
|
297 | }
|
298 |
|
299 | export interface ThisExpression extends BaseExpression {
|
300 | type: 'ThisExpression';
|
301 | }
|
302 |
|
303 | export interface ArrayExpression extends BaseExpression {
|
304 | type: 'ArrayExpression';
|
305 | elements: Array<Expression | SpreadElement | null>;
|
306 | }
|
307 |
|
308 | export interface ObjectExpression extends BaseExpression {
|
309 | type: 'ObjectExpression';
|
310 | properties: Array<Property | SpreadElement>;
|
311 | }
|
312 |
|
313 | export interface PrivateIdentifier extends BaseNode {
|
314 | type: 'PrivateIdentifier';
|
315 | name: string;
|
316 | }
|
317 |
|
318 | export interface Property extends BaseNode {
|
319 | type: 'Property';
|
320 | key: Expression | PrivateIdentifier;
|
321 | value: Expression | Pattern;
|
322 | kind: 'init' | 'get' | 'set';
|
323 | method: boolean;
|
324 | shorthand: boolean;
|
325 | computed: boolean;
|
326 | }
|
327 |
|
328 | export interface PropertyDefinition extends BaseNode {
|
329 | type: 'PropertyDefinition';
|
330 | key: Expression | PrivateIdentifier;
|
331 | value?: Expression | null | undefined;
|
332 | computed: boolean;
|
333 | static: boolean;
|
334 | }
|
335 |
|
336 | export interface FunctionExpression extends BaseFunction, BaseExpression {
|
337 | id?: Identifier | null | undefined;
|
338 | type: 'FunctionExpression';
|
339 | body: BlockStatement;
|
340 | }
|
341 |
|
342 | export interface SequenceExpression extends BaseExpression {
|
343 | type: 'SequenceExpression';
|
344 | expressions: Expression[];
|
345 | }
|
346 |
|
347 | export interface UnaryExpression extends BaseExpression {
|
348 | type: 'UnaryExpression';
|
349 | operator: UnaryOperator;
|
350 | prefix: true;
|
351 | argument: Expression;
|
352 | }
|
353 |
|
354 | export interface BinaryExpression extends BaseExpression {
|
355 | type: 'BinaryExpression';
|
356 | operator: BinaryOperator;
|
357 | left: Expression;
|
358 | right: Expression;
|
359 | }
|
360 |
|
361 | export interface AssignmentExpression extends BaseExpression {
|
362 | type: 'AssignmentExpression';
|
363 | operator: AssignmentOperator;
|
364 | left: Pattern | MemberExpression;
|
365 | right: Expression;
|
366 | }
|
367 |
|
368 | export interface UpdateExpression extends BaseExpression {
|
369 | type: 'UpdateExpression';
|
370 | operator: UpdateOperator;
|
371 | argument: Expression;
|
372 | prefix: boolean;
|
373 | }
|
374 |
|
375 | export interface LogicalExpression extends BaseExpression {
|
376 | type: 'LogicalExpression';
|
377 | operator: LogicalOperator;
|
378 | left: Expression;
|
379 | right: Expression;
|
380 | }
|
381 |
|
382 | export interface ConditionalExpression extends BaseExpression {
|
383 | type: 'ConditionalExpression';
|
384 | test: Expression;
|
385 | alternate: Expression;
|
386 | consequent: Expression;
|
387 | }
|
388 |
|
389 | export interface BaseCallExpression extends BaseExpression {
|
390 | callee: Expression | Super;
|
391 | arguments: Array<Expression | SpreadElement>;
|
392 | }
|
393 | export type CallExpression = SimpleCallExpression | NewExpression;
|
394 |
|
395 | export interface SimpleCallExpression extends BaseCallExpression {
|
396 | type: 'CallExpression';
|
397 | optional: boolean;
|
398 | }
|
399 |
|
400 | export interface NewExpression extends BaseCallExpression {
|
401 | type: 'NewExpression';
|
402 | }
|
403 |
|
404 | export interface MemberExpression extends BaseExpression, BasePattern {
|
405 | type: 'MemberExpression';
|
406 | object: Expression | Super;
|
407 | property: Expression | PrivateIdentifier;
|
408 | computed: boolean;
|
409 | optional: boolean;
|
410 | }
|
411 |
|
412 | export type Pattern = Identifier | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | MemberExpression;
|
413 |
|
414 | export interface BasePattern extends BaseNode {}
|
415 |
|
416 | export interface SwitchCase extends BaseNode {
|
417 | type: 'SwitchCase';
|
418 | test?: Expression | null | undefined;
|
419 | consequent: Statement[];
|
420 | }
|
421 |
|
422 | export interface CatchClause extends BaseNode {
|
423 | type: 'CatchClause';
|
424 | param: Pattern | null;
|
425 | body: BlockStatement;
|
426 | }
|
427 |
|
428 | export interface Identifier extends BaseNode, BaseExpression, BasePattern {
|
429 | type: 'Identifier';
|
430 | name: string;
|
431 | }
|
432 |
|
433 | export type Literal = SimpleLiteral | RegExpLiteral | BigIntLiteral;
|
434 |
|
435 | export interface SimpleLiteral extends BaseNode, BaseExpression {
|
436 | type: 'Literal';
|
437 | value: string | boolean | number | null;
|
438 | raw?: string | undefined;
|
439 | }
|
440 |
|
441 | export interface RegExpLiteral extends BaseNode, BaseExpression {
|
442 | type: 'Literal';
|
443 | value?: RegExp | null | undefined;
|
444 | regex: {
|
445 | pattern: string;
|
446 | flags: string;
|
447 | };
|
448 | raw?: string | undefined;
|
449 | }
|
450 |
|
451 | export interface BigIntLiteral extends BaseNode, BaseExpression {
|
452 | type: 'Literal';
|
453 | value?: bigint | null | undefined;
|
454 | bigint: string;
|
455 | raw?: string | undefined;
|
456 | }
|
457 |
|
458 | export type UnaryOperator = '-' | '+' | '!' | '~' | 'typeof' | 'void' | 'delete';
|
459 |
|
460 | export type BinaryOperator =
|
461 | | '=='
|
462 | | '!='
|
463 | | '==='
|
464 | | '!=='
|
465 | | '<'
|
466 | | '<='
|
467 | | '>'
|
468 | | '>='
|
469 | | '<<'
|
470 | | '>>'
|
471 | | '>>>'
|
472 | | '+'
|
473 | | '-'
|
474 | | '*'
|
475 | | '/'
|
476 | | '%'
|
477 | | '**'
|
478 | | '|'
|
479 | | '^'
|
480 | | '&'
|
481 | | 'in'
|
482 | | 'instanceof';
|
483 |
|
484 | export type LogicalOperator = '||' | '&&' | '??';
|
485 |
|
486 | export type AssignmentOperator =
|
487 | | '='
|
488 | | '+='
|
489 | | '-='
|
490 | | '*='
|
491 | | '/='
|
492 | | '%='
|
493 | | '**='
|
494 | | '<<='
|
495 | | '>>='
|
496 | | '>>>='
|
497 | | '|='
|
498 | | '^='
|
499 | | '&=';
|
500 |
|
501 | export type UpdateOperator = '++' | '--';
|
502 |
|
503 | export interface ForOfStatement extends BaseForXStatement {
|
504 | type: 'ForOfStatement';
|
505 | await: boolean;
|
506 | }
|
507 |
|
508 | export interface Super extends BaseNode {
|
509 | type: 'Super';
|
510 | }
|
511 |
|
512 | export interface SpreadElement extends BaseNode {
|
513 | type: 'SpreadElement';
|
514 | argument: Expression;
|
515 | }
|
516 |
|
517 | export interface ArrowFunctionExpression extends BaseExpression, BaseFunction {
|
518 | type: 'ArrowFunctionExpression';
|
519 | expression: boolean;
|
520 | body: BlockStatement | Expression;
|
521 | }
|
522 |
|
523 | export interface YieldExpression extends BaseExpression {
|
524 | type: 'YieldExpression';
|
525 | argument?: Expression | null | undefined;
|
526 | delegate: boolean;
|
527 | }
|
528 |
|
529 | export interface TemplateLiteral extends BaseExpression {
|
530 | type: 'TemplateLiteral';
|
531 | quasis: TemplateElement[];
|
532 | expressions: Expression[];
|
533 | }
|
534 |
|
535 | export interface TaggedTemplateExpression extends BaseExpression {
|
536 | type: 'TaggedTemplateExpression';
|
537 | tag: Expression;
|
538 | quasi: TemplateLiteral;
|
539 | }
|
540 |
|
541 | export interface TemplateElement extends BaseNode {
|
542 | type: 'TemplateElement';
|
543 | tail: boolean;
|
544 | value: {
|
545 |
|
546 | cooked?: string | null | undefined;
|
547 | raw: string;
|
548 | };
|
549 | }
|
550 |
|
551 | export interface AssignmentProperty extends Property {
|
552 | value: Pattern;
|
553 | kind: 'init';
|
554 | method: boolean;
|
555 | }
|
556 |
|
557 | export interface ObjectPattern extends BasePattern {
|
558 | type: 'ObjectPattern';
|
559 | properties: Array<AssignmentProperty | RestElement>;
|
560 | }
|
561 |
|
562 | export interface ArrayPattern extends BasePattern {
|
563 | type: 'ArrayPattern';
|
564 | elements: Array<Pattern | null>;
|
565 | }
|
566 |
|
567 | export interface RestElement extends BasePattern {
|
568 | type: 'RestElement';
|
569 | argument: Pattern;
|
570 | }
|
571 |
|
572 | export interface AssignmentPattern extends BasePattern {
|
573 | type: 'AssignmentPattern';
|
574 | left: Pattern;
|
575 | right: Expression;
|
576 | }
|
577 |
|
578 | export type Class = ClassDeclaration | ClassExpression;
|
579 | export interface BaseClass extends BaseNode {
|
580 | superClass?: Expression | null | undefined;
|
581 | body: ClassBody;
|
582 | }
|
583 |
|
584 | export interface ClassBody extends BaseNode {
|
585 | type: 'ClassBody';
|
586 | body: Array<MethodDefinition | PropertyDefinition | StaticBlock>;
|
587 | }
|
588 |
|
589 | export interface MethodDefinition extends BaseNode {
|
590 | type: 'MethodDefinition';
|
591 | key: Expression | PrivateIdentifier;
|
592 | value: FunctionExpression;
|
593 | kind: 'constructor' | 'method' | 'get' | 'set';
|
594 | computed: boolean;
|
595 | static: boolean;
|
596 | }
|
597 |
|
598 | export interface ClassDeclaration extends BaseClass, BaseDeclaration {
|
599 | type: 'ClassDeclaration';
|
600 |
|
601 | id: Identifier | null;
|
602 | }
|
603 |
|
604 | export interface ClassExpression extends BaseClass, BaseExpression {
|
605 | type: 'ClassExpression';
|
606 | id?: Identifier | null | undefined;
|
607 | }
|
608 |
|
609 | export interface MetaProperty extends BaseExpression {
|
610 | type: 'MetaProperty';
|
611 | meta: Identifier;
|
612 | property: Identifier;
|
613 | }
|
614 |
|
615 | export type ModuleDeclaration =
|
616 | | ImportDeclaration
|
617 | | ExportNamedDeclaration
|
618 | | ExportDefaultDeclaration
|
619 | | ExportAllDeclaration;
|
620 | export interface BaseModuleDeclaration extends BaseNode {}
|
621 |
|
622 | export type ModuleSpecifier = ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier;
|
623 | export interface BaseModuleSpecifier extends BaseNode {
|
624 | local: Identifier;
|
625 | }
|
626 |
|
627 | export interface ImportDeclaration extends BaseModuleDeclaration {
|
628 | type: 'ImportDeclaration';
|
629 | specifiers: Array<ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier>;
|
630 | source: Literal;
|
631 | }
|
632 |
|
633 | export interface ImportSpecifier extends BaseModuleSpecifier {
|
634 | type: 'ImportSpecifier';
|
635 | imported: Identifier;
|
636 | }
|
637 |
|
638 | export interface ImportExpression extends BaseExpression {
|
639 | type: 'ImportExpression';
|
640 | source: Expression;
|
641 | }
|
642 |
|
643 | export interface ImportDefaultSpecifier extends BaseModuleSpecifier {
|
644 | type: 'ImportDefaultSpecifier';
|
645 | }
|
646 |
|
647 | export interface ImportNamespaceSpecifier extends BaseModuleSpecifier {
|
648 | type: 'ImportNamespaceSpecifier';
|
649 | }
|
650 |
|
651 | export interface ExportNamedDeclaration extends BaseModuleDeclaration {
|
652 | type: 'ExportNamedDeclaration';
|
653 | declaration?: Declaration | null | undefined;
|
654 | specifiers: ExportSpecifier[];
|
655 | source?: Literal | null | undefined;
|
656 | }
|
657 |
|
658 | export interface ExportSpecifier extends BaseModuleSpecifier {
|
659 | type: 'ExportSpecifier';
|
660 | exported: Identifier;
|
661 | }
|
662 |
|
663 | export interface ExportDefaultDeclaration extends BaseModuleDeclaration {
|
664 | type: 'ExportDefaultDeclaration';
|
665 | declaration: Declaration | Expression;
|
666 | }
|
667 |
|
668 | export interface ExportAllDeclaration extends BaseModuleDeclaration {
|
669 | type: 'ExportAllDeclaration';
|
670 | exported: Identifier | null;
|
671 | source: Literal;
|
672 | }
|
673 |
|
674 | export interface AwaitExpression extends BaseExpression {
|
675 | type: 'AwaitExpression';
|
676 | argument: Expression;
|
677 | }
|