JavaScript/ast/node:修订间差异

来自康健生活
Kangkk​(留言 | 贡献)
Kangkk​(留言 | 贡献)
无编辑摘要
第1行: 第1行:
== 引言 ==
== test ==
== 列表 ==
Node objects
=== Identifier ===
interface Node {
标识符
    type: string;
=== Literal ===
    loc: SourceLocation | null;
字面量
}
=== RegExpLiteral ===
interface SourceLocation {
正则字面量
    source: string | null;
=== Programs ===
    start: Position;
一段完成代码的根节点。
    end: Position;
=== Functions ===
}
函数表达式节点。
interface Position {
=== Statement ===
    line: uint32 >= 1;
语句节点。
    column: uint32 >= 0;
=== ExpressionStatement ===
}
表达式节点对象
Programs
=== BlockStatement ===
A complete program source tree.
块语句节点
 
=== EmptyStatement ===
interface Program <: Node {
空的语句节点
    type: "Program";
=== DebuggerStatement ===
    body: [ Statement ];
debugger
}
=== WithStatement ===
 
with 语句节点
program(body[, loc])
=== ReturnStatement ===
body: [ Statement ]
返回语句节点
loc: SourceLocation
=== LabeledStatement ===
Functions
label 语句
A function declaration or expression.
=== BreakStatement ===
 
break 语句节点
interface Function <: Node {
=== ContinueStatement ===
    id: Identifier | null;
continue 语句节点
    params: [ Pattern ];
=== IfStatement ===
    defaults: [ Expression ];
if 语句节点
    rest: Identifier | null;
=== SwitchStatement ===
    body: BlockStatement | Expression;
switch 语句节点
    generator: boolean;
=== SwitchCase ===
    expression: boolean;
switch 的 case 节点
}
=== ThrowStatement ===
Statements
throw 语句节点
Any statement.
=== TryStatement ===
 
try 语句节点
interface Statement <: Node { }
=== CatchClause ===
An empty statement, i.e., a solitary semicolon.
catch 节点
 
=== WhileStatement ===
interface EmptyStatement <: Statement {
while 语句节点
    type: "EmptyStatement";
=== DoWhileStatement ===
}
do/while 语句节点
 
=== ForStatement ===
emptyStatement([loc])
for 循环语句节点
loc: SourceLocation
=== ForInStatement ===
A block statement, i.e., a sequence of statements surrounded by braces.
for/in 语句节点
 
=== Declarations ===
The builder differs from that specified in the Mozilla Parser API: body is an Array of Statements instead of a single Statement.
声明语句节点
 
=== FunctionDeclaration ===
interface BlockStatement <: Statement {
函数声明
    type: "BlockStatement";
=== VariableDeclaration ===
    body: [ Statement ];
变量声明
}
=== VariableDeclarator ===
 
变量声明的描述
blockStatement(body[, loc])
=== Expressions ===
body: [ Statement ]
表达式节点
loc: SourceLocation
=== ThisExpression ===
An expression statement, i.e., a statement consisting of a single expression.
表示 this
 
=== ArrayExpression ===
interface ExpressionStatement <: Statement {
数组表达式节点
    type: "ExpressionStatement";
=== ObjectExpression ===
    expression: Expression;
对象表达式节点
}
=== Property ===
 
对象表达式中的属性节点
expressionStatement(expr[, loc])
=== FunctionExpression ===
expr: Expression
函数表达式节点
loc: SourceLocation
=== UnaryExpression ===
An if statement.
一元运算表达式节点
 
=== UnaryOperator ===
interface IfStatement <: Statement {
一元运算符
    type: "IfStatement";
=== UpdateExpression ===
    test: Expression;
update 运算表达式节点
    consequent: Statement;
=== UpdateOperator ===
    alternate: Statement | null;
update 运算符
}
=== BinaryExpression ===
 
二元运算表达式节点
ifStatement(test, cons, alt[, loc])
=== BinaryOperator ===
test: Expression
二元运算符
cons: Statement
=== AssignmentExpression ===
alt: Statement | null
赋值表达式节点
loc: SourceLocation
=== AssignmentOperator ===
A labeled statement, i.e., a statement prefixed by a break/continue label.
赋值运算符
 
=== LogicalExpression ===
interface LabeledStatement <: Statement {
逻辑运算表达式节点
    type: "LabeledStatement";
=== LogicalOperator ===
    label: Identifier;
逻辑运算符
    body: Statement;
=== MemberExpression ===
}
成员表达式节点
 
=== ConditionalExpression ===
labeledStatement(label, body[, loc])
条件表达式
label: Identifier
=== CallExpression ===
body: Statement
函数调用表达式
loc: SourceLocation
=== NewExpression ===
A break statement.
new 表达式
 
=== SequenceExpression ===
interface BreakStatement <: Statement {
逗号运算符构建的表达式
    type: "BreakStatement";
    label: Identifier | null;
}
 
breakStatement(label[, loc])
label: Identifier | null
loc: SourceLocation
A continue statement.
 
