These are the core @babel/parser (babylon) AST node types.
- Node objects
- Changes
- Identifier
- PrivateName
- Literals
- Programs
- Functions
- Statements
- Declarations
- Misc
- Expressions
- Super
- Import
- ThisExpression
- ArrowFunctionExpression
- YieldExpression
- AwaitExpression
- ArrayExpression
- ObjectExpression
- FunctionExpression
- Unary operations
- Binary operations
- ConditionalExpression
- CallExpression
- OptionalCallExpression
- NewExpression
- SequenceExpression
- ParenthesizedExpression
- DoExpression
- ModuleExpression
- Template Literals
- Patterns
- Classes
- Modules
AST nodes are represented as Node objects, which may have any prototype inheritance but which implement the following interface:
interface Node {
type: string;
loc: SourceLocation | null;
}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.
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):
interface SourceLocation {
source: string | null;
start: Position;
end: Position;
}Each Position object consists of a line number (1-indexed) and a column number (0-indexed):
interface Position {
line: number; // >= 1
column: number; // >= 0
}Flow: Node renamed from ExistentialTypeParam to ExistsTypeAnnotation #322
Flow: Node renamed from NumericLiteralTypeAnnotation to NumberLiteralTypeAnnotation babel/babylon#332
Flow: Node Variance which replaces the string value of the variance field on several nodes babel/babylon#333
Flow: ObjectTypeIndexer location info matches Flow's better babel/babylon#228
Node ForAwaitStatement has been removed #349 in favor of modifying ForOfStatement
RestProperty and SpreadProperty have been dropped in favor of RestElement and SpreadElement.
interface Identifier <: Expression, Pattern {
type: "Identifier";
name: string;
}An identifier. Note that an identifier may be an expression or a destructuring pattern.
interface PrivateName <: Node {
type: "PrivateName";
id: Identifier;
}A Private Name Identifier.
interface Literal <: Expression { }A literal token. May or may not represent an expression.
interface RegExpLiteral <: Literal {
type: "RegExpLiteral";
pattern: string;
flags: string;
}interface NullLiteral <: Literal {
type: "NullLiteral";
}interface StringLiteral <: Literal {
type: "StringLiteral";
value: string;
}interface BooleanLiteral <: Literal {
type: "BooleanLiteral";
value: boolean;
}interface NumericLiteral <: Literal {
type: "NumericLiteral";
value: number;
}interface BigIntLiteral <: Literal {
type: "BigIntLiteral";
value: bigint;
}interface DecimalLiteral <: Literal {
type: "DecimalLiteral";
value: string;
}The value property is the string representation of the BigDecimal value. It doesn't include the suffix m.
interface Program <: Node {
type: "Program";
interpreter: InterpreterDirective | null;
sourceType: "script" | "module";
body: [ Statement | ImportDeclaration | ExportDeclaration ];
directives: [ Directive ];
}A complete program source tree.
Parsers must specify sourceType as "module" if the source has been parsed as an ES6 module. Otherwise, sourceType must be "script".
interface Function <: Node {
id: Identifier | null;
params: [ Pattern ];
body: BlockStatement;
generator: boolean;
async: boolean;
}A function declaration or expression.
interface Statement <: Node { }Any statement.
interface ExpressionStatement <: Statement {
type: "ExpressionStatement";
expression: Expression;
}An expression statement, i.e., a statement consisting of a single expression.
interface BlockStatement <: Statement {
type: "BlockStatement";
body: [ Statement ];
directives: [ Directive ];
}A block statement, i.e., a sequence of statements surrounded by braces.
interface EmptyStatement <: Statement {
type: "EmptyStatement";
}An empty statement, i.e., a solitary semicolon.
interface DebuggerStatement <: Statement {
type: "DebuggerStatement";
}A debugger statement.
interface WithStatement <: Statement {
type: "WithStatement";
object: Expression;
body: Statement;
}A with statement.
interface ReturnStatement <: Statement {
type: "ReturnStatement";
argument: Expression | null;
}A return statement.
interface LabeledStatement <: Statement {
type: "LabeledStatement";
label: Identifier;
body: Statement;
}A labeled statement, i.e., a statement prefixed by a break/continue label.
interface BreakStatement <: Statement {
type: "BreakStatement";
label: Identifier | null;
}A break statement.
interface ContinueStatement <: Statement {
type: "ContinueStatement";
label: Identifier | null;
}A continue statement.
interface IfStatement <: Statement {
type: "IfStatement";
test: Expression;
consequent: Statement;
alternate: Statement | null;
}An if statement.
interface SwitchStatement <: Statement {
type: "SwitchStatement";
discriminant: Expression;
cases: [ SwitchCase ];
}A switch statement.
interface SwitchCase <: Node {
type: "SwitchCase";
test: Expression | null;
consequent: [ Statement ];
}A case (if test is an Expression) or default (if test === null) clause in the body of a switch statement.
interface ThrowStatement <: Statement {
type: "ThrowStatement";
argument: Expression;
}A throw statement.
interface TryStatement <: Statement {
type: "TryStatement";
block: BlockStatement;
handler: CatchClause | null;
finalizer: BlockStatement | null;
}A try statement. If handler is null then finalizer must be a BlockStatement.
interface CatchClause <: Node {
type: "CatchClause";
param?: Pattern;
body: BlockStatement;
}A catch clause following a try block.
interface WhileStatement <: Statement {
type: "WhileStatement";
test: Expression;
body: Statement;
}A while statement.
interface DoWhileStatement <: Statement {
type: "DoWhileStatement";
body: Statement;
test: Expression;
}A do/while statement.
interface ForStatement <: Statement {
type: "ForStatement";
init: VariableDeclaration | Expression | null;
test: Expression | null;
update: Expression | null;
body: Statement;
}A for statement.
interface ForInStatement <: Statement {
type: "ForInStatement";
left: VariableDeclaration | Expression;
right: Expression;
body: Statement;
}A for/in statement.
interface ForOfStatement <: ForInStatement {
type: "ForOfStatement";
await: boolean;
}interface Declaration <: Statement { }Any declaration node. Note that declarations are considered statements; this is because declarations can appear in any statement context.
interface FunctionDeclaration <: Function, Declaration {
type: "FunctionDeclaration";
id: Identifier;
}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.
interface VariableDeclaration <: Declaration {
type: "VariableDeclaration";
declarations: [ VariableDeclarator ];
kind: "var" | "let" | "const" | "using" | "await using";
}A variable declaration.
interface VariableDeclarator <: Node {
type: "VariableDeclarator";
id: Pattern;
init: Expression | null;
}A variable declarator.
interface Decorator <: Node {
type: "Decorator";
expression: Expression;
}interface Directive <: Node {
type: "Directive";
value: DirectiveLiteral;
}interface DirectiveLiteral <: StringLiteral {
type: "DirectiveLiteral";
}interface InterpreterDirective <: StringLiteral {
type: "InterpreterDirective";
}interface Expression <: Node { }Any expression node. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern.
interface Super <: Node {
type: "Super";
}A super pseudo-expression.
interface Import <: Node {
type: "Import";
}A import pseudo-expression.
interface ThisExpression <: Expression {
type: "ThisExpression";
}A this expression.
interface ArrowFunctionExpression <: Function, Expression {
type: "ArrowFunctionExpression";
body: BlockStatement | Expression;
}A fat arrow function expression, e.g., let foo = (bar) => { /* body */ }.
interface YieldExpression <: Expression {
type: "YieldExpression";
argument: Expression | null;
delegate: boolean;
}A yield expression.
interface AwaitExpression <: Expression {
type: "AwaitExpression";
argument: Expression | null;
}A await expression.
interface ArrayExpression <: Expression {
type: "ArrayExpression";
elements: [ Expression | SpreadElement | null ];
}An array expression.
interface ObjectExpression <: Expression {
type: "ObjectExpression";
properties: [ ObjectProperty | ObjectMethod | SpreadElement ];
}An object expression.
interface ObjectMember <: Node {
key: Expression;
computed: boolean;
decorators: [ Decorator ];
}interface ObjectProperty <: ObjectMember {
type: "ObjectProperty";
shorthand: boolean;
value: Expression;
}interface ObjectMethod <: ObjectMember, Function {
type: "ObjectMethod";
kind: "get" | "set" | "method";
}interface FunctionExpression <: Function, Expression {
type: "FunctionExpression";
}A function expression.
interface UnaryExpression <: Expression {
type: "UnaryExpression";
operator: UnaryOperator;
prefix: boolean;
argument: Expression;
}A unary operator expression.
enum UnaryOperator {
"-" | "+" | "!" | "~" | "typeof" | "void" | "delete" | "throw"
}A unary operator token.
interface UpdateExpression <: Expression {
type: "UpdateExpression";
operator: UpdateOperator;
argument: Expression;
prefix: boolean;
}An update (increment or decrement) operator expression.
enum UpdateOperator {
"++" | "--"
}An update (increment or decrement) operator token.
interface BinaryExpression <: Expression {
type: "BinaryExpression";
operator: BinaryOperator;
left: Expression | PrivateName;
right: Expression;
}A binary operator expression. When operator is in, the left can be a PrivateName.
enum BinaryOperator {
"==" | "!=" | "===" | "!=="
| "<" | "<=" | ">" | ">="
| "<<" | ">>" | ">>>"
| "+" | "-" | "*" | "/" | "%"
| "**" | "|" | "^" | "&" | "in"
| "instanceof"
| "|>"
}A binary operator token.
interface AssignmentExpression <: Expression {
type: "AssignmentExpression";
operator: AssignmentOperator;
left: Pattern | Expression;
right: Expression;
}An assignment operator expression. It has short-circuiting behaviour if the operator is one of "||=", "&&=", and "??=".
enum AssignmentOperator {
"=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**="
| "<<=" | ">>=" | ">>>="
| "|=" | "^=" | "&="
| "||=" | "&&=" | "??="
}An assignment operator token.
interface LogicalExpression <: Expression {
type: "LogicalExpression";
operator: LogicalOperator;
left: Expression;
right: Expression;
}A logical operator expression.
enum LogicalOperator {
"||" | "&&" | "??"
}A logical operator token.
interface SpreadElement <: Node {
type: "SpreadElement";
argument: Expression;
}interface ArgumentPlaceholder <: Node {
type: "ArgumentPlaceholder";
}interface MemberExpression <: Expression, Pattern {
type: "MemberExpression";
object: Expression | Super;
property: Expression | PrivateName;
computed: boolean;
}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.
interface OptionalMemberExpression <: Expression {
type: "OptionalMemberExpression";
object: Expression;
property: Expression | PrivateName;
computed: boolean;
optional: boolean;
}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 for more AST examples.
interface BindExpression <: Expression {
type: "BindExpression";
object: Expression | null;
callee: Expression;
}If object is null, then callee should be a MemberExpression.
interface ConditionalExpression <: Expression {
type: "ConditionalExpression";
test: Expression;
alternate: Expression;
consequent: Expression;
}A conditional expression, i.e., a ternary ?/: expression.
interface CallExpression <: Expression {
type: "CallExpression";
callee: Expression | Super | Import;
arguments: [ Expression | SpreadElement ];
}A function or method call expression. When the callee is Import, the arguments must have only one Expression element.
interface OptionalCallExpression <: Expression {
type: "OptionalCallExpression";
callee: Expression;
arguments: [ Expression | SpreadElement ];
optional: boolean;
}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 for more AST examples.
interface NewExpression <: CallExpression {
type: "NewExpression";
}A new expression.
interface SequenceExpression <: Expression {
type: "SequenceExpression";
expressions: [ Expression ];
}A sequence expression, i.e., a comma-separated sequence of expressions.
interface ParenthesizedExpression <: Expression {
type "ParenthesizedExpression";
expression: Expression;
}An expression wrapped by parentheses. By default @babel/parser does not create this node, unless the createParenthesizedExpressions: true option is passed.
interface DoExpression <: Expression {
type: "DoExpression";
body: BlockStatement;
async: boolean;
}interface ModuleExpression <: Expression {
type: "ModuleExpression";
body: Program
}A inline module expression proposed in https://github.com/tc39/proposal-js-module-blocks.
interface TopicReference <: Expression {
type: "TopicReference";
}A topic reference to be used inside the body of a Hack-style pipe expression.
interface TemplateLiteral <: Expression {
type: "TemplateLiteral";
quasis: [ TemplateElement ];
expressions: [ Expression ];
}interface TaggedTemplateExpression <: Expression {
type: "TaggedTemplateExpression";
tag: Expression;
quasi: TemplateLiteral;
}interface TemplateElement <: Node {
type: "TemplateElement";
tail: boolean;
value: {
cooked: string | null;
raw: string;
};
}interface Pattern <: Node { }interface AssignmentProperty <: ObjectProperty {
value: Pattern;
}
interface ObjectPattern <: Pattern {
type: "ObjectPattern";
properties: [ AssignmentProperty | RestElement ];
}interface ArrayPattern <: Pattern {
type: "ArrayPattern";
elements: [ Pattern | null ];
}interface RestElement <: Pattern {
type: "RestElement";
argument: Pattern;
}interface AssignmentPattern <: Pattern {
type: "AssignmentPattern";
left: Pattern;
right: Expression;
}interface VoidPattern <: Pattern {
type: "VoidPattern";
}A void binding used in the discard binding proposal.
interface Class <: Node {
id: Identifier | null;
superClass: Expression | null;
body: ClassBody;
decorators: [ Decorator ];
}interface ClassBody <: Node {
type: "ClassBody";
body: [ ClassMethod | ClassPrivateMethod | ClassProperty | ClassPrivateProperty | StaticBlock ];
}interface ClassMethod <: Function {
type: "ClassMethod";
key: Expression;
kind: "constructor" | "method" | "get" | "set";
computed: boolean;
static: boolean;
decorators: [ Decorator ];
}interface ClassPrivateMethod <: Function {
type: "ClassPrivateMethod";
key: PrivateName;
kind: "method" | "get" | "set";
static: boolean;
decorators: [ Decorator ];
}interface ClassProperty <: Node {
type: "ClassProperty";
key: Expression;
value: Expression;
static: boolean;
computed: boolean;
}interface ClassPrivateProperty <: Node {
type: "ClassPrivateProperty";
key: PrivateName;
value: Expression;
static: boolean;
}interface ClassAccessorProperty <: Node {
type: "ClassAccessorProperty";
key: Expression | PrivateName;
value: Expression;
static: boolean;
computed: boolean;
}interface StaticBlock <: Node {
type: "StaticBlock";
body: [ Statement ];
}A static block proposed in https://github.com/tc39/proposal-class-static-block.
interface ClassDeclaration <: Class, Declaration {
type: "ClassDeclaration";
id: Identifier;
}interface ClassExpression <: Class, Expression {
type: "ClassExpression";
}interface MetaProperty <: Expression {
type: "MetaProperty";
meta: Identifier;
property: Identifier;
}interface ModuleSpecifier <: Node {
local: Identifier;
}A specifier in an import or export declaration.
interface ImportDeclaration <: Node {
type: "ImportDeclaration";
importKind: null | "type" | "typeof" | "value";
specifiers: [ ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier ];
source: StringLiteral;
attribtues?: [ ImportAttribute ];
}An import declaration, e.g., import foo from "mod";.
importKind is only set when
flowplugin enabled in babel-parser
interface ImportSpecifier <: ModuleSpecifier {
type: "ImportSpecifier";
imported: Identifier | StringLiteral;
}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.
interface ImportDefaultSpecifier <: ModuleSpecifier {
type: "ImportDefaultSpecifier";
}A default import specifier, e.g., foo in import foo from "mod.js".
interface ImportNamespaceSpecifier <: ModuleSpecifier {
type: "ImportNamespaceSpecifier";
}A namespace import specifier, e.g., * as foo in import * as foo from "mod.js".
interface ImportAttribute <: Node {
type: "ImportAttribute";
key: Identifier;
value: StringLiteral;
}An attribute specified on the ImportDeclaration.
interface ExportDeclaration <: Node {}An export declaration.
interface ExportNamedDeclaration <: ExportDeclaration {
type: "ExportNamedDeclaration";
declaration: Declaration | null;
specifiers: [ ExportSpecifier | ExportNamespaceSpecifier ];
source: StringLiteral | null;
attributes?: [ ImportAttribute ];
}An export named declaration, e.g., export {foo, bar};, export {foo} from "mod";, export var foo = 1; or export * as foo from "bar";.
Note:
- Having
declarationpopulated with non-emptyspecifiersor non-nullsourceresults in an invalid state. - If
sourceisnull, for eachspecifierofspecifiers,specifier.localcan not be aStringLiteral. - If
specifierscontainsExportNamespaceSpecifier, it must have only oneExportNamespaceSpecifier.
interface ExportSpecifier <: ModuleSpecifier {
type: "ExportSpecifier";
exported: Identifier | StringLiteral;
local?: Identifier | StringLiteral;
}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.
interface ExportNamespaceSpecifier <: ModuleSpecifier {
type: "ExportNamespaceSpecifier";
exported: Identifier;
}A namespace export specifier, e.g., * as foo in export * as foo from "mod.js".
interface ExportDefaultSpecifier <: ModuleSpecifier {
type: "ExportDefaultSpecifier";
exported: Identifier;
}A default export specifier used in the export default from proposal.
interface OptFunctionDeclaration <: FunctionDeclaration {
id: Identifier | null;
}
interface OptClassDeclaration <: ClassDeclaration {
id: Identifier | null;
}
interface ExportDefaultDeclaration <: ExportDeclaration {
type: "ExportDefaultDeclaration";
declaration: OptFunctionDeclaration | OptClassDeclaration | Expression;
}An export default declaration, e.g., export default function () {}; or export default 1;.
interface ExportAllDeclaration <: ExportDeclaration {
type: "ExportAllDeclaration";
source: StringLiteral;
attributes?: [ ImportAttribute ];
}An export batch declaration, e.g., export * from "mod";.