Debian Codegraph @

packages/babel-parser/ast/spec.md

raw
1 These are the core @babel/parser (babylon) AST node types.
2
3 - [Node objects](#node-objects)
4 - [Changes](#changes)
5 - [Identifier](#identifier)
6 - [PrivateName](#privatename)
7 - [Literals](#literals)
8 - [RegExpLiteral](#regexpliteral)
9 - [NullLiteral](#nullliteral)
10 - [StringLiteral](#stringliteral)
11 - [BooleanLiteral](#booleanliteral)
12 - [NumericLiteral](#numericliteral)
13 - [BigIntLiteral](#bigintliteral)
14 - [DecimalLiteral](#decimalliteral)
15 - [Programs](#programs)
16 - [Functions](#functions)
17 - [Statements](#statements)
18 - [ExpressionStatement](#expressionstatement)
19 - [BlockStatement](#blockstatement)
20 - [EmptyStatement](#emptystatement)
21 - [DebuggerStatement](#debuggerstatement)
22 - [WithStatement](#withstatement)
23 - [Control flow](#control-flow)
24 - [ReturnStatement](#returnstatement)
25 - [LabeledStatement](#labeledstatement)
26 - [BreakStatement](#breakstatement)
27 - [ContinueStatement](#continuestatement)
28 - [Choice](#choice)
29 - [IfStatement](#ifstatement)
30 - [SwitchStatement](#switchstatement)
31 - [SwitchCase](#switchcase)
32 - [Exceptions](#exceptions)
33 - [ThrowStatement](#throwstatement)
34 - [TryStatement](#trystatement)
35 - [CatchClause](#catchclause)
36 - [Loops](#loops)
37 - [WhileStatement](#whilestatement)
38 - [DoWhileStatement](#dowhilestatement)
39 - [ForStatement](#forstatement)
40 - [ForInStatement](#forinstatement)
41 - [ForOfStatement](#forofstatement)
42 - [Declarations](#declarations)
43 - [FunctionDeclaration](#functiondeclaration)
44 - [VariableDeclaration](#variabledeclaration)
45 - [VariableDeclarator](#variabledeclarator)
46 - [Misc](#misc)
47 - [Decorator](#decorator)
48 - [Directive](#directive)
49 - [DirectiveLiteral](#directiveliteral)
50 - [InterpreterDirective](#interpreterdirective)
51 - [Expressions](#expressions)
52 - [Super](#super)
53 - [Import](#import)
54 - [ThisExpression](#thisexpression)
55 - [ArrowFunctionExpression](#arrowfunctionexpression)
56 - [YieldExpression](#yieldexpression)
57 - [AwaitExpression](#awaitexpression)
58 - [ArrayExpression](#arrayexpression)
59 - [ObjectExpression](#objectexpression)
60 - [ObjectMember](#objectmember)
61 - [ObjectProperty](#objectproperty)
62 - [ObjectMethod](#objectmethod)
63 - [RecordExpression](#recordexpression)
64 - [TupleExpression](#tupleexpression)
65 - [FunctionExpression](#functionexpression)
66 - [Unary operations](#unary-operations)
67 - [UnaryExpression](#unaryexpression)
68 - [UnaryOperator](#unaryoperator)
69 - [UpdateExpression](#updateexpression)
70 - [UpdateOperator](#updateoperator)
71 - [Binary operations](#binary-operations)
72 - [BinaryExpression](#binaryexpression)
73 - [BinaryOperator](#binaryoperator)
74 - [AssignmentExpression](#assignmentexpression)
75 - [AssignmentOperator](#assignmentoperator)
76 - [LogicalExpression](#logicalexpression)
77 - [LogicalOperator](#logicaloperator)
78 - [SpreadElement](#spreadelement)
79 - [ArgumentPlaceholder](#argumentplaceholder)
80 - [MemberExpression](#memberexpression)
81 - [OptionalMemberExpression](#optionalmemberexpression)
82 - [BindExpression](#bindexpression)
83 - [ConditionalExpression](#conditionalexpression)
84 - [CallExpression](#callexpression)
85 - [OptionalCallExpression](#optionalcallexpression)
86 - [NewExpression](#newexpression)
87 - [SequenceExpression](#sequenceexpression)
88 - [ParenthesizedExpression](#parenthesizedexpression)
89 - [DoExpression](#doexpression)
90 - [ModuleExpression](#moduleexpression)
91 - [Template Literals](#template-literals)
92 - [TemplateLiteral](#templateliteral)
93 - [TaggedTemplateExpression](#taggedtemplateexpression)
94 - [TemplateElement](#templateelement)
95 - [Patterns](#patterns)
96 - [ObjectPattern](#objectpattern)
97 - [ArrayPattern](#arraypattern)
98 - [RestElement](#restelement)
99 - [AssignmentPattern](#assignmentpattern)
100 - [Classes](#classes)
101 - [ClassBody](#classbody)
102 - [ClassMethod](#classmethod)
103 - [ClassPrivateMethod](#classprivatemethod)
104 - [ClassProperty](#classproperty)
105 - [ClassPrivateProperty](#classprivateproperty)
106 - [StaticBlock](#staticblock)
107 - [ClassDeclaration](#classdeclaration)
108 - [ClassExpression](#classexpression)
109 - [MetaProperty](#metaproperty)
110 - [Modules](#modules)
111 - [ModuleSpecifier](#modulespecifier)
112 - [Imports](#imports)
113 - [ImportDeclaration](#importdeclaration)
114 - [ImportSpecifier](#importspecifier)
115 - [ImportDefaultSpecifier](#importdefaultspecifier)
116 - [ImportNamespaceSpecifier](#importnamespacespecifier)
117 - [ImportAttribute](#importattribute)
118 - [Exports](#exports)
119 - [ExportDeclaration](#exportdeclaration)
120 - [ExportNamedDeclaration](#exportnameddeclaration)
121 - [ExportSpecifier](#exportspecifier)
122 - [ExportNamespaceSpecifier](#exportnamespacespecifier)
123 - [ExportDefaultDeclaration](#exportdefaultdeclaration)
124 - [ExportAllDeclaration](#exportalldeclaration)
125
126 # Node objects
127
128 AST nodes are represented as `Node` objects, which may have any prototype inheritance but which implement the following interface:
129
130 ```js
131 interface Node {
132 type: string;
133 loc: SourceLocation | null;
134 }
135 ```
136
137 The `type` field is a string representing the AST variant type. Each subtype of `Node` is documented below with the specific string of its `type` field. You can use this field to determine which interface a node implements.
138
139 The `loc` field represents the source location information of the node. If the node contains no information about the source location, the field is `null`; otherwise it is an object consisting of a start position (the position of the first character of the parsed source region) and an end position (the position of the first character after the parsed source region):
140
141 ```js
142 interface SourceLocation {
143 source: string | null;
144 start: Position;
145 end: Position;
146 }
147 ```
148
149 Each `Position` object consists of a `line` number (1-indexed) and a `column` number (0-indexed):
150
151 ```js
152 interface Position {
153 line: number; // >= 1
154 column: number; // >= 0
155 }
156 ```
157
158 # Changes
159
160 ### @babel/parser (Babylon) v7
161
162 Flow: Node renamed from `ExistentialTypeParam` to `ExistsTypeAnnotation` [#322](https://github.com/babel/babylon/pull/322)
163
164 Flow: Node renamed from `NumericLiteralTypeAnnotation` to `NumberLiteralTypeAnnotation` [babel/babylon#332](https://github.com/babel/babylon/pull/332)
165
166 Flow: Node `Variance` which replaces the string value of the `variance` field on several nodes [babel/babylon#333](https://github.com/babel/babylon/pull/333)
167
168 Flow: `ObjectTypeIndexer` location info matches Flow's better [babel/babylon#228](https://github.com/babel/babylon/pull/228)
169
170 Node `ForAwaitStatement` has been removed [#349](https://github.com/babel/babylon/pull/349) in favor of modifying `ForOfStatement`
171
172 `RestProperty` and `SpreadProperty` have been dropped in favor of `RestElement` and `SpreadElement`.
173
174 # Identifier
175
176 ```js
177 interface Identifier <: Expression, Pattern {
178 type: "Identifier";
179 name: string;
180 }
181 ```
182
183 An identifier. Note that an identifier may be an expression or a destructuring pattern.
184
185 # PrivateName
186
187 ```js
188 interface PrivateName <: Node {
189 type: "PrivateName";
190 id: Identifier;
191 }
192 ```
193
194 A Private Name Identifier.
195
196 # Literals
197
198 ```js
199 interface Literal <: Expression { }
200 ```
201
202 A literal token. May or may not represent an expression.
203
204 ## RegExpLiteral
205
206 ```js
207 interface RegExpLiteral <: Literal {
208 type: "RegExpLiteral";
209 pattern: string;
210 flags: string;
211 }
212 ```
213
214 ## NullLiteral
215
216 ```js
217 interface NullLiteral <: Literal {
218 type: "NullLiteral";
219 }
220 ```
221
222 ## StringLiteral
223
224 ```js
225 interface StringLiteral <: Literal {
226 type: "StringLiteral";
227 value: string;
228 }
229 ```
230
231 ## BooleanLiteral
232
233 ```js
234 interface BooleanLiteral <: Literal {
235 type: "BooleanLiteral";
236 value: boolean;
237 }
238 ```
239
240 ## NumericLiteral
241
242 ```js
243 interface NumericLiteral <: Literal {
244 type: "NumericLiteral";
245 value: number;
246 }
247 ```
248
249 ## BigIntLiteral
250
251 ```js
252 interface BigIntLiteral <: Literal {
253 type: "BigIntLiteral";
254 value: string;
255 }
256 ```
257
258 The `value` property is the string representation of the `BigInt` value. It doesn't include the suffix `n`.
259
260 ## DecimalLiteral
261
262 ```js
263 interface DecimalLiteral <: Literal {
264 type: "DecimalLiteral";
265 value: string;
266 }
267 ```
268
269 The `value` property is the string representation of the `BigDecimal` value. It doesn't include the suffix `m`.
270
271 # Programs
272
273 ```js
274 interface Program <: Node {
275 type: "Program";
276 interpreter: InterpreterDirective | null;
277 sourceType: "script" | "module";
278 body: [ Statement | ImportDeclaration | ExportDeclaration ];
279 directives: [ Directive ];
280 }
281 ```
282
283 A complete program source tree.
284
285 Parsers must specify `sourceType` as `"module"` if the source has been parsed as an ES6 module. Otherwise, `sourceType` must be `"script"`.
286
287 # Functions
288
289 ```js
290 interface Function <: Node {
291 id: Identifier | null;
292 params: [ Pattern ];
293 body: BlockStatement;
294 generator: boolean;
295 async: boolean;
296 }
297 ```
298
299 A function [declaration](#functiondeclaration) or [expression](#functionexpression).
300
301 # Statements
302
303 ```js
304 interface Statement <: Node { }
305 ```
306
307 Any statement.
308
309 ## ExpressionStatement
310
311 ```js
312 interface ExpressionStatement <: Statement {
313 type: "ExpressionStatement";
314 expression: Expression;
315 }
316 ```
317
318 An expression statement, i.e., a statement consisting of a single expression.
319
320 ## BlockStatement
321
322 ```js
323 interface BlockStatement <: Statement {
324 type: "BlockStatement";
325 body: [ Statement ];
326 directives: [ Directive ];
327 }
328 ```
329
330 A block statement, i.e., a sequence of statements surrounded by braces.
331
332 ## EmptyStatement
333
334 ```js
335 interface EmptyStatement <: Statement {
336 type: "EmptyStatement";
337 }
338 ```
339
340 An empty statement, i.e., a solitary semicolon.
341
342 ## DebuggerStatement
343
344 ```js
345 interface DebuggerStatement <: Statement {
346 type: "DebuggerStatement";
347 }
348 ```
349
350 A `debugger` statement.
351
352 ## WithStatement
353
354 ```js
355 interface WithStatement <: Statement {
356 type: "WithStatement";
357 object: Expression;
358 body: Statement;
359 }
360 ```
361
362 A `with` statement.
363
364 ## Control flow
365
366 ### ReturnStatement
367
368 ```js
369 interface ReturnStatement <: Statement {
370 type: "ReturnStatement";
371 argument: Expression | null;
372 }
373 ```
374
375 A `return` statement.
376
377 ### LabeledStatement
378
379 ```js
380 interface LabeledStatement <: Statement {
381 type: "LabeledStatement";
382 label: Identifier;
383 body: Statement;
384 }
385 ```
386
387 A labeled statement, i.e., a statement prefixed by a `break`/`continue` label.
388
389 ### BreakStatement
390
391 ```js
392 interface BreakStatement <: Statement {
393 type: "BreakStatement";
394 label: Identifier | null;
395 }
396 ```
397
398 A `break` statement.
399
400 ### ContinueStatement
401
402 ```js
403 interface ContinueStatement <: Statement {
404 type: "ContinueStatement";
405 label: Identifier | null;
406 }
407 ```
408
409 A `continue` statement.
410
411 ## Choice
412
413 ### IfStatement
414
415 ```js
416 interface IfStatement <: Statement {
417 type: "IfStatement";
418 test: Expression;
419 consequent: Statement;
420 alternate: Statement | null;
421 }
422 ```
423
424 An `if` statement.
425
426 ### SwitchStatement
427
428 ```js
429 interface SwitchStatement <: Statement {
430 type: "SwitchStatement";
431 discriminant: Expression;
432 cases: [ SwitchCase ];
433 }
434 ```
435
436 A `switch` statement.
437
438 #### SwitchCase
439
440 ```js
441 interface SwitchCase <: Node {
442 type: "SwitchCase";
443 test: Expression | null;
444 consequent: [ Statement ];
445 }
446 ```
447
448 A `case` (if `test` is an `Expression`) or `default` (if `test === null`) clause in the body of a `switch` statement.
449
450 ## Exceptions
451
452 ### ThrowStatement
453
454 ```js
455 interface ThrowStatement <: Statement {
456 type: "ThrowStatement";
457 argument: Expression;
458 }
459 ```
460
461 A `throw` statement.
462
463 ### TryStatement
464
465 ```js
466 interface TryStatement <: Statement {
467 type: "TryStatement";
468 block: BlockStatement;
469 handler: CatchClause | null;
470 finalizer: BlockStatement | null;
471 }
472 ```
473
474 A `try` statement. If `handler` is `null` then `finalizer` must be a `BlockStatement`.
475
476 #### CatchClause
477
478 ```js
479 interface CatchClause <: Node {
480 type: "CatchClause";
481 param?: Pattern;
482 body: BlockStatement;
483 }
484 ```
485
486 A `catch` clause following a `try` block.
487
488 ## Loops
489
490 ### WhileStatement
491
492 ```js
493 interface WhileStatement <: Statement {
494 type: "WhileStatement";
495 test: Expression;
496 body: Statement;
497 }
498 ```
499
500 A `while` statement.
501
502 ### DoWhileStatement
503
504 ```js
505 interface DoWhileStatement <: Statement {
506 type: "DoWhileStatement";
507 body: Statement;
508 test: Expression;
509 }
510 ```
511
512 A `do`/`while` statement.
513
514 ### ForStatement
515
516 ```js
517 interface ForStatement <: Statement {
518 type: "ForStatement";
519 init: VariableDeclaration | Expression | null;
520 test: Expression | null;
521 update: Expression | null;
522 body: Statement;
523 }
524 ```
525
526 A `for` statement.
527
528 ### ForInStatement
529
530 ```js
531 interface ForInStatement <: Statement {
532 type: "ForInStatement";
533 left: VariableDeclaration | Expression;
534 right: Expression;
535 body: Statement;
536 }
537 ```
538
539 A `for`/`in` statement.
540
541 ## ForOfStatement
542
543 ```js
544 interface ForOfStatement <: ForInStatement {
545 type: "ForOfStatement";
546 await: boolean;
547 }
548 ```
549
550 # Declarations
551
552 ```js
553 interface Declaration <: Statement { }
554 ```
555
556 Any declaration node. Note that declarations are considered statements; this is because declarations can appear in any statement context.
557
558 ## FunctionDeclaration
559
560 ```js
561 interface FunctionDeclaration <: Function, Declaration {
562 type: "FunctionDeclaration";
563 id: Identifier;
564 }
565 ```
566
567 A function declaration. Note that unlike in the parent interface `Function`, the `id` cannot be `null`, except when this is the child of an `ExportDefaultDeclaration`.
568
569 ## VariableDeclaration
570
571 ```js
572 interface VariableDeclaration <: Declaration {
573 type: "VariableDeclaration";
574 declarations: [ VariableDeclarator ];
575 kind: "var" | "let" | "const" | "using";
576 }
577 ```
578
579 A variable declaration.
580
581 ### VariableDeclarator
582
583 ```js
584 interface VariableDeclarator <: Node {
585 type: "VariableDeclarator";
586 id: Pattern;
587 init: Expression | null;
588 }
589 ```
590
591 A variable declarator.
592
593 # Misc
594
595 ## Decorator
596
597 ```js
598 interface Decorator <: Node {
599 type: "Decorator";
600 expression: Expression;
601 }
602 ```
603
604 ## Directive
605
606 ```js
607 interface Directive <: Node {
608 type: "Directive";
609 value: DirectiveLiteral;
610 }
611 ```
612
613 ## DirectiveLiteral
614
615 ```js
616 interface DirectiveLiteral <: StringLiteral {
617 type: "DirectiveLiteral";
618 }
619 ```
620
621 ## InterpreterDirective
622
623 ```js
624 interface InterpreterDirective <: StringLiteral {
625 type: "InterpreterDirective";
626 }
627 ```
628
629 # Expressions
630
631 ```js
632 interface Expression <: Node { }
633 ```
634
635 Any expression node. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern.
636
637 ## Super
638
639 ```js
640 interface Super <: Node {
641 type: "Super";
642 }
643 ```
644
645 A `super` pseudo-expression.
646
647 ## Import
648
649 ```js
650 interface Import <: Node {
651 type: "Import";
652 }
653 ```
654
655 A `import` pseudo-expression.
656
657 ## ThisExpression
658
659 ```js
660 interface ThisExpression <: Expression {
661 type: "ThisExpression";
662 }
663 ```
664
665 A `this` expression.
666
667 ## ArrowFunctionExpression
668
669 ```js
670 interface ArrowFunctionExpression <: Function, Expression {
671 type: "ArrowFunctionExpression";
672 body: BlockStatement | Expression;
673 }
674 ```
675
676 A fat arrow function expression, e.g., `let foo = (bar) => { /* body */ }`.
677
678 ## YieldExpression
679
680 ```js
681 interface YieldExpression <: Expression {
682 type: "YieldExpression";
683 argument: Expression | null;
684 delegate: boolean;
685 }
686 ```
687
688 A `yield` expression.
689
690 ## AwaitExpression
691
692 ```js
693 interface AwaitExpression <: Expression {
694 type: "AwaitExpression";
695 argument: Expression | null;
696 }
697 ```
698
699 A `await` expression.
700
701 ## ArrayExpression
702
703 ```js
704 interface ArrayExpression <: Expression {
705 type: "ArrayExpression";
706 elements: [ Expression | SpreadElement | null ];
707 }
708 ```
709
710 An array expression.
711
712 ## ObjectExpression
713
714 ```js
715 interface ObjectExpression <: Expression {
716 type: "ObjectExpression";
717 properties: [ ObjectProperty | ObjectMethod | SpreadElement ];
718 }
719 ```
720
721 An object expression.
722
723 ### ObjectMember
724
725 ```js
726 interface ObjectMember <: Node {
727 key: Expression;
728 computed: boolean;
729 decorators: [ Decorator ];
730 }
731 ```
732
733 #### ObjectProperty
734
735 ```js
736 interface ObjectProperty <: ObjectMember {
737 type: "ObjectProperty";
738 shorthand: boolean;
739 value: Expression;
740 }
741 ```
742
743 #### ObjectMethod
744
745 ```js
746 interface ObjectMethod <: ObjectMember, Function {
747 type: "ObjectMethod";
748 kind: "get" | "set" | "method";
749 }
750 ```
751
752 ## RecordExpression
753
754 ```js
755 interface RecordExpression <: Expression {
756 type: "RecordExpression";
757 properties: [ ObjectProperty | ObjectMethod | SpreadElement ];
758 }
759 ```
760
761 ## TupleExpression
762
763 ```js
764 interface TupleExpression <: Expression {
765 type: "TupleExpression";
766 elements: [ Expression | SpreadElement | null ];
767 }
768 ```
769
770 ## FunctionExpression
771
772 ```js
773 interface FunctionExpression <: Function, Expression {
774 type: "FunctionExpression";
775 }
776 ```
777
778 A `function` expression.
779
780 ## Unary operations
781
782 ### UnaryExpression
783
784 ```js
785 interface UnaryExpression <: Expression {
786 type: "UnaryExpression";
787 operator: UnaryOperator;
788 prefix: boolean;
789 argument: Expression;
790 }
791 ```
792
793 A unary operator expression.
794
795 #### UnaryOperator
796
797 ```js
798 enum UnaryOperator {
799 "-" | "+" | "!" | "~" | "typeof" | "void" | "delete" | "throw"
800 }
801 ```
802
803 A unary operator token.
804
805 ### UpdateExpression
806
807 ```js
808 interface UpdateExpression <: Expression {
809 type: "UpdateExpression";
810 operator: UpdateOperator;
811 argument: Expression;
812 prefix: boolean;
813 }
814 ```
815
816 An update (increment or decrement) operator expression.
817
818 #### UpdateOperator
819
820 ```js
821 enum UpdateOperator {
822 "++" | "--"
823 }
824 ```
825
826 An update (increment or decrement) operator token.
827
828 ## Binary operations
829
830 ### BinaryExpression
831
832 ```js
833 interface BinaryExpression <: Expression {
834 type: "BinaryExpression";
835 operator: BinaryOperator;
836 left: Expression | PrivateName;
837 right: Expression;
838 }
839 ```
840
841 A binary operator expression. When `operator` is `in`, the `left` can be a `PrivateName`.
842
843 #### BinaryOperator
844
845 ```js
846 enum BinaryOperator {
847 "==" | "!=" | "===" | "!=="
848 | "<" | "<=" | ">" | ">="
849 | "<<" | ">>" | ">>>"
850 | "+" | "-" | "*" | "/" | "%"
851 | "**" | "|" | "^" | "&" | "in"
852 | "instanceof"
853 | "|>"
854 }
855 ```
856
857 A binary operator token.
858
859 ### AssignmentExpression
860
861 ```js
862 interface AssignmentExpression <: Expression {
863 type: "AssignmentExpression";
864 operator: AssignmentOperator;
865 left: Pattern | Expression;
866 right: Expression;
867 }
868 ```
869
870 An assignment operator expression. It has short-circuiting behaviour if the `operator` is one of `"||="`, `"&&="`, and `"??="`.
871
872 #### AssignmentOperator
873
874 ```js
875 enum AssignmentOperator {
876 "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**="
877 | "<<=" | ">>=" | ">>>="
878 | "|=" | "^=" | "&="
879 | "||=" | "&&=" | "??="
880 }
881 ```
882
883 An assignment operator token.
884
885 ### LogicalExpression
886
887 ```js
888 interface LogicalExpression <: Expression {
889 type: "LogicalExpression";
890 operator: LogicalOperator;
891 left: Expression;
892 right: Expression;
893 }
894 ```
895
896 A logical operator expression.
897
898 #### LogicalOperator
899
900 ```js
901 enum LogicalOperator {
902 "||" | "&&" | "??"
903 }
904 ```
905
906 A logical operator token.
907
908 ### SpreadElement
909
910 ```js
911 interface SpreadElement <: Node {
912 type: "SpreadElement";
913 argument: Expression;
914 }
915 ```
916
917 ### ArgumentPlaceholder
918
919 ```js
920 interface ArgumentPlaceholder <: Node {
921 type: "ArgumentPlaceholder";
922 }
923 ```
924
925 ### MemberExpression
926
927 ```js
928 interface MemberExpression <: Expression, Pattern {
929 type: "MemberExpression";
930 object: Expression | Super;
931 property: Expression | PrivateName;
932 computed: boolean;
933 }
934 ```
935
936 A member expression. If `computed` is `true`, the node corresponds to a computed (`a[b]`) member expression and `property` is an `Expression`. If `computed` is `false`, the node corresponds to a static (`a.b`) member expression and `property` is an `Identifier` or a `PrivateName`.
937
938 ### OptionalMemberExpression
939
940 ```js
941 interface OptionalMemberExpression <: Expression {
942 type: "OptionalMemberExpression";
943 object: Expression;
944 property: Expression | PrivateName;
945 computed: boolean;
946 optional: boolean;
947 }
948 ```
949
950 An optional member expression is a part of the optional chain. When `optional` is `true`, it is the starting element of the optional chain. i.e. In `a?.b.c`, `?.b` is an optional member expression with `optional: true`, `.c` is an optional member expression. See this [gist](https://gist.github.com/JLHwung/567fb29fa2b82bbe164ad9067ff3290f) for more AST examples.
951
952 ### BindExpression
953
954 ```js
955 interface BindExpression <: Expression {
956 type: "BindExpression";
957 object: Expression | null;
958 callee: Expression;
959 }
960 ```
961
962 If `object` is `null`, then `callee` should be a `MemberExpression`.
963
964 ## ConditionalExpression
965
966 ```js
967 interface ConditionalExpression <: Expression {
968 type: "ConditionalExpression";
969 test: Expression;
970 alternate: Expression;
971 consequent: Expression;
972 }
973 ```
974
975 A conditional expression, i.e., a ternary `?`/`:` expression.
976
977 ## CallExpression
978
979 ```js
980 interface CallExpression <: Expression {
981 type: "CallExpression";
982 callee: Expression | Super | Import;
983 arguments: [ Expression | SpreadElement ];
984 }
985 ```
986
987 A function or method call expression. When the `callee` is `Import`, the `arguments` must have only one `Expression` element.
988
989 ## OptionalCallExpression
990
991 ```js
992 interface OptionalCallExpression <: Expression {
993 type: "OptionalCallExpression";
994 callee: Expression;
995 arguments: [ Expression | SpreadElement ];
996 optional: boolean;
997 }
998 ```
999
1000 An optional call expression is a part of the optional chain. When `optional` is `true`, it is the starting element of the optional chain. i.e. In `f?.()()`, `?.()` is an optional call expression with `optional: true`, `()` is an optional call expression with `optional: false`. See this [gist](https://gist.github.com/JLHwung/567fb29fa2b82bbe164ad9067ff3290f) for more AST examples.
1001
1002 ## NewExpression
1003
1004 ```js
1005 interface NewExpression <: CallExpression {
1006 type: "NewExpression";
1007 }
1008 ```
1009
1010 A `new` expression.
1011
1012 ## SequenceExpression
1013
1014 ```js
1015 interface SequenceExpression <: Expression {
1016 type: "SequenceExpression";
1017 expressions: [ Expression ];
1018 }
1019 ```
1020
1021 A sequence expression, i.e., a comma-separated sequence of expressions.
1022
1023 ## ParenthesizedExpression
1024
1025 ```js
1026 interface ParenthesizedExpression <: Expression {
1027 type "ParenthesizedExpression";
1028 expression: Expression;
1029 }
1030 ```
1031
1032 An expression wrapped by parentheses. By default `@babel/parser` does not create this node, unless the `createParenthesizedExpressions: true` option is passed.
1033
1034 ## DoExpression
1035
1036 ```js
1037 interface DoExpression <: Expression {
1038 type: "DoExpression";
1039 body: BlockStatement;
1040 async: boolean;
1041 }
1042 ```
1043
1044 ## ModuleExpression
1045
1046 ```js
1047 interface ModuleExpression <: Expression {
1048 type: "ModuleExpression";
1049 body: Program
1050 }
1051 ```
1052
1053 A inline module expression proposed in https://github.com/tc39/proposal-js-module-blocks.
1054
1055 ## TopicReference
1056
1057 ```js
1058 interface TopicReference <: Expression {
1059 type: "TopicReference";
1060 }
1061 ```
1062
1063 A topic reference to be used inside the body of
1064 a [Hack-style pipe expression](https://github.com/js-choi/proposal-hack-pipes).
1065
1066 # Template Literals
1067
1068 ## TemplateLiteral
1069
1070 ```js
1071 interface TemplateLiteral <: Expression {
1072 type: "TemplateLiteral";
1073 quasis: [ TemplateElement ];
1074 expressions: [ Expression ];
1075 }
1076 ```
1077
1078 ## TaggedTemplateExpression
1079
1080 ```js
1081 interface TaggedTemplateExpression <: Expression {
1082 type: "TaggedTemplateExpression";
1083 tag: Expression;
1084 quasi: TemplateLiteral;
1085 }
1086 ```
1087
1088 ## TemplateElement
1089
1090 ```js
1091 interface TemplateElement <: Node {
1092 type: "TemplateElement";
1093 tail: boolean;
1094 value: {
1095 cooked: string | null;
1096 raw: string;
1097 };
1098 }
1099 ```
1100
1101 # Patterns
1102
1103 ```js
1104 interface Pattern <: Node { }
1105 ```
1106
1107 ## ObjectPattern
1108
1109 ```js
1110 interface AssignmentProperty <: ObjectProperty {
1111 value: Pattern;
1112 }
1113
1114 interface ObjectPattern <: Pattern {
1115 type: "ObjectPattern";
1116 properties: [ AssignmentProperty | RestElement ];
1117 }
1118 ```
1119
1120 ## ArrayPattern
1121
1122 ```js
1123 interface ArrayPattern <: Pattern {
1124 type: "ArrayPattern";
1125 elements: [ Pattern | null ];
1126 }
1127 ```
1128
1129 ## RestElement
1130
1131 ```js
1132 interface RestElement <: Pattern {
1133 type: "RestElement";
1134 argument: Pattern;
1135 }
1136 ```
1137
1138 ## AssignmentPattern
1139
1140 ```js
1141 interface AssignmentPattern <: Pattern {
1142 type: "AssignmentPattern";
1143 left: Pattern;
1144 right: Expression;
1145 }
1146 ```
1147
1148 # Classes
1149
1150 ```js
1151 interface Class <: Node {
1152 id: Identifier | null;
1153 superClass: Expression | null;
1154 body: ClassBody;
1155 decorators: [ Decorator ];
1156 }
1157 ```
1158
1159 ## ClassBody
1160
1161 ```js
1162 interface ClassBody <: Node {
1163 type: "ClassBody";
1164 body: [ ClassMethod | ClassPrivateMethod | ClassProperty | ClassPrivateProperty | StaticBlock ];
1165 }
1166 ```
1167
1168 ## ClassMethod
1169
1170 ```js
1171 interface ClassMethod <: Function {
1172 type: "ClassMethod";
1173 key: Expression;
1174 kind: "constructor" | "method" | "get" | "set";
1175 computed: boolean;
1176 static: boolean;
1177 decorators: [ Decorator ];
1178 }
1179 ```
1180
1181 ## ClassPrivateMethod
1182
1183 ```js
1184 interface ClassPrivateMethod <: Function {
1185 type: "ClassPrivateMethod";
1186 key: PrivateName;
1187 kind: "method" | "get" | "set";
1188 static: boolean;
1189 decorators: [ Decorator ];
1190 }
1191 ```
1192
1193 ## ClassProperty
1194
1195 ```js
1196 interface ClassProperty <: Node {
1197 type: "ClassProperty";
1198 key: Expression;
1199 value: Expression;
1200 static: boolean;
1201 computed: boolean;
1202 }
1203 ```
1204
1205 ## ClassPrivateProperty
1206
1207 ```js
1208 interface ClassPrivateProperty <: Node {
1209 type: "ClassPrivateProperty";
1210 key: PrivateName;
1211 value: Expression;
1212 static: boolean;
1213 }
1214 ```
1215
1216 ## ClassAccessorProperty
1217
1218 ```js
1219 interface ClassAccessorProperty <: Node {
1220 type: "ClassAccessorProperty";
1221 key: Expression | PrivateName;
1222 value: Expression;
1223 static: boolean;
1224 computed: boolean;
1225 }
1226 ```
1227
1228 ## StaticBlock
1229
1230 ```js
1231 interface StaticBlock <: Node {
1232 type: "StaticBlock";
1233 body: [ Statement ];
1234 }
1235 ```
1236
1237 A static block proposed in https://github.com/tc39/proposal-class-static-block.
1238
1239 ## ClassDeclaration
1240
1241 ```js
1242 interface ClassDeclaration <: Class, Declaration {
1243 type: "ClassDeclaration";
1244 id: Identifier;
1245 }
1246 ```
1247
1248 ## ClassExpression
1249
1250 ```js
1251 interface ClassExpression <: Class, Expression {
1252 type: "ClassExpression";
1253 }
1254 ```
1255
1256 ## MetaProperty
1257
1258 ```js
1259 interface MetaProperty <: Expression {
1260 type: "MetaProperty";
1261 meta: Identifier;
1262 property: Identifier;
1263 }
1264 ```
1265
1266 # Modules
1267
1268 ## ModuleSpecifier
1269
1270 ```js
1271 interface ModuleSpecifier <: Node {
1272 local: Identifier;
1273 }
1274 ```
1275
1276 A specifier in an import or export declaration.
1277
1278 ## Imports
1279
1280 ### ImportDeclaration
1281
1282 ```js
1283 interface ImportDeclaration <: Node {
1284 type: "ImportDeclaration";
1285 importKind: null | "type" | "typeof" | "value";
1286 specifiers: [ ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier ];
1287 source: StringLiteral;
1288 assertions?: [ ImportAttribute ];
1289 }
1290 ```
1291
1292 An import declaration, e.g., `import foo from "mod";`.
1293
1294 > importKind is only set when `flow` plugin enabled in babel-parser
1295
1296 ### ImportSpecifier
1297
1298 ```js
1299 interface ImportSpecifier <: ModuleSpecifier {
1300 type: "ImportSpecifier";
1301 imported: Identifier | StringLiteral;
1302 }
1303 ```
1304
1305 An imported variable binding, e.g., `{foo}` in `import {foo} from "mod"` or `{foo as bar}` in `import {foo as bar} from "mod"`. The `imported` field refers to the name of the export imported from the module. The `local` field refers to the binding imported into the local module scope. If it is a basic named import, such as in `import {foo} from "mod"`, both `imported` and `local` are equivalent `Identifier` nodes; in this case an `Identifier` node representing `foo`. If it is an aliased import, such as in `import {foo as bar} from "mod"`, the `imported` field is an `Identifier` node representing `foo`, and the `local` field is an `Identifier` node representing `bar`.
1306
1307 ### ImportDefaultSpecifier
1308
1309 ```js
1310 interface ImportDefaultSpecifier <: ModuleSpecifier {
1311 type: "ImportDefaultSpecifier";
1312 }
1313 ```
1314
1315 A default import specifier, e.g., `foo` in `import foo from "mod.js"`.
1316
1317 ### ImportNamespaceSpecifier
1318
1319 ```js
1320 interface ImportNamespaceSpecifier <: ModuleSpecifier {
1321 type: "ImportNamespaceSpecifier";
1322 }
1323 ```
1324
1325 A namespace import specifier, e.g., `* as foo` in `import * as foo from "mod.js"`.
1326
1327 ### ImportAttribute
1328
1329 ```js
1330 interface ImportAttribute <: Node {
1331 type: "ImportAttribute";
1332 key: Identifier;
1333 value: StringLiteral;
1334 }
1335 ```
1336
1337 An attribute specified on the ImportDeclaration.
1338
1339 ## Exports
1340
1341 ### ExportDeclaration
1342
1343 ```js
1344 interface ExportDeclaration <: Node {}
1345 ```
1346
1347 An `export` declaration.
1348
1349 ### ExportNamedDeclaration
1350
1351 ```js
1352 interface ExportNamedDeclaration <: ExportDeclaration {
1353 type: "ExportNamedDeclaration";
1354 declaration: Declaration | null;
1355 specifiers: [ ExportSpecifier | ExportNamespaceSpecifier ];
1356 source: StringLiteral | null;
1357 assertions?: [ ImportAttribute ];
1358 }
1359 ```
1360
1361 An export named declaration, e.g., `export {foo, bar};`, `export {foo} from "mod";`, `export var foo = 1;` or `export * as foo from "bar";`.
1362
1363 Note:
1364
1365 - Having `declaration` populated with non-empty `specifiers` or non-null `source` results in an invalid state.
1366 - If `source` is `null`, for each `specifier` of `specifiers`, `specifier.local` can not be a `StringLiteral`.
1367 - If `specifiers` contains `ExportNamespaceSpecifier`, it must have only one `ExportNamespaceSpecifier`.
1368
1369 ### ExportSpecifier
1370
1371 ```js
1372 interface ExportSpecifier <: ModuleSpecifier {
1373 type: "ExportSpecifier";
1374 exported: Identifier | StringLiteral;
1375 local?: Identifier | StringLiteral;
1376 }
1377 ```
1378
1379 An exported variable binding, e.g., `{foo}` in `export {foo}` or `{bar as foo}` in `export {bar as foo}`. The `exported` field refers to the name exported in the module. The `local` field refers to the binding into the local module scope. If it is a basic named export, such as in `export {foo}`, both `exported` and `local` are equivalent `Identifier` nodes; in this case an `Identifier` node representing `foo`. If it is an aliased export, such as in `export {bar as foo}`, the `exported` field is an `Identifier` node representing `foo`, and the `local` field is an `Identifier` node representing `bar`.
1380
1381 ### ExportNamespaceSpecifier
1382
1383 ```js
1384 interface ExportNamespaceSpecifier <: ModuleSpecifier {
1385 type: "ExportNamespaceSpecifier";
1386 exported: Identifier;
1387 }
1388 ```
1389
1390 A namespace export specifier, e.g., `* as foo` in `export * as foo from "mod.js"`.
1391
1392 ### ExportDefaultDeclaration
1393
1394 ```js
1395 interface OptFunctionDeclaration <: FunctionDeclaration {
1396 id: Identifier | null;
1397 }
1398
1399 interface OptClassDeclaration <: ClassDeclaration {
1400 id: Identifier | null;
1401 }
1402
1403 interface ExportDefaultDeclaration <: ExportDeclaration {
1404 type: "ExportDefaultDeclaration";
1405 declaration: OptFunctionDeclaration | OptClassDeclaration | Expression;
1406 }
1407 ```
1408
1409 An export default declaration, e.g., `export default function () {};` or `export default 1;`.
1410
1411 ### ExportAllDeclaration
1412
1413 ```js
1414 interface ExportAllDeclaration <: ExportDeclaration {
1415 type: "ExportAllDeclaration";
1416 source: StringLiteral;
1417 assertions?: [ ImportAttribute ];
1418 }
1419 ```
1420
1421 An export batch declaration, e.g., `export * from "mod";`.
1422
1423 ### Smart-mix pipelines
1424
1425 These types are **deprecated**.
1426 They are used by the deprecated smart-mix pipe operator to determine
1427 the type of a pipe expression's the body expression.
1428 The Hack and F# pipe operators use simple `BinaryExpression`s.
1429
1430 #### PipelineBody
1431
1432 ```js
1433 interface PipelineBody <: NodeBase {
1434 type: "PipelineBody";
1435 }
1436 ```
1437
1438 #### PipelineBareFunctionBody
1439
1440 ```js
1441 interface PipelineBody <: NodeBase {
1442 type: "PipelineBareFunctionBody";
1443 callee: Expression;
1444 }
1445 ```
1446
1447 #### PipelineBareConstructorBody
1448
1449 ```js
1450 interface PipelineBareConstructorBody <: NodeBase {
1451 type: "PipelineBareConstructorBody";
1452 callee: Expression;
1453 }
1454 ```
1455
1456 #### PipelineBareAwaitedFunctionBody
1457
1458 ```js
1459 interface PipelineBareConstructorBody <: NodeBase {
1460 type: "PipelineTopicBody";
1461 expression: Expression;
1462 }
1463 ```
1464
1465 #### PipelineTopicBody
1466
1467 ```js
1468 interface PipelineBareConstructorBody <: NodeBase {
1469 type: "PipelineBareAwaitedFunctionBody";
1470 callee: Expression;
1471 }
1472 ```