interface ContinueStatement <: Statement {
    type: "ContinueStatement";
    label: Identifier | null;
}
 
continueStatement(label[, loc])
label: Identifier | null
loc: SourceLocation
A with statement.
 
interface WithStatement <: Statement {
    type: "WithStatement";
    object: Expression;
    body: Statement;
}
 
withStatement(obj, body[, loc])
obj: Expression
body: Statement
loc: SourceLocation
A switch statement.
 
The lexical flag is metadata indicating whether the switch statement contains any unnested let declarations (and therefore introduces a new lexical scope).
 
interface SwitchStatement <: Statement {
    type: "SwitchStatement";
    discriminant: Expression;
    cases: [ SwitchCase ];
    lexical: boolean;
}
 
switchStatement(disc, cases, isLexical[, loc])
disc: Expression
cases: [ SwitchCase ]
isLexical: boolean
loc: SourceLocation
A return statement.
 
interface ReturnStatement <: Statement {
    type: "ReturnStatement";
    argument: Expression | null;
}
 
returnStatement(arg[, loc])
arg: Expression | null
loc: SourceLocation
A throw statement.
 
interface ThrowStatement <: Statement {
    type: "ThrowStatement";
    argument: Expression;
}
 
throwStatement(arg[, loc])
arg: Expression
loc: SourceLocation
A try statement.
 
The builder in the Mozilla Parser API accepts multiple handlers. This only accepts a single handler.
 
interface TryStatement <: Statement {
    type: "TryStatement";
    block: BlockStatement;
    handler: CatchClause | null;
    guardedHandlers: [ CatchClause ];
    finalizer: BlockStatement | null;
}
 
tryStatement(body, handler, fin[, loc])
body: Statement
handler: CatchClause
fin: Statement | null
loc: SourceLocation
A while statement.
 
interface WhileStatement <: Statement {
    type: "WhileStatement";
    test: Expression;
    body: Statement;
}
 
whileStatement(test, body[, loc])
test: Expression
body: Statement
loc: SourceLocation
A do/while statement.
 
interface DoWhileStatement <: Statement {
    type: "DoWhileStatement";
    body: Statement;
    test: Expression;
}
 
doWhileStatement(body, test[, loc])
body: Statement
test: Expression
loc: SourceLocation
A for statement.
 
interface ForStatement <: Statement {
    type: "ForStatement";
    init: VariableDeclaration | Expression | null;
    test: Expression | null;
    update: Expression | null;
    body: Statement;
}
 
forStatement(init, test, update, body[, loc])
init: VariableDeclaration | Expression | null
test: Expression | null
update: Expression | null
body: Statement
loc: SourceLocation
A for/in statement, or, if each is true, a for each/in statement.
 
interface ForInStatement <: Statement {
    type: "ForInStatement";
    left: VariableDeclaration | Expression;
    right: Expression;
    body: Statement;
    each: boolean;
}
 
forInStatement(left, right, body, isForEach[, loc])
left: VariableDeclaration | Expression
right: Expression
body: Statement
isForEach: boolean
loc: SourceLocation
A for/of statement.
 
The Mozilla Parser API does not define a builder, so one has been defined here.
 
interface ForOfStatement <: Statement {
    type: "ForOfStatement";
    left: VariableDeclaration | Expression;
    right: Expression;
    body: Statement;
}
 
forOfStatement(left, right, body[, loc])
left: VariableDeclaration | Expression
right: Expression
body: Statement
A let statement.
 
interface LetStatement <: Statement {
    type: "LetStatement";
    head: [ { id: Pattern, init: Expression | null } ];
    body: Statement;
}
 
letStatement(head, body[, loc])
head: [ Declarator ]
body: Statement
loc: SourceLocation
A debugger statement.
 
interface DebuggerStatement <: Statement {
    type: "DebuggerStatement";
}
 
debuggerStatement([loc])
loc: SourceLocation
Declarations
Any declaration node.
 
interface Declaration <: Statement { }
A function declaration.
 
The builder intentionally differs from the Mozilla Parser API in its arguments instead of (name, args, body, isGenerator, isExpression[, loc]).
 
interface FunctionDeclaration <: Function, Declaration {
    type: "FunctionDeclaration";
    id: Identifier;
    params: [ Pattern ];
    defaults: [ Expression ];
    rest: Identifier | null;
    body: BlockStatement | Expression;
    generator: boolean;
    expression: boolean;
}
 
functionDeclaration(id, params, defaults, rest, body, isGenerator, isExpression[, loc])
id: Identifier
params: [ Pattern ]
defaults: [ Expression ]
rest: Identifier | null
body: BlockStatement | Expression
isGenerator: boolean
isExpression: boolean
loc: SourceLocation
A variable declaration, via one of var, let, or const.
 
interface VariableDeclaration <: Declaration {
    type: "VariableDeclaration";
    declarations: [ VariableDeclarator ];
    kind: "var" | "let" | "const";
}
 
