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