<: 代表 extends
Programs
一个完整的程序数
interface Program <: Node {
type: "Program";
body: [ Statement ];
}
Statement(语句)
代表任意语句
interface Statement <: Node { }
tip: 语句一般会包含其他更小的语法
语句开始
EmptyStatement
一个空语句,也就是,一个孤立的分号.
interface EmptyStatement <: Statement {
type: "EmptyStatement";
}
BlockStatement
一个语句块,也就是由大括号包围的语句序列.
interface BlockStatement <: Statement {
type: "BlockStatement";
body: [ Statement ];
}
ExpressionStatement
一个表达式语句,也就是,仅有一个表达式组成的语句.
interface ExpressionStatement <: Statement {
type: "ExpressionStatement";
expression: Expression;
}
IfStatement
一个if语句.
interface IfStatement <: Statement {
type: "IfStatement";
test: Expression;
consequent: Statement;
alternate: Statement | null;
}
LabeledStatement
一个标签语句,也就是, 一个以 break/continue 标签开头的语句
interface LabeledStatement <: Statement {
type: "LabeledStatement";
label: Identifier;
body: Statement;
}
BreakStatement
一个 break 语句
interface BreakStatement <: Statement {
type: "BreakStatement";
label: Identifier | null;
}
ContinueStatement
一个continue语句.
interface ContinueStatement <: Statement {
type: "ContinueStatement";
label: Identifier | null;
}
WithStatement
一个 with 语句
interface WithStatement <: Statement {
type: "WithStatement";
object: Expression;
body: Statement;
}
SwitchStatement
一个 switch 语句
interface SwitchStatement <: Statement {
type: "SwitchStatement";
discriminant: Expression;
cases: [ SwitchCase ];
lexical: boolean;
}
ReturnStatement
一个 return 语句
interface ReturnStatement <: Statement {
type: "ReturnStatement";
argument: Expression | null;
}
ThrowStatement
一个人 throw 语句
interface ThrowStatement <: Statement {
type: "ThrowStatement";
argument: Expression;
}
TryStatement
一个 try catch 语句
interface TryStatement <: Statement {
type: "TryStatement";
block: BlockStatement;
handlers: [ CatchClause ];
finalizer: BlockStatement | null;
}
WhileStatement
一个 while 语句
interface WhileStatement <: Statement {
type: "WhileStatement";
test: Expression;
body: Statement;
}
DoWhileStatement
一个 do/while 语句
interface DoWhileStatement <: Statement {
type: "DoWhileStatement";
body: Statement;
test: Expression;
}
ForStatement
一个 for 语句
interface ForStatement <: Statement {
type: "ForStatement";
init: VariableDeclaration | Expression | null;
test: Expression | null;
update: Expression | null;
body: Statement;
}
ForInStatement
一个 for/in 语句
interface ForInStatement <: Statement {
type: "ForInStatement";
left: VariableDeclaration | Expression;
right: Expression;
body: Statement;
each: boolean;
}
LetStatement
一个 let 语句
interface LetStatement <: Statement {
type: "LetStatement";
head: [ { id: Pattern, init: Expression | null } ];
body: Statement;
}
DebuggerStatement
一个 debugger 语句
interface DebuggerStatement <: Statement {
type: "DebuggerStatement";
}
Declaration(声明)
声明开始
FunctionDeclaration
一个函数声明
注意:id 字段不能为 null
interface FunctionDeclaration <: Function, Declaration {
type: "FunctionDeclaration";
id: Identifier;
params: [ Pattern ];
defaults: [ Expression ];
rest: Identifier | null;
body: BlockStatement | Expression;
generator: boolean;
expression: boolean;
}
VariableDeclaration
一个变量声明,可以通过var, let, 或const.
interface VariableDeclaration <: Declaration {
type: "VariableDeclaration";
declarations: [ VariableDeclarator ];
kind: "var" | "let" | "const";
}
VariableDeclarator
一个变量声明符.
注意:
- id字段不能为 null
- let和const是SpiderMonkey特有的.
- 注:SpiderMonkey 是Mozilla使用C/C++编写的JavaScript 引擎
interface VariableDeclarator <: Node {
type: "VariableDeclarator";
id: Pattern;
init: Expression | null;
}
表达式
interface Expression <: Node, Pattern { }
表达式开始
ThisExpression
一个this表达式
interface ThisExpression <: Expression {
type: "ThisExpression";
}
ArrayExpression
一个数组表达式
interface ArrayExpression <: Expression {
type: "ArrayExpression";
elements: [ Expression | null ];
}
ObjectExpression
一个对象表达式
interface ObjectExpression <: Expression {
type: "ObjectExpression";
properties: [ { key: Literal | Identifier,
value: Expression,
kind: "init" | "get" | "set" } ];
}
FunctionExpression
一个函数表达式
interface FunctionExpression <: Function, Expression {
type: "FunctionExpression";
id: Identifier | null;
params: [ Pattern ];
defaults: [ Expression ];
rest: Identifier | null;
body: BlockStatement | Expression;
generator: boolean;
expression: boolean;
}
SequenceExpression
一个序列表达式,也就是由逗号分割的表达式序列
interface SequenceExpression <: Expression {
type: "SequenceExpression";
expressions: [ Expression ];
}