variableDeclaration(kind, dtors[, loc])
kind: "var" | "let" | "const"
dtors: [ Declarator ]
loc: SourceLocation
A variable declarator.
 
interface VariableDeclarator <: Node {
    type: "VariableDeclarator";
    id: Pattern;
    init: Expression | null;
}
 
variableDeclarator(patt, init[, loc])
patt: Pattern
init: Expression | null
loc: SourceLocation
Expressions
Any expression node.
 
interface Expression <: Node, Pattern { }
A this expression.
 
interface ThisExpression <: Expression {
    type: "ThisExpression";
}
 
thisExpression([loc])
loc: SourceLocation
An array expression.
 
interface ArrayExpression <: Expression {
    type: "ArrayExpression";
    elements: [ Expression | null ];
}
 
arrayExpression(elts[, loc])
elts: [ Expression | null ]
loc: SourceLocation
An object expression.
 
A literal property in an object expression can have either a string or number as its value.
 
Ordinary property initializers have a kind value "init"; getters and setters have the kind values "get" and "set", respectively.
 
interface ObjectExpression <: Expression {
    type: "ObjectExpression";
    properties: [ Property ];
}
 
objectExpression(props[, loc])
props: [ Property ]
loc: SourceLocation
A function expression.
 
The builder intentionally differs from the Mozilla Parser API in its arguments instead of (name, args, body, isGenerator, isExpression[, loc]).
 
interface FunctionExpression <: Function, Expression {
    type: "FunctionExpression";
    id: Identifier | null;
    params: [ Pattern ];
    defaults: [ Expression ];
    rest: Identifier | null;
    body: BlockStatement | Expression;
    generator: boolean;
    expression: boolean;
}
 
functionExpression(id, params, defaults, rest, body, isGenerator, isExpression[, loc])
id: Identifier | null
params: [ Pattern ]
defaults: [ Expression ]
rest: Identifier | null
body: BlockStatement | Expression
isGenerator: boolean
isExpression: boolean
loc: SourceLocation
A fat arrow function expression, i.e., `let foo = (bar) => { /* body */ }`.
 
The Mozilla Parser API does not specify a builder for the ArrowFunction node, so one has been created here.
 
interface ArrowExpression <: Function, Expression {
    type: "ArrowExpression";
    params: [ Pattern ];
    defaults: [ Expression ];
    rest: Identifier | null;
    body: BlockStatement | Expression;
    generator: boolean;
    expression: boolean;
}
 
arrowExpression(params, defaults, rest, body, isGenerator, isExpression[, loc])
params: [ Pattern ]
defaults: [ Expression ]
rest: Identifier | null
body: BlockStatement | Expression
isGenerator: boolean
isExpression: boolean
loc: SourceLocation
A sequence expression, i.e., a comma-separated sequence of expressions.
 
interface SequenceExpression <: Expression {
    type: "SequenceExpression";
    expressions: [ Expression ];
}
 
sequenceExpression(exprs[, loc])
exprs: [ Expression ]
loc: SourceLocation
A unary operator expression.
 
interface UnaryExpression <: Expression {
    type: "UnaryExpression";
    operator: UnaryOperator;
    prefix: boolean;
    argument: Expression;
}
 
unaryExpression(op, arg, isPrefix[, loc])
op: UnaryOperator
arg: Expression
isPrefix: boolean
loc: SourceLocation
A binary operator expression.
 
interface BinaryExpression <: Expression {
    type: "BinaryExpression";
    operator: BinaryOperator;
    left: Expression;
    right: Expression;
}
 
binaryExpression(op, left, right[, loc])
op: BinaryOperator
left: Expression
right: Expression
loc: SourceLocation
An assignment operator expression.
 
interface AssignmentExpression <: Expression {
    type: "AssignmentExpression";
    operator: AssignmentOperator;
    left: Expression;
    right: Expression;
}
 
assignmentExpression(op, left, right[, loc])
op: AssignmentOperator
left: Expression
right: Expression
loc: SourceLocation
An update (increment or decrement) operator expression.
 
interface UpdateExpression <: Expression {
    type: "UpdateExpression";
    operator: UpdateOperator;
    argument: Expression;
    prefix: boolean;
}
 
updateExpression(op, arg, isPrefix[, loc])
op: UpdateOperator
arg: Expression
isPrefix: boolean
loc: SourceLocation
A logical operator expression.
 
interface LogicalExpression <: Expression {
    type: "LogicalExpression";
    operator: LogicalOperator;
    left: Expression;
    right: Expression;
}
 
logicalExpression(op, left, right[, loc])
op: LogicalOperator
left: Expression
right: Expression
loc: SourceLocation
A conditional expression, i.e., a ternary ?/: expression.
 
interface ConditionalExpression <: Expression {
    type: "ConditionalExpression";
    test: Expression;
    alternate: Expression;
    consequent: Expression;
}
 
conditionalExpression(test, cons, alt[, loc])
test: Expression
cons: Expression
alt: Expression
loc: SourceLocation
A new expression.
 
interface NewExpression <: Expression {
    type: "NewExpression";
    callee: Expression;
    arguments: [ Expression | null ];
}
 
newExpression(callee, args[, loc])
callee: Expression
args: [ Expression ]
loc: SourceLocation
A function or method call expression.
 
interface CallExpression <: Expression {
    type: "CallExpression";
    callee: Expression;
    arguments: [ Expression | null ];
}
 
callExpression(callee, args[, loc])
callee: Expression
args: [ Expression ]
loc: SourceLocation
A member expression.
 
If computed === true, the node corresponds to a computed e1[e2] expression and property is an Expression. If computed === false, the node corresponds to a static e1.x expression and property is an Identifier.
 
interface MemberExpression <: Expression {
    type: "MemberExpression";
    object: Expression;
    property: Identifier | Expression;
    computed: boolean;
}
 
memberExpression(obj, prop, isComputed[, loc])
obj: Expression
prop: Identifier | Expression
isComputed: boolean
loc: SourceLocation
A yield expression.
 
The Mozilla Parser API does not specify a type property for YieldExpression, so one has been added here.
 
interface YieldExpression <: Expression {
    type: "YieldExpression";
    argument: Expression | null;
}
 
yieldExpression(arg[, loc])
arg: Expression
loc: SourceLocation
An array comprehension.
 
The blocks array corresponds to the sequence of for and for each blocks.
 
The optional filter expression corresponds to the final if clause, if present.
 
The Mozilla Parser API does not specify a type property for ComprehensionExpression, so one has been added here.
 
interface ComprehensionExpression <: Expression {
    type: "ComprehensionExpression";
    body: Expression;
    blocks: [ ComprehensionBlock ];
    filter: Expression | null;
}
 
comprehensionExpression(body, blocks, filter[, loc])
body: Expression
blocks: [ ComprehensionBlock ]
filter: Expression | null
loc: SourceLocation
A generator expression.
 
As with array comprehensions, the blocks array corresponds to the sequence of for and for each blocks, and the optional filter expression corresponds to the final if clause, if present.
 
The Mozilla Parser API does not specify a type property for GeneratorExpression, so one has been added here.
 
interface GeneratorExpression <: Expression {
    type: "GeneratorExpression";
    body: Expression;
    blocks: [ ComprehensionBlock ];
    filter: Expression | null;
}
 
generatorExpression(body, blocks, filter[, loc])
body: Expression
blocks: [ ComprehensionBlock ]
filter: Expression | null
loc: SourceLocation
A let expression.
 
interface LetExpression <: Expression {
    type: "LetExpression";
    head: [ { id: Pattern, init: Expression | null } ];
    body: Expression;
}
 
letExpression(head, body[, loc])
head: [ Declarator ]
body: Expression
loc: SourceLocation
Patterns
interface Pattern <: Node { }
An object-destructuring pattern.
 
A literal property in an object pattern can have either a string or number as its value.
 
interface ObjectPattern <: Pattern {
    type: "ObjectPattern";
    properties: [ PropertyPattern ];
}
 
objectPattern(props[, loc])
props: [ PropertyPattern ]
loc: SourceLocation
An object property pattern.
 
The Mozilla Parser API does not specify a type property for PropertyPattern, so one has been added here.
 
interface PropertyPattern <: Node {
    type: "PropertyPattern";
    key: Literal | Identifier;
    value: Pattern;
}
 
propertyPattern(key, patt[, loc])
key: Literal | Identifier
patt: Pattern
loc: SourceLocation
An array-destructuring pattern.
 
interface ArrayPattern <: Pattern {
    type: "ArrayPattern";
    elements: [ Pattern | null ];
}
 
arrayPattern(elts[, loc])
elts: [ Pattern | null ]
loc: SourceLocation
Clauses
A case (if test is an Expression) or default (if test === null) clause in the body of a switch statement.
 
interface SwitchCase <: Node {
    type: "SwitchCase";
    test: Expression | null;
    consequent: [ Statement ];
}
 
switchCase(test, cons[, loc])
test: Expression | null
cons: [ Statement ]
loc: SourceLocation
A catch clause following a try block.
 
The optional guard property corresponds to the optional expression guard on the bound variable.
 
interface CatchClause <: Node {
    type: "CatchClause";
    param: Pattern;
    guard: Expression | null;
    body: BlockStatement;
}
 
catchClause(arg, guard, body[, loc])
arg: Pattern
guard: Expression
body: Statement
loc: SourceLocation
A for or for each block in an array comprehension or generator expression.
 
The Mozilla Parser API does not specify a type property for ComprehensionBlock, so one has been added here.
 
interface ComprehensionBlock <: Node {
    type: "ComprehensionBlock";
    left: Pattern;
    right: Expression;
    each: boolean;
}
 
comprehensionBlock(left, right, isForEach[, loc])
left: Pattern
right: Expression
isForEach: boolean
loc: SourceLocation
Miscellaneous
An identifier.
 
Note that an identifier may be an expression or a destructuring pattern.
 
interface Identifier <: Node, Expression, Pattern {
    type: "Identifier";
    name: string;
}
 
identifier(name[, loc])
name: string
loc: SourceLocation
A literal token.
 
Note that a literal can be an expression.
 
interface Literal <: Node, Expression {
    type: "Literal";
    value: string | boolean | null | number | RegExp;
}
 
literal(val[, loc])
val: string | boolean | null | number | RegExp
loc: SourceLocation
An object property initializer.
 
The order of the arguments in the builder intentionally differs from that specified by the Mozilla Parser API: the kind argument comes third, rather than first.
 
interface Property < Node {
    type: "Property";
    key: Literal | Identifier;
    value: Expression;
    kind: "init" | "get" | "set";
}
 
property(key, val, kind[, loc])
key: Literal | Identifier
val: Expression
kind: "init" | "get" | "set"
loc: SourceLocation
A unary operator token.
 
<syntaxhighlight lang="javascript">
enum UnaryOperator {
    "-" | "+" | "!" | "~" | "typeof" | "void" | "delete"
}</syntaxhighlight>
A binary operator token.
 
<syntaxhighlight lang="javascript">
enum BinaryOperator {
    "==" | "!=" | "===" | "!=="
        | "<" | "<=" | ">" | ">="
        | "<<" | ">>" | ">>>"
        | "+" | "-" | "*" | "/" | "%"
        | "&" | "|" | "^" | "in"
        | "instanceof" | ".."
}</syntaxhighlight>
A logical operator token.
 
<syntaxhighlight lang="javascript">
enum LogicalOperator {
    "||" | "&&"
}</syntaxhighlight>
An assignment operator token.
 
<syntaxhighlight lang="javascript">
enum AssignmentOperator {
    "=" | "+=" | "-=" | "*=" | "/=" | "%="
        | "<<=" | ">>=" | ">>>="
        | "|=" | "^=" | "&="
}</syntaxhighlight>
An update (increment or decrement) operator token.
 
<syntaxhighlight lang="javascript">
enum UpdateOperator {
    "++" | "--"
}</syntaxhighlight>

2022年11月22日 (二) 16:08的版本

test

Node objects interface Node {

   type: string;
   loc: SourceLocation | null;

} interface SourceLocation {

   source: string | null;
   start: Position;
   end: Position;

} interface Position {

   line: uint32 >= 1;
   column: uint32 >= 0;

} Programs A complete program source tree.

interface Program <: Node {

   type: "Program";
   body: [ Statement ];

}

program(body[, loc]) body: [ Statement ] loc: SourceLocation Functions A function declaration or expression.

interface Function <: Node {

   id: Identifier | null;
   params: [ Pattern ];
   defaults: [ Expression ];
   rest: Identifier | null;
   body: BlockStatement | Expression;
   generator: boolean;
   expression: boolean;

} Statements Any statement.

interface Statement <: Node { } An empty statement, i.e., a solitary semicolon.

interface EmptyStatement <: Statement {

   type: "EmptyStatement";

}

emptyStatement([loc]) loc: SourceLocation A block statement, i.e., a sequence of statements surrounded by braces.

The builder differs from that specified in the Mozilla Parser API: body is an Array of Statements instead of a single Statement.

interface BlockStatement <: Statement {

   type: "BlockStatement";
   body: [ Statement ];

}

blockStatement(body[, loc]) body: [ Statement ] loc: SourceLocation An expression statement, i.e., a statement consisting of a single expression.

interface ExpressionStatement <: Statement {

   type: "ExpressionStatement";
   expression: Expression;

}

expressionStatement(expr[, loc]) expr: Expression loc: SourceLocation An if statement.

interface IfStatement <: Statement {

   type: "IfStatement";
   test: Expression;
   consequent: Statement;
   alternate: Statement | null;

}

ifStatement(test, cons, alt[, loc]) test: Expression cons: Statement alt: Statement | null loc: SourceLocation A labeled statement, i.e., a statement prefixed by a break/continue label.

interface LabeledStatement <: Statement {

   type: "LabeledStatement";
   label: Identifier;
   body: Statement;

}

labeledStatement(label, body[, loc]) label: Identifier body: Statement loc: SourceLocation A break statement.

interface BreakStatement <: Statement {

   type: "BreakStatement";
   label: Identifier | null;

}

breakStatement(label[, loc]) label: Identifier | null loc: SourceLocation A continue statement.

interface ContinueStatement <: Statement {

   type: "ContinueStatement";
   label: Identifier | null;

}

continueStatement(label[, loc]) label: Identifier | null loc: SourceLocation A with statement.

interface WithStatement <: Statement {

   type: "WithStatement";
   object: Expression;
   body: Statement;

}

withStatement(obj, body[, loc]) obj: Expression body: Statement loc: SourceLocation A switch statement.

The lexical flag is metadata indicating whether the switch statement contains any unnested let declarations (and therefore introduces a new lexical scope).

interface SwitchStatement <: Statement {

   type: "SwitchStatement";
   discriminant: Expression;
   cases: [ SwitchCase ];
   lexical: boolean;

}

switchStatement(disc, cases, isLexical[, loc]) disc: Expression cases: [ SwitchCase ] isLexical: boolean loc: SourceLocation A return statement.

interface ReturnStatement <: Statement {

   type: "ReturnStatement";
   argument: Expression | null;

}

returnStatement(arg[, loc]) arg: Expression | null loc: SourceLocation A throw statement.

interface ThrowStatement <: Statement {

   type: "ThrowStatement";
   argument: Expression;

}

throwStatement(arg[, loc]) arg: Expression loc: SourceLocation A try statement.

The builder in the Mozilla Parser API accepts multiple handlers. This only accepts a single handler.

interface TryStatement <: Statement {

   type: "TryStatement";
   block: BlockStatement;
   handler: CatchClause | null;
   guardedHandlers: [ CatchClause ];
   finalizer: BlockStatement | null;

}

tryStatement(body, handler, fin[, loc]) body: Statement handler: CatchClause fin: Statement | null loc: SourceLocation A while statement.

interface WhileStatement <: Statement {

   type: "WhileStatement";
   test: Expression;
   body: Statement;

}

whileStatement(test, body[, loc]) test: Expression body: Statement loc: SourceLocation A do/while statement.

interface DoWhileStatement <: Statement {

   type: "DoWhileStatement";
   body: Statement;
   test: Expression;

}

doWhileStatement(body, test[, loc]) body: Statement test: Expression loc: SourceLocation A for statement.

interface ForStatement <: Statement {

   type: "ForStatement";
   init: VariableDeclaration | Expression | null;
   test: Expression | null;
   update: Expression | null;
   body: Statement;

}

forStatement(init, test, update, body[, loc]) init: VariableDeclaration | Expression | null test: Expression | null update: Expression | null body: Statement loc: SourceLocation A for/in statement, or, if each is true, a for each/in statement.

interface ForInStatement <: Statement {

   type: "ForInStatement";
   left: VariableDeclaration | Expression;
   right: Expression;
   body: Statement;
   each: boolean;

}

forInStatement(left, right, body, isForEach[, loc]) left: VariableDeclaration | Expression right: Expression body: Statement isForEach: boolean loc: SourceLocation A for/of statement.

The Mozilla Parser API does not define a builder, so one has been defined here.

interface ForOfStatement <: Statement {

   type: "ForOfStatement";
   left: VariableDeclaration | Expression;
   right: Expression;
   body: Statement;

}

forOfStatement(left, right, body[, loc]) left: VariableDeclaration | Expression right: Expression body: Statement A let statement.

interface LetStatement <: Statement {

   type: "LetStatement";
   head: [ { id: Pattern, init: Expression | null } ];
   body: Statement;

}

letStatement(head, body[, loc]) head: [ Declarator ] body: Statement loc: SourceLocation A debugger statement.

interface DebuggerStatement <: Statement {

   type: "DebuggerStatement";

}

debuggerStatement([loc]) loc: SourceLocation Declarations Any declaration node.

interface Declaration <: Statement { } A function declaration.

The builder intentionally differs from the Mozilla Parser API in its arguments instead of (name, args, body, isGenerator, isExpression[, loc]).

interface FunctionDeclaration <: Function, Declaration {

   type: "FunctionDeclaration";
   id: Identifier;
   params: [ Pattern ];
   defaults: [ Expression ];
   rest: Identifier | null;
   body: BlockStatement | Expression;
   generator: boolean;
   expression: boolean;

}

functionDeclaration(id, params, defaults, rest, body, isGenerator, isExpression[, loc]) id: Identifier params: [ Pattern ] defaults: [ Expression ] rest: Identifier | null body: BlockStatement | Expression isGenerator: boolean isExpression: boolean loc: SourceLocation A variable declaration, via one of var, let, or const.

interface VariableDeclaration <: Declaration {

   type: "VariableDeclaration";
   declarations: [ VariableDeclarator ];
   kind: "var" | "let" | "const";

}

variableDeclaration(kind, dtors[, loc]) kind: "var" | "let" | "const" dtors: [ Declarator ] loc: SourceLocation A variable declarator.

interface VariableDeclarator <: Node {

   type: "VariableDeclarator";
   id: Pattern;
   init: Expression | null;

}

variableDeclarator(patt, init[, loc]) patt: Pattern init: Expression | null loc: SourceLocation Expressions Any expression node.

interface Expression <: Node, Pattern { } A this expression.

interface ThisExpression <: Expression {

   type: "ThisExpression";

}

thisExpression([loc]) loc: SourceLocation An array expression.

interface ArrayExpression <: Expression {

   type: "ArrayExpression";
   elements: [ Expression | null ];

}

arrayExpression(elts[, loc]) elts: [ Expression | null ] loc: SourceLocation An object expression.

A literal property in an object expression can have either a string or number as its value.

Ordinary property initializers have a kind value "init"; getters and setters have the kind values "get" and "set", respectively.

interface ObjectExpression <: Expression {

   type: "ObjectExpression";
   properties: [ Property ];

}

objectExpression(props[, loc]) props: [ Property ] loc: SourceLocation A function expression.

The builder intentionally differs from the Mozilla Parser API in its arguments instead of (name, args, body, isGenerator, isExpression[, loc]).

interface FunctionExpression <: Function, Expression {

   type: "FunctionExpression";
   id: Identifier | null;
   params: [ Pattern ];
   defaults: [ Expression ];
   rest: Identifier | null;
   body: BlockStatement | Expression;
   generator: boolean;
   expression: boolean;

}

functionExpression(id, params, defaults, rest, body, isGenerator, isExpression[, loc]) id: Identifier | null params: [ Pattern ] defaults: [ Expression ] rest: Identifier | null body: BlockStatement | Expression isGenerator: boolean isExpression: boolean loc: SourceLocation A fat arrow function expression, i.e., `let foo = (bar) => { /* body */ }`.

The Mozilla Parser API does not specify a builder for the ArrowFunction node, so one has been created here.

interface ArrowExpression <: Function, Expression {

   type: "ArrowExpression";
   params: [ Pattern ];
   defaults: [ Expression ];
   rest: Identifier | null;
   body: BlockStatement | Expression;
   generator: boolean;
   expression: boolean;

}

arrowExpression(params, defaults, rest, body, isGenerator, isExpression[, loc]) params: [ Pattern ] defaults: [ Expression ] rest: Identifier | null body: BlockStatement | Expression isGenerator: boolean isExpression: boolean loc: SourceLocation A sequence expression, i.e., a comma-separated sequence of expressions.

interface SequenceExpression <: Expression {

   type: "SequenceExpression";
   expressions: [ Expression ];

}

sequenceExpression(exprs[, loc]) exprs: [ Expression ] loc: SourceLocation A unary operator expression.

interface UnaryExpression <: Expression {

   type: "UnaryExpression";
   operator: UnaryOperator;
   prefix: boolean;
   argument: Expression;

}

unaryExpression(op, arg, isPrefix[, loc]) op: UnaryOperator arg: Expression isPrefix: boolean loc: SourceLocation A binary operator expression.

interface BinaryExpression <: Expression {

   type: "BinaryExpression";
   operator: BinaryOperator;
   left: Expression;
   right: Expression;

}

binaryExpression(op, left, right[, loc]) op: BinaryOperator left: Expression right: Expression loc: SourceLocation An assignment operator expression.

interface AssignmentExpression <: Expression {

   type: "AssignmentExpression";
   operator: AssignmentOperator;
   left: Expression;
   right: Expression;

}

assignmentExpression(op, left, right[, loc]) op: AssignmentOperator left: Expression right: Expression loc: SourceLocation An update (increment or decrement) operator expression.

interface UpdateExpression <: Expression {

   type: "UpdateExpression";
   operator: UpdateOperator;
   argument: Expression;
   prefix: boolean;

}

updateExpression(op, arg, isPrefix[, loc]) op: UpdateOperator arg: Expression isPrefix: boolean loc: SourceLocation A logical operator expression.

interface LogicalExpression <: Expression {

   type: "LogicalExpression";
   operator: LogicalOperator;
   left: Expression;
   right: Expression;

}

logicalExpression(op, left, right[, loc]) op: LogicalOperator left: Expression right: Expression loc: SourceLocation A conditional expression, i.e., a ternary ?/: expression.

interface ConditionalExpression <: Expression {

   type: "ConditionalExpression";
   test: Expression;
   alternate: Expression;
   consequent: Expression;

}

conditionalExpression(test, cons, alt[, loc]) test: Expression cons: Expression alt: Expression loc: SourceLocation A new expression.

interface NewExpression <: Expression {

   type: "NewExpression";
   callee: Expression;
   arguments: [ Expression | null ];

}

newExpression(callee, args[, loc]) callee: Expression args: [ Expression ] loc: SourceLocation A function or method call expression.

interface CallExpression <: Expression {

   type: "CallExpression";
   callee: Expression;
   arguments: [ Expression | null ];

}

callExpression(callee, args[, loc]) callee: Expression args: [ Expression ] loc: SourceLocation A member expression.

If computed === true, the node corresponds to a computed e1[e2] expression and property is an Expression. If computed === false, the node corresponds to a static e1.x expression and property is an Identifier.

interface MemberExpression <: Expression {

   type: "MemberExpression";
   object: Expression;
   property: Identifier | Expression;
   computed: boolean;

}

memberExpression(obj, prop, isComputed[, loc]) obj: Expression prop: Identifier | Expression isComputed: boolean loc: SourceLocation A yield expression.

The Mozilla Parser API does not specify a type property for YieldExpression, so one has been added here.

interface YieldExpression <: Expression {

   type: "YieldExpression";
   argument: Expression | null;

}

yieldExpression(arg[, loc]) arg: Expression loc: SourceLocation An array comprehension.

The blocks array corresponds to the sequence of for and for each blocks.

The optional filter expression corresponds to the final if clause, if present.

The Mozilla Parser API does not specify a type property for ComprehensionExpression, so one has been added here.

interface ComprehensionExpression <: Expression {

   type: "ComprehensionExpression";
   body: Expression;
   blocks: [ ComprehensionBlock ];
   filter: Expression | null;

}

comprehensionExpression(body, blocks, filter[, loc]) body: Expression blocks: [ ComprehensionBlock ] filter: Expression | null loc: SourceLocation A generator expression.

As with array comprehensions, the blocks array corresponds to the sequence of for and for each blocks, and the optional filter expression corresponds to the final if clause, if present.

The Mozilla Parser API does not specify a type property for GeneratorExpression, so one has been added here.

interface GeneratorExpression <: Expression {

   type: "GeneratorExpression";
   body: Expression;
   blocks: [ ComprehensionBlock ];
   filter: Expression | null;

}

generatorExpression(body, blocks, filter[, loc]) body: Expression blocks: [ ComprehensionBlock ] filter: Expression | null loc: SourceLocation A let expression.

interface LetExpression <: Expression {

   type: "LetExpression";
   head: [ { id: Pattern, init: Expression | null } ];
   body: Expression;

}

letExpression(head, body[, loc]) head: [ Declarator ] body: Expression loc: SourceLocation Patterns interface Pattern <: Node { } An object-destructuring pattern.

A literal property in an object pattern can have either a string or number as its value.

interface ObjectPattern <: Pattern {

   type: "ObjectPattern";
   properties: [ PropertyPattern ];

}

objectPattern(props[, loc]) props: [ PropertyPattern ] loc: SourceLocation An object property pattern.

The Mozilla Parser API does not specify a type property for PropertyPattern, so one has been added here.

interface PropertyPattern <: Node {

   type: "PropertyPattern";
   key: Literal | Identifier;
   value: Pattern;

}

propertyPattern(key, patt[, loc]) key: Literal | Identifier patt: Pattern loc: SourceLocation An array-destructuring pattern.

interface ArrayPattern <: Pattern {

   type: "ArrayPattern";
   elements: [ Pattern | null ];

}

arrayPattern(elts[, loc]) elts: [ Pattern | null ] loc: SourceLocation Clauses A case (if test is an Expression) or default (if test === null) clause in the body of a switch statement.

interface SwitchCase <: Node {

   type: "SwitchCase";
   test: Expression | null;
   consequent: [ Statement ];

}

switchCase(test, cons[, loc]) test: Expression | null cons: [ Statement ] loc: SourceLocation A catch clause following a try block.

The optional guard property corresponds to the optional expression guard on the bound variable.

interface CatchClause <: Node {

   type: "CatchClause";
   param: Pattern;
   guard: Expression | null;
   body: BlockStatement;

}

catchClause(arg, guard, body[, loc]) arg: Pattern guard: Expression body: Statement loc: SourceLocation A for or for each block in an array comprehension or generator expression.

The Mozilla Parser API does not specify a type property for ComprehensionBlock, so one has been added here.

interface ComprehensionBlock <: Node {

   type: "ComprehensionBlock";
   left: Pattern;
   right: Expression;
   each: boolean;

}

comprehensionBlock(left, right, isForEach[, loc]) left: Pattern right: Expression isForEach: boolean loc: SourceLocation Miscellaneous An identifier.

Note that an identifier may be an expression or a destructuring pattern.

interface Identifier <: Node, Expression, Pattern {

   type: "Identifier";
   name: string;

}

identifier(name[, loc]) name: string loc: SourceLocation A literal token.

Note that a literal can be an expression.

interface Literal <: Node, Expression {

   type: "Literal";
   value: string | boolean | null | number | RegExp;

}

literal(val[, loc]) val: string | boolean | null | number | RegExp loc: SourceLocation An object property initializer.

The order of the arguments in the builder intentionally differs from that specified by the Mozilla Parser API: the kind argument comes third, rather than first.

interface Property < Node {

   type: "Property";
   key: Literal | Identifier;
   value: Expression;
   kind: "init" | "get" | "set";

}

property(key, val, kind[, loc]) key: Literal | Identifier val: Expression kind: "init" | "get" | "set" loc: SourceLocation A unary operator token.

enum UnaryOperator {
    "-" | "+" | "!" | "~" | "typeof" | "void" | "delete"
}

A binary operator token.

enum BinaryOperator {
    "==" | "!=" | "===" | "!=="
         | "<" | "<=" | ">" | ">="
         | "<<" | ">>" | ">>>"
         | "+" | "-" | "*" | "/" | "%"
         | "&" | "|" | "^" | "in"
         | "instanceof" | ".."
}

A logical operator token.

enum LogicalOperator {
    "||" | "&&"
}

An assignment operator token.

enum AssignmentOperator {
    "=" | "+=" | "-=" | "*=" | "/=" | "%="
        | "<<=" | ">>=" | ">>>="
        | "|=" | "^=" | "&="
}

An update (increment or decrement) operator token.

enum UpdateOperator {
    "++" | "--"
}