Parser API

  • 版本网址缩略名: SpiderMonkey/Parser_API
  • 版本标题: Parser API
  • 版本 id: 329531
  • 创建于:
  • 创建者: ziyunfei
  • 是否是当前版本?
  • 评论

修订内容

{{ jsapi_minversion_header("1.8.5") }}

Recent builds of the standalone SpiderMonkey shell include a reflection of the SpiderMonkey parser, made available as a JavaScript API. 这使得我们更容易的用JavaScript写出处理JavaScript源代码的工具, 比如语法高亮工具,静态分析工具, 翻译器,编译器,混淆器等等.

例子:

> var expr = Reflect.parse("obj.foo + 42").body[0].expression
> expr.left.property
({loc:null, type:"Identifier", name:"foo"})
> expr.right
({loc:{source:null, start:{line:1, column:10}, end:{line:1, column:12}}, type:"Literal", value:42})

Reflect也可以使用在Firefox 7及以上版本中,但必须要导入一个模块:

Components.utils.import("resource://gre/modules/reflect.jsm") 

如果不想用Reflect全局对象,也可以指定一个对象名称:

Components.utils.import("resource://gre/modules/reflect.jsm", obj)

内置对象

无论是SpiderMonkey shell还是Firefox (导入模块之后),全局对象Reflect目前都只有一个parse方法.

Reflect对象的属性

Reflect对象目前只有一个方法.

Reflect.parse(src[, options])

Coerces src to a string and parses the result as a JavaScript program. By default, the parsing returns a Program object (see below) representing the parsed abstract syntax tree (AST).

Additional options may be provided via the options object, which can include any of the following properties:

loc Boolean Default: true
如果loctrue,则解析器会在返回的AST节点中包含上源码的位置信息.
source String Default: null
A description of the input source; typically a filename, path, or URL. This string is not meaningful to the parsing process, but is produced as part of the source location information in the returned AST nodes.
line Number Default: 1
初始行号,用在源码位置信息上.
builder Builder Default: null

A builder object, which can be used to produce AST nodes in custom data formats. The expected callback methods are described under Builder Objects.

If parsing fails due to a syntax error, an instance of SyntaxError is thrown. The syntax error object thrown by Reflect.parse() has the same message property as the syntax error that would be thrown by eval(src). The lineNumber and fileName properties of the syntax error object indicate the source location of the syntax error.

节点对象

By default, Reflect.parse() produces Node objects, which are plain JavaScript objects (i.e., their prototype derives from the standard Object prototype). All node types 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 parser produced no information about the node's 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: uint32 >= 1;
    column: uint32 >= 0;
}

Programs

interface Program <: Node {
    type: "Program";
    body: [ Statement ];
}

A complete program source tree.

函数

interface Function <: Node {
    id: Identifier | null;
    params: [ Pattern ];
    defaults: [ Expression ];
    rest: Identifier | null;
    body: BlockStatement | Expression;
    generator: boolean;
    expression: boolean;
}

A function declaration or expression. The body of the function may be a block statement, or in the case of an expression closure, an expression.

注: Expression closures 是SpiderMonkey特有的.

If the generator flag is true, the function is a generator function, i.e., contains a yield expression in its body (other than in a nested function).

注: Generators 是SpiderMonkey特有的.

If the expression flag is true, the function is an expression closure and the body field is an expression.

语句

interface Statement <: Node { }

任意语句.

interface EmptyStatement <: Statement {
    type: "EmptyStatement";
}

一个空语句,也就是,一个孤立的分号.

interface BlockStatement <: Statement {
    type: "BlockStatement";
    body: [ Statement ];
}

一个语句块,也就是由大括号包围的语句序列.

interface ExpressionStatement <: Statement {
    type: "ExpressionStatement";
    expression: Expression;
}

一个表达式语句,也就是,仅有一个表达式组成的语句.

interface IfStatement <: Statement {
    type: "IfStatement";
    test: Expression;
    consequent: Statement;
    alternate: Statement | null;
}

一个if语句.

interface LabeledStatement <: Statement {
    type: "LabeledStatement";
    label: Identifier;
    body: Statement;
}

一个标签语句,也就是, a statement prefixed by a break/continue label.

interface BreakStatement <: Statement {
    type: "BreakStatement";
    label: Identifier | null;
}

一个break语句.

interface ContinueStatement <: Statement {
    type: "ContinueStatement";
    label: Identifier | null;
}

一个continue语句.

interface WithStatement <: Statement {
    type: "WithStatement";
    object: Expression;
    body: Statement;
}

with statement.

interface SwitchStatement <: Statement {
    type: "SwitchStatement";
    discriminant: Expression;
    cases: [ SwitchCase ];
    lexical: boolean;
}

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

interface ReturnStatement <: Statement {
    type: "ReturnStatement";
    argument: Expression | null;
}

一个return语句.

interface ThrowStatement <: Statement {
    type: "ThrowStatement";
    argument: Expression;
}

一个throw语句.

interface TryStatement <: Statement {
    type: "TryStatement";
    block: BlockStatement;
    handlers: [ CatchClause ];
    finalizer: BlockStatement | null;
}

一个try语句.

注: 多个catch子句是SpiderMonkey特有的.
interface WhileStatement <: Statement {
    type: "WhileStatement";
    test: Expression;
    body: Statement;
}

一个while语句.

interface DoWhileStatement <: Statement {
    type: "DoWhileStatement";
    body: Statement;
    test: Expression;
}

一个do/while语句.

interface ForStatement <: Statement {
    type: "ForStatement";
    init: VariableDeclaration | Expression | null;
    test: Expression | null;
    update: Expression | null;
    body: Statement;
}

一个for语句.

interface ForInStatement <: Statement {
    type: "ForInStatement";
    left: VariableDeclaration |  Expression;
    right: Expression;
    body: Statement;
    each: boolean;
}

一个for/in语句, or, if each is true, a for each/in statement.

注: for each语法是SpiderMonkey特有的.
interface LetStatement <: Statement {
    type: "LetStatement";
    head: [ { id: Pattern, init: Expression | null } ];
    body: Statement;
}

一个let语句.

注: let语句形式是SpiderMonkey特有的.
interface DebuggerStatement <: Statement {
    type: "DebuggerStatement";
}

一个debugger语句.

注: debugger语句是ECMAScript 5中的新语法,尽管SpiderMonkey已经支持它很多年了.

声明

interface Declaration <: Statement { }

Any declaration node. Note that declarations are considered statements; this is because declarations can appear in any statement context in the language recognized by the SpiderMonkey parser.

注: 任意嵌套作用域下的声明是SpiderMonkey特有的.
interface FunctionDeclaration <: Function, Declaration {
    type: "FunctionDeclaration";
    id: Identifier;
    params: [ Pattern ];
    defaults: [ Expression ];
    rest: Identifier | null;
    body: BlockStatement | Expression;
    generator: boolean;
    expression: boolean;
}

一个函数声明.

注: id字段不能为null.
interface VariableDeclaration <: Declaration {
    type: "VariableDeclaration";
    declarations: [ VariableDeclarator ];
    kind: "var" | "let" | "const";
}

一个变量声明,可以通过var, let, 或const.

interface VariableDeclarator <: Node {
    type: "VariableDeclarator";
    id: Pattern;
    init: Expression | null;
}

一个变量声明符.

注: id字段不能为null.
注: letconst是SpiderMonkey特有的.

表达式

interface Expression <: Node, Pattern { }

任意表达式节点. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern.

interface ThisExpression <: Expression {
    type: "ThisExpression";
}

一个this表达式.

interface ArrayExpression <: Expression {
    type: "ArrayExpression";
    elements: [ Expression | null ];
}

一个数组表达式.

interface ObjectExpression <: Expression {
    type: "ObjectExpression";
    properties: [ { key: Literal | Identifier,
                    value: Expression,
                    kind: "init" | "get" | "set" } ];
}

一个对象表达式. 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 FunctionExpression <: Function, Expression {
    type: "FunctionExpression";
    id: Identifier | null;
    params: [ Pattern ];
    defaults: [ Expression ];
    rest: Identifier | null;
    body: BlockStatement | Expression;
    generator: boolean;
    expression: boolean;
}

一个函数表达式.

interface SequenceExpression <: Expression {
    type: "SequenceExpression";
    expressions: [ Expression ];
}

一个序列表达式,也就是一个由逗号分割的表达式序列.

interface UnaryExpression <: Expression {
    type: "UnaryExpression";
    operator: UnaryOperator;
    prefix: boolean;
    argument: Expression;
}

A unary operator expression.

interface BinaryExpression <: Expression {
    type: "BinaryExpression";
    operator: BinaryOperator;
    left: Expression;
    right: Expression;
}

一个二元运算符表达式.

interface AssignmentExpression <: Expression {
    type: "AssignmentExpression";
    operator: AssignmentOperator;
    left: Expression;
    right: Expression;
}

An assignment operator expression.

interface UpdateExpression <: Expression {
    type: "UpdateExpression";
    operator: UpdateOperator;
    argument: Expression;
    prefix: boolean;
}

An update (increment or decrement) operator expression.

interface LogicalExpression <: Expression {
    type: "LogicalExpression";
    operator: LogicalOperator;
    left: Expression;
    right: Expression;
}

一个逻辑运算符表达式.

interface ConditionalExpression <: Expression {
    type: "ConditionalExpression";
    test: Expression;
    alternate: Expression;
    consequent: Expression;
}

一个条件运算符表达式, i.e., a ternary ?/: expression.

interface NewExpression <: Expression {
    type: "NewExpression";
    callee: Expression;
    arguments: [ Expression ] | null;
}

A new expression.

interface CallExpression <: Expression {
    type: "CallExpression";
    callee: Expression;
    arguments: [ Expression ];
}

A function or method call expression.

interface MemberExpression <: Expression {
    type: "MemberExpression";
    object: Expression;
    property: Identifier | Expression;
    computed : boolean;
}

一个member表达式. 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 YieldExpression <: Expression {
    argument: Expression | null;
}

yield expression.

注: yield expressions 是SpiderMonkey特有的.
interface ComprehensionExpression <: Expression {
    body: Expression;
    blocks: [ ComprehensionBlock ];
    filter: Expression | null;
}

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.

注: Array comprehensions 是SpiderMonkey特有的.
interface GeneratorExpression <: Expression {
    body: Expression;
    blocks: [ ComprehensionBlock ];
    filter: Expression | null;
}

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.

注: Generator expressions 是SpiderMonkey特有的.
interface GraphExpression <: Expression {
    index: uint32;
    expression: Literal;
}

graph expression, aka "sharp literal," such as #1={ self: #1# }.

注: Graph expressions 是SpiderMonkey特有的.
interface GraphIndexExpression <: Expression {
    index: uint32;
}

一个graph索引表达式,又称为"井号变量",比如#1#.

注: Graph索引表达式
Graph索引表达式是SpiderMonkey特有的.
interface LetExpression <: Expression {
    type: "LetExpression";
    head: [ { id: Pattern, init: Expression | null } ];
    body: Expression;
}

一个let表达式.

注: let表达式是SpiderMonkey特有的.

模式

interface Pattern <: Node { }

JavaScript 1.7 introduced destructuring assignment and binding forms. All binding forms (such as function parameters, variable declarations, and catch block headers), accept array and object destructuring patterns in addition to plain identifiers. The left-hand sides of assignment expressions can be arbitrary expressions, but in the case where the expression is an object or array literal, it is interpreted by SpiderMonkey as a destructuring pattern.

Since the left-hand side of an assignment can in general be any expression, in an assignment context, a pattern can be any expression. In binding positions (such as function parameters, variable declarations, and catch headers), patterns can only be identifiers in the base case, not arbitrary expressions.

interface ObjectPattern <: Pattern {
    type: "ObjectPattern";
    properties: [ { key: Literal | Identifier, value: Pattern } ];
}

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

interface ArrayPattern <: Pattern {
    type: "ArrayPattern";
    elements: [ Pattern | null ];
}

An array-destructuring pattern.

子句

interface SwitchCase <: Node {
    type: "SwitchCase";
    test: Expression | null;
    consequent: [ Statement ];
}

一个case (if test is an Expression) or default (if test === null) clause in the body of a switch语句.

interface CatchClause <: Node {
    type: "CatchClause";
    param: Pattern;
    guard: Expression | null;
    body: BlockStatement;
}

catch clause following a try block. The optional guard property corresponds to the optional expression guard on the bound variable.

注: The guard expression is SpiderMonkey-specific.
interface ComprehensionBlock <: Node {
    left: Pattern;
    right: Expression;
    each: boolean;
}

for or for each block in an array comprehension or generator expression.

注: Array comprehensions and generator expressions 是SpiderMonkey特有的.

杂项

interface Identifier <: Node, Expression, Pattern {
    type: "Identifier";
    name: string;
}

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

interface Literal <: Node, Expression {
    type: "Literal";
    value: string | boolean | null | number | RegExp;
}

A literal token. Note that a literal can be an expression.

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

A unary operator token.

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

A binary operator token.

注: The .. operator is E4X-specific.
enum LogicalOperator {
    "||" | "&&"
}

A logical operator token.

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

An assignment operator token.

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

An update (increment or decrement) operator token.

E4X

下面介绍一下为E4X提供支持的节点类型.

注: E4X不是ECMAScript规范(ECMA-262)的一部分,它是一个单独的标准(ECMA-357).

声明

interface XMLDefaultDeclaration <: Declaration {
    type: "XMLDefaultDeclaration";
    namespace: Expression;
}

一个默认xml命名空间声明

表达式

interface XMLAnyName <: Expression {
    type: "XMLAnyName";
}

The special E4X wildcard pseudo-identifier *.

interface XMLQualifiedIdentifier <: Expression {
    type: "XMLQualifiedIdentifier";
    left: Identifier | XMLAnyName;
    right: Identifier | Expression;
    computed: boolean;
}

An E4X qualified identifier, i.e., a pseudo-identifier using the namespace separator ::. If the qualified identifier has a computed name (i.e., the id::[expr] form), then computed is true and the right property is an expression.

interface XMLFunctionQualifiedIdentifier <: Expression {
    type: "XMLFunctionQualifiedIdentifier";
    right: Identifier | Expression;
    computed: boolean;
}

An E4X identifier qualified by the function keyword, e.g. function::id.

注: function-qualified identifiers 是SpiderMonkey特有的.
interface XMLAttributeSelector <: Expression {
    type: "XMLAttributeSelector";
    attribute: Expression;
}

An E4X attribute selector expression, i.e., an @ expression.

interface XMLFilterExpression <: Expression {
    type: "XMLFilterExpression";
    left: Expression;
    right: Expression;
}

An E4X list filter expression, i.e., an expression of the form expr.(expr).

interface XMLElement <: XML, Expression {
    type: "XMLElement";
    contents: [ XML ];
}

An E4X literal representing a single XML element.

interface XMLList <: XML, Expression {
    type: "XMLList";
    contents: [ XML ];
}

An E4X literal representing a list of XML elements.

XML

interface XML <: Node { }

XML data.

interface XMLEscape <: XML {
    type "XMLEscape";
    expression: Expression;
}

XML data with an escaped JavaScript expression.

interface XMLText <: XML {
    type: "XMLText";
    text: string;
}

Literal XML text.

interface XMLStartTag <: XML {
    type: "XMLStartTag";
    contents: [ XML ];
}

An XML start tag.

interface XMLEndTag <: XML {
    type: "XMLEndTag";
    contents: [ XML ];
}

An XML end tag.

interface XMLPointTag <: XML {
    type: "XMLPointTag";
    contents: [ XML ];
}

An XML point tag.

interface XMLName <: XML {
    type: "XMLName";
    contents: string | [ XML ];
}

An XML name.

interface XMLAttribute <: XML {
    type: "XMLAttribute";
    value: string;
}

An XML attribute value.

interface XMLCdata <: XML {
    type: "XMLCdata";
    contents: string;
}

An XML CDATA node.

interface XMLComment <: XML {
    type: "XMLComment";
    contents: string;
}

An XML comment.

interface XMLProcessingInstruction <: XML {
    type: "XMLProcessingInstruction";
    target: string;
    contents: string | null;
}

An XML processing instruction.

Builder objects

The optional builder parameter to Reflect.parse() makes it possible to construct user-specified data from the parser, rather than the default Node objects. Builder objects may contain any of the callback methods described in this section.

Each callback can produce any custom, user-defined datatype; these are referred to below as CustomExpression, CustomStatement, etc.

注: Because this library uses null for optional nodes, it is recommended that user-defined datatypes not use null as a representation of an AST node.

If the loc option is enabled (see the Reflect.parse() options above), then each callback is provided with the source location information of the parsed node as an extra parameter.

All builder callbacks are optional. When a callback is missing, the default format is used, but the provided builder methods are still used recursively for sub-nodes.

Programs

program(body[, loc])
body: [ CustomStatement ]
loc: SourceLocation

返回: CustomProgram

Callback to produce a custom program node.

Statements

emptyStatement([loc])
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom empty statement node.

blockStatement(body[, loc])
body: CustomStatement
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom block statement node.

expressionStatement(expr[, loc])
expr: CustomExpression
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom expression statement node.

labeledStatement(label, body[, loc])
label: CustomIdentifier
body: CustomStatement
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom labeled statement node.

ifStatement(test, cons, alt[, loc])
test: CustomExpression
cons: CustomStatement
alt: CustomStatement | null
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom if statement node.

switchStatement(disc, cases, isLexical[, loc])
disc: CustomExpression
cases: [ CustomSwitchCase ]
isLexical: boolean
loc: SourceLocation

返回: CustomStatement

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

whileStatement(test, body[, loc])
test: CustomExpression
body: CustomStatement
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom while statement node.

doWhileStatement(body, test[, loc])
body: CustomStatement
test: CustomExpression
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom do-while statement node.

forStatement(init, test, update, body[, loc])
init: CustomVariableDeclaration | CustomExpression | null
test: CustomExpression | null
update: CustomExpression | null
body: CustomStatement
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom for statement node.

forInStatement(left, right, body, isForEach[, loc])
left: CustomVariableDeclaration | CustomExpression
right: CustomExpression
body: CustomStatement
isForEach: boolean
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom for-in statement node. The isForEach flag indicates whether the node is a for each statement.

breakStatement(label[, loc])
label: CustomIdentifier | null
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom break statement node.

continueStatement(label[, loc])
label: CustomIdentifier | null
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom continue statement node.

withStatement(obj, body[, loc])
obj: CustomExpression
body: CustomStatement
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom with statement node.

returnStatement(arg[, loc])
arg: CustomExpression | null
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom return statement node.

tryStatement(body, handlers, fin[, loc])
body: CustomStatement
handlers: [ CustomCatchClause ]
fin: CustomStatement | null
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom try statement node.

throwStatement(arg[, loc])
arg: CustomExpression
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom throw statement node.

debuggerStatement([loc])
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom debugger statement node.

letStatement(head, body[, loc])
head: [ CustomDeclarator ]
body: CustomStatement
loc: SourceLocation

返回: CustomStatement

Callback to produce a custom let statement node.

声明

functionDeclaration(name, args, body, isGenerator, isExpression[, loc])
name: string
args: [ CustomPattern ]
body: CustomStatement | CustomExpression
isGenerator: boolean
isExpression: boolean
loc: SourceLocation

返回: CustomDeclaration

Callback to produce a custom function declaration node.

variableDeclaration(kind, dtors[, loc])
kind: "const" | "let" | "var"
dtors: [ CustomDeclarator ]
loc: SourceLocation

返回: CustomDeclaration

Callback to produce a custom variable declaration node.

variableDeclarator(patt, init[, loc])
patt: CustomPattern
init: CustomExpression | null
loc: SourceLocation

返回: CustomDeclarator

Callback to produce a custom variable declarator node.

表达式

sequenceExpression(exprs[, loc])
exprs: [ CustomExpression ]
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom sequence expression node.

conditionalExpression(test, cons, alt[, loc])
test: CustomExpression
cons: CustomExpression
alt: CustomExpression
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom conditional expression node.

unaryExpression(op, arg, isPrefix[, loc])
op: UnaryOperator
arg: CustomExpression
isPrefix: boolean
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom unary expression node.

binaryExpression(op, left, right[, loc])
op: BinaryOperator
left: CustomExpression
right: CustomExpression
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom binary expression node.

assignmentExpression(op, left, right[, loc])
op: AssignmentOperator
left: CustomExpression
right: CustomExpression
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom assignment expression node.

logicalExpression(op, left, right[, loc])
op: LogicalOperator
left: CustomExpression
right: CustomExpression
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom logical expression node.

updateExpression(op, arg, isPrefix[, loc])
op: UpdateOperator
arg: CustomExpression
isPrefix: boolean
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom update expression node.

newExpression(callee, args[, loc])
callee: CustomExpression
args: [ CustomExpression ]
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom new-expression node.

callExpression(callee, args[, loc])
callee: CustomExpression
args: [ CustomExpression ]
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom function call node.

memberExpression(obj, prop, isComputed[, loc])
obj: CustomExpression
prop: CustomIdentifier | CustomExpression
isComputed: boolean
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom member expression node.

functionExpression(name, args, body, isGenerator, isExpression[, loc])
name: CustomIdentifier | null
args: [ CustomPattern ]
body: CustomStatement | CustomExpression
isGenerator: boolean
isExpression: boolean
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom function expression node.

arrayExpression(elts[, loc])
elts: [ CustomExpression | null ]
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom array expression node.

objectExpression(props[, loc])
props: [ CustomObjectProperty ]
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom object expression node.

thisExpression([loc])
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom this expression node.

graphExpression(index, expr[, loc])
index: uint32 >= 1
expr: CustomExpression
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom graph expression node.

graphIndexExpression(index[, loc])
index: uint32 >= 1
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom graph index expression node.

comprehensionExpression(body, blocks, filter[, loc])
body: CustomExpression
blocks: [ CustomComprehensionBlock ]
filter: CustomExpression | null
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom comprehension expression node.

generatorExpression(body, blocks, filter[, loc])
body: CustomExpression
blocks: [ CustomComprehensionBlock ]
filter: CustomExpression | null
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom generator expression node.

yieldExpression(arg[, loc])
arg: CustomExpression
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom yield expression node.

letExpression(head, body[, loc])
head: [ CustomDeclarator ]
body: CustomExpression
loc: SourceLocation

返回: CustomExpression

Callback to produce a custom let expression node.

Patterns

arrayPattern(elts[, loc])
elts: [ CustomPattern | null ]
loc: SourceLocation

返回: CustomPattern

Callback to produce a custom array destructuring pattern node.

objectPattern(props[, loc])
props: [ CustomPropertyPattern ]
loc: SourceLocation

返回: CustomPattern

Callback to produce a custom object destructuring pattern node.

propertyPattern(key, patt[, loc])
key: CustomLiteral | CustomIdentifier
patt: CustomPattern
loc: SourceLocation

返回: CustomPropertyPattern

Callback to produce a custom object property destructuring pattern node.

Clauses

switchCase(test, cons[, loc])
test: CustomExpression | null
cons: [ CustomStatement ]
loc: SourceLocation

返回: CustomSwitchCase

Callback to produce a custom case or default clause node. The test argument is null if and only if the node is a default clause.

catchClause(arg, guard, body[, loc])
arg: CustomPattern
guard: CustomExpression
body: CustomStatement
loc: SourceLocation

返回: CustomCatchClause

Callback to produce a custom catch clause node.

comprehensionBlock(left, right, isForEach[, loc])
left: CustomPattern
right: CustomExpression
isForEach: boolean
loc: SourceLocation

返回: CustomComprehensionBlock

Callback to produce a custom comprehension block node. The isForEach flag indicates whether the node is a for each block.

Miscellaneous

identifier(name[, loc])
name: string
loc: SourceLocation

返回: CustomIdentifier/CustomPattern/CustomExpression

Callback to produce a custom identifier node.

literal(val[, loc])
val: string | boolean | null | number | RegExp
loc: SourceLocation

返回: CustomLiteral / CustomExpression

Callback to produce a custom literal node.

property(kind, key, val[, loc])
kind: "init" | "get" | "set"
key: CustomLiteral | CustomIdentifier
val: CustomExpression
loc: SourceLocation 

返回: CustomObjectProperty

Callback to produce a custom object property initializer node.

E4X

Declarations

xmlDefaultDeclaration(ns[, loc])
loc: SourceLocation

返回: CustomDeclaration

Callback to produce a custom XML default namespace declaration node.

Expressions

xmlAnyName([loc])
loc: SourceLocation

返回: CustomXMLAnyName/CustomXML/CustomExpression

Callback to produce a custom XML node for the wildcard pseudo-identifier *.

xmlAttributeSelector(expr[, loc])
expr: CustomExpression
loc: SourceLocation

返回: CustomXML/CustomExpression

Callback to produce a custom XML attribute selector node.

xmlFilterExpression(left, right[, loc])
left: CustomExpression
right: CustomExpression
loc: SourceLocation

返回: CustomXML/CustomExpression

Callback to produce a custom XML filter expression node.

xmlQualifiedIdentifier(left, right, isComputed[, loc])
left: CustomIdentifier | CustomXMLAnyName
right: CustomIdentifier | CustomExpression
isComputed: boolean
loc: SourceLocation

返回: CustomXML/CustomExpression

Callback to produce a custom qualified identifier node.

xmlFunctionQualifiedIdentifier(right, isComputed[, loc])
right: CustomIdentifier | CustomExpression
isComputed: boolean
loc: SourceLocation

返回: CustomXML/CustomExpression

Callback to produce a custom XML function-qualified identifier node.

xmlElement(contents[, loc])
contents: [ CustomXML ]
loc: SourceLocation

返回: CustomXML / CustomExpression

Callback to produce a custom XML element node.

xmlList(contents[, loc])
contents: [ CustomXML ]
loc: SourceLocation

返回: CustomXML/CustomExpression

Callback to produce a custom XML list node.

XML

xmlEscape(expr[, loc])
expr: CustomExpression
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML escape node.

xmlText(text[, loc])
text: string
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML text node.

xmlStartTag(contents[, loc])
contents: [ CustomXML ]
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML start-tag node.

xmlEndTag(contents[, loc])
contents: [ CustomXML ]
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML end-tag node.

xmlPointTag(contents[, loc])
contents: [ CustomXML ]
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML point tag node.

xmlName(contents[, loc])
contents: string | [ CustomXML ]
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML name node.

xmlAttribute(value[, loc])
value: string
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML attribute node.

xmlCdata(contents[, loc])
contents: string
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML CDATA node.

xmlComment(contents[, loc])
contents: string
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML comment node.

xmlProcessingInstruction(target, contents[, loc])
target: string
contents: string | null
loc: SourceLocation

返回: CustomXML

Callback to produce a custom XML processing instruction node.

修订版来源

<p>{{ jsapi_minversion_header("1.8.5") }}</p>
<p>Recent builds of the <a href="/En/SpiderMonkey/Build_Documentation" title="https://developer.mozilla.org/en/SpiderMonkey/Build_Documentation">standalone SpiderMonkey shell</a> include a reflection of the SpiderMonkey parser, made available as a JavaScript API. 这使得我们更容易的用JavaScript写出处理JavaScript源代码的工具, 比如语法高亮工具,静态分析工具, 翻译器,编译器,混淆器等等.</p>
<p>例子:</p>
<pre>
&gt; var expr = Reflect.parse("obj.foo + 42").body[0].expression
&gt; expr.left.property
({loc:null, type:"Identifier", name:"foo"})
&gt; expr.right
({loc:{source:null, start:{line:1, column:10}, end:{line:1, column:12}}, type:"Literal", value:42})
</pre>
<p>Reflect也可以使用在Firefox 7及以上版本中,但必须要导入一个模块:</p>
<pre>
Components.utils.import("resource://gre/modules/reflect.jsm") 
</pre>
<p>如果不想用<code>Reflect</code>全局对象,也可以指定一个对象名称:</p>
<pre>
Components.utils.import("resource://gre/modules/reflect.jsm", obj)
</pre>
<h2 id="Built-in_objects">内置对象</h2>
<p>无论是SpiderMonkey shell还是Firefox (导入模块之后),全局对象<code>Reflect</code>目前都只有一个<code>parse</code>方法.</p>
<h2 id="Properties_of_the_Reflect_object"><code>Reflect</code>对象的属性</h2>
<p><code>Reflect</code>对象目前只有一个方法.</p>
<h4 id="Reflect.parse(src.5B.2C_options.5D)"><code>Reflect.parse(src[, options])</code></h4>
<p>Coerces <strong><span style="font-family: Courier New;">src</span></strong> to a string and parses the result as a JavaScript program. By default, the parsing returns a Program object (see below) representing the parsed abstract syntax tree (AST).</p>
<p>Additional options may be provided via the <strong><span style="font-family: Courier New;">options</span></strong> object, which can include any of the following properties:</p>
<table border="0" cellpadding="1" cellspacing="1" style="width: 67%; table-layout: fixed; border: 1px solid rgb(237, 242, 247);">
  <tbody>
    <tr style="background-color: rgb(241, 246, 251);">
      <td style=""><strong><span style="font-family: Courier New;">loc</span></strong></td>
      <td style="">Boolean</td>
      <td style="">Default:&nbsp;<span style="font-family: Courier New;">true</span></td>
    </tr>
    <tr>
      <td colspan="3">如果<strong><span style="font-family: Courier New;">loc</span></strong>为<span style="font-family: Courier New;">true</span>,则解析器会在返回的AST节点中包含上源码的位置信息.</td>
    </tr>
    <tr style="background-color: rgb(241, 246, 251);">
      <td><strong><span style="font-family: Courier New;">source</span></strong></td>
      <td>String</td>
      <td>Default:&nbsp;<span style="font-family: Courier New;">null</span></td>
    </tr>
    <tr>
      <td colspan="3">A description of the input source; typically a filename, path, or URL. This string is not meaningful to the parsing process, but is produced as part of the source location information in the returned AST&nbsp;nodes.</td>
    </tr>
    <tr style="background-color: rgb(241, 246, 251);">
      <td><strong><span style="font-family: Courier New;">line</span></strong></td>
      <td>Number</td>
      <td>Default:&nbsp;<span style="font-family: Courier New;">1</span></td>
    </tr>
    <tr>
      <td colspan="3">初始行号,用在源码位置信息上.</td>
    </tr>
    <tr style="background-color: rgb(241, 246, 251);">
      <td><strong><span style="font-family: Courier New;">builder</span></strong></td>
      <td>Builder</td>
      <td>Default:&nbsp;<span style="font-family: Courier New;">null</span></td>
    </tr>
    <tr>
      <td colspan="3">
        <p>A builder object, which can be used to produce AST&nbsp;nodes in custom data formats. The expected callback methods are described under <a href="/en/SpiderMonkey/Parser_API#Builder_objects" title="en/SpiderMonkey/Parser API#Builder objects">Builder Objects</a>.</p>
      </td>
    </tr>
  </tbody>
</table>
<p>If parsing fails due to a syntax error, an instance of <code>SyntaxError</code> is thrown. The syntax error object thrown by <code>Reflect.parse()</code> has the same <code>message</code> property as the syntax error that would be thrown by <code>eval(src)</code>. The <code>lineNumber</code> and <code>fileName</code> properties of the syntax error object indicate the source location of the syntax error.</p>
<h2 id="Node_objects">节点对象</h2>
<p>By default, <code>Reflect.parse()</code> produces Node objects, which are plain JavaScript objects (i.e., their prototype derives from the standard <code>Object</code> prototype). All node types implement the following interface:</p>
<pre>
interface Node {
    type: string;
    loc: SourceLocation |&nbsp;null;
}
</pre>
<p>The <code>type</code> field is a string representing the AST&nbsp;variant type. Each subtype of Node is documented below with the specific string of its <code>type</code> field. You can use this field to determine which interface a node implements.</p>
<p>The <code>loc</code> field represents the source location information of the node. If the parser produced no information about the node's source location, the field is <code>null</code>; 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 <em>after</em> the parsed source region):</p>
<pre>
interface SourceLocation {
    source:&nbsp;string |&nbsp;null;
    start:&nbsp;Position;
    end:&nbsp;Position;
} 
</pre>
<p>Each <code>Position</code> object consists of a <code>line</code> number (1-indexed)&nbsp;and a <code>column</code> number (0-indexed):</p>
<pre>
interface Position {
    line: uint32 &gt;= 1;
    column: uint32 &gt;= 0;
}</pre>
<h3 id="Programs">Programs</h3>
<pre>
interface Program &lt;: Node {
    type:&nbsp;"Program";
    body: [ Statement ];
}
</pre>
<p>A&nbsp;complete program source tree.</p>
<h3 id="Functions">函数</h3>
<pre>
interface Function &lt;: Node {
    id: Identifier | null;
    params: [ Pattern ];
    defaults: [ Expression ];
    rest: Identifier | null;
    body: BlockStatement |&nbsp;Expression;
    generator:&nbsp;boolean;
    expression:&nbsp;boolean;
}
</pre>
<p>A function declaration or expression. The <code>body</code> of the function may be a block statement, or in the case of an <a href="/en/JavaScript/New_in_JavaScript/1.8#Expression_closures_%28Merge_into_own_page.2fsection%29" title="https://developer.mozilla.org/en/new_in_javascript_1.8#Expression_closures_(Merge_into_own_page.2fsection)">expression closure</a>, an expression.</p>
<div class="note">
  <strong>注:</strong> Expression closures 是SpiderMonkey特有的.</div>
<p>If the <code>generator</code> flag is <code>true</code>, the function is a <a href="/en/JavaScript/Guide/Iterators_and_Generators" title="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Iterators_and_Generators">generator function</a>, i.e., contains a <code>yield</code> expression in its body (other than in a nested function).</p>
<div class="note">
  <strong>注:</strong> Generators 是SpiderMonkey特有的.</div>
<p>If the <code>expression</code> flag is <code>true</code>, the function is an expression closure and the <code>body</code> field is an expression.</p>
<h3 id="Statements">语句</h3>
<pre>
interface Statement &lt;: Node { }
</pre>
<p>任意语句.</p>
<pre>
interface EmptyStatement &lt;: Statement {
    type:&nbsp;"EmptyStatement";
}
</pre>
<p>一个空语句,也就是,一个孤立的分号.</p>
<pre>
interface BlockStatement &lt;: Statement {
    type:&nbsp;"BlockStatement";
    body: [ Statement ];
}
</pre>
<p>一个语句块,也就是由大括号包围的语句序列.</p>
<pre>
interface ExpressionStatement &lt;: Statement {
    type:&nbsp;"ExpressionStatement";
    expression: Expression;
}
</pre>
<p>一个表达式语句,也就是,仅有一个表达式组成的语句.</p>
<pre>
interface IfStatement &lt;: Statement {
    type:&nbsp;"IfStatement";
    test: Expression;
    consequent: Statement;
    alternate: Statement |&nbsp;null;
}
</pre>
<p>一个<code>if</code>语句.</p>
<pre>
interface LabeledStatement &lt;: Statement {
    type:&nbsp;"LabeledStatement";
    label: Identifier;
    body: Statement;
}
</pre>
<p>一个标签语句,也就是, a statement prefixed by a <code>break</code>/<code>continue</code> label.</p>
<pre>
interface BreakStatement &lt;: Statement {
    type:&nbsp;"BreakStatement";
    label: Identifier | null;
}
</pre>
<p>一个<code>break</code>语句.</p>
<pre>
interface ContinueStatement &lt;: Statement {
    type:&nbsp;"ContinueStatement";
    label: Identifier | null;
}
</pre>
<p>一个<code>continue语句</code>.</p>
<pre>
interface WithStatement &lt;: Statement {
    type:&nbsp;"WithStatement";
    object: Expression;
    body: Statement;
}
</pre>
<p>A&nbsp;<code>with</code> statement.</p>
<pre>
interface SwitchStatement &lt;: Statement {
    type:&nbsp;"SwitchStatement";
    discriminant: Expression;
    cases: [ SwitchCase ];
    lexical:&nbsp;boolean;
}
</pre>
<p>一个<code>switch</code>语句. The lexical flag is metadata indicating whether the <code>switch</code> statement contains any unnested <code>let</code> declarations (and therefore introduces a new lexical scope).</p>
<pre>
interface ReturnStatement &lt;: Statement {
    type:&nbsp;"ReturnStatement";
    argument: Expression | null;
}
</pre>
<p>一个<code>return</code>语句.</p>
<pre>
interface ThrowStatement &lt;: Statement {
    type:&nbsp;"ThrowStatement";
    argument: Expression;
}
</pre>
<p>一个<code>throw</code>语句.</p>
<pre>
interface TryStatement &lt;: Statement {
    type:&nbsp;"TryStatement";
    block: BlockStatement;
    handlers: [ CatchClause ];
    finalizer: BlockStatement | null;
}
</pre>
<p>一个<code>try</code>语句.</p>
<div class="note">
  <strong>注:</strong> 多个<code>catch</code>子句是SpiderMonkey特有的.</div>
<pre>
interface WhileStatement &lt;: Statement {
    type:&nbsp;"WhileStatement";
    test: Expression;
    body: Statement;
}
</pre>
<p>一个<code>while</code>语句.</p>
<pre>
interface DoWhileStatement &lt;: Statement {
    type:&nbsp;"DoWhileStatement";
    body: Statement;
    test: Expression;
}
</pre>
<p>一个<code>do</code>/<code>while</code>语句.</p>
<pre>
interface ForStatement &lt;: Statement {
    type:&nbsp;"ForStatement";
    init: VariableDeclaration | Expression | null;
    test: Expression | null;
    update: Expression | null;
    body:&nbsp;Statement;
}
</pre>
<p>一个<code>for</code>语句.</p>
<pre>
interface ForInStatement &lt;: Statement {
    type:&nbsp;"ForInStatement";
    left: VariableDeclaration |  Expression;
    right: Expression;
    body: Statement;
    each:&nbsp;boolean;
}
</pre>
<p>一个<code>for</code>/<code>in</code>语句, or, if <code>each</code> is <code>true</code>, a <code>for each</code>/<code>in</code> statement.</p>
<div class="note">
  <strong>注:</strong> <code>for each</code>语法是SpiderMonkey特有的.</div>
<pre>
interface LetStatement &lt;: Statement {
    type:&nbsp;"LetStatement";
    head: [ { id: Pattern, init: Expression | null } ];
    body:&nbsp;Statement;
}
</pre>
<p>一个<code>let语句</code>.</p>
<div class="note">
  <strong>注:</strong> <code>let</code>语句形式是SpiderMonkey特有的.</div>
<pre>
interface DebuggerStatement &lt;: Statement {
    type:&nbsp;"DebuggerStatement";
}
</pre>
<p>一个<code>debugger</code>语句.</p>
<div class="note">
  <strong>注:</strong> <code>debugger</code>语句是ECMAScript 5中的新语法,尽管SpiderMonkey已经支持它很多年了.</div>
<h3 id=".E5.A3.B0.E6.98.8E">声明</h3>
<pre>
interface Declaration &lt;: Statement { }
</pre>
<p>Any declaration node. Note that declarations are considered statements; this is because declarations can appear in any statement context in the language recognized by the SpiderMonkey parser.</p>
<div class="note">
  <strong>注:</strong> 任意嵌套作用域下的声明是SpiderMonkey特有的.</div>
<pre>
interface FunctionDeclaration &lt;: Function, Declaration {
    type: "FunctionDeclaration";
    id: Identifier;
    params: [ Pattern ];
    defaults: [ Expression ];
    rest: Identifier | null;
    body: BlockStatement | Expression;
    generator: boolean;
    expression: boolean;
}
</pre>
<p>一个函数声明.</p>
<div class="note">
  <strong>注:</strong> <code>id</code>字段不能为<code>null</code>.</div>
<pre>
interface VariableDeclaration &lt;: Declaration {
    type:&nbsp;"VariableDeclaration";
    declarations: [ VariableDeclarator ];
    kind:&nbsp;"var"&nbsp;|&nbsp;"let"&nbsp;|&nbsp;"const";
}
</pre>
<p>一个变量声明,可以通过<code>var</code>, <code>let</code>, 或<code>const</code>.</p>
<pre>
interface VariableDeclarator &lt;: Node {
    type:&nbsp;"VariableDeclarator";
    id: Pattern;
    init:&nbsp;Expression |&nbsp;null;
}
</pre>
<p>一个变量<span class="st">声明符</span>.</p>
<div class="note">
  <strong>注:</strong> <code>id</code>字段不能为<code>null</code>.</div>
<div class="note">
  <strong>注:</strong>&nbsp;<code>let</code>和<code>const是</code>SpiderMonkey特有的.</div>
<h3 id=".E8.A1.A8.E8.BE.BE.E5.BC.8F">表达式</h3>
<pre>
interface Expression &lt;: Node, Pattern { }</pre>
<p>任意表达式节点. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern.</p>
<pre>
interface ThisExpression &lt;: Expression {
    type:&nbsp;"ThisExpression";
}
</pre>
<p>一个<code>this</code>表达式.</p>
<pre>
interface ArrayExpression &lt;: Expression {
    type:&nbsp;"ArrayExpression";
    elements: [ Expression | null ];
}</pre>
<p>一个数组表达式.</p>
<pre>
interface ObjectExpression &lt;: Expression {
    type:&nbsp;"ObjectExpression";
    properties: [ { key: Literal | Identifier,
                   &nbsp;value: Expression,
                    kind:&nbsp;"init"&nbsp;|&nbsp;"get"&nbsp;|&nbsp;"set" } ];
}</pre>
<p>一个对象表达式. A literal property in an object expression can have either a string or number as its <code>value</code>. Ordinary property initializers have a <code>kind</code> value <code>"init"</code>; getters and setters have the <code>kind</code> values <code>"get"</code>&nbsp;and <code>"set"</code>, respectively.</p>
<pre>
interface FunctionExpression &lt;: Function, Expression {
    type:&nbsp;"FunctionExpression";
    id: Identifier | null;
    params: [ Pattern ];
    defaults: [ Expression ];
    rest: Identifier | null;
    body: BlockStatement | Expression;
    generator: boolean;
    expression: boolean;
}
</pre>
<p>一个函数表达式.</p>
<pre>
interface SequenceExpression &lt;: Expression {
    type:&nbsp;"SequenceExpression";
    expressions: [ Expression ];
}</pre>
<p>一个序列表达式,也就是一个由逗号分割的表达式序列.</p>
<pre>
interface UnaryExpression &lt;: Expression {
    type:&nbsp;"UnaryExpression";
    operator: UnaryOperator;
    prefix: boolean;
    argument: Expression;
}</pre>
<p>A unary operator expression.</p>
<pre>
interface BinaryExpression &lt;: Expression {
    type:&nbsp;"BinaryExpression";
    operator: BinaryOperator;
    left: Expression;
    right: Expression;
}</pre>
<p>一个二元运算符表达式.</p>
<pre>
interface AssignmentExpression &lt;: Expression {
    type:&nbsp;"AssignmentExpression";
    operator: AssignmentOperator;
    left: Expression;
    right: Expression;
}</pre>
<p>An assignment operator expression.</p>
<pre>
interface UpdateExpression &lt;: Expression {
    type:&nbsp;"UpdateExpression";
    operator: UpdateOperator;
    argument: Expression;
    prefix: boolean;
}</pre>
<p>An update (increment or decrement)&nbsp;operator expression.</p>
<pre>
interface LogicalExpression &lt;: Expression {
    type:&nbsp;"LogicalExpression";
    operator: LogicalOperator;
    left: Expression;
    right: Expression;
}</pre>
<p>一个逻辑运算符表达式.</p>
<pre>
interface ConditionalExpression &lt;: Expression {
    type:&nbsp;"ConditionalExpression";
    test: Expression;
    alternate: Expression;
    consequent: Expression;
}</pre>
<p>一个条件运算符表达式, i.e., a ternary <code>?</code>/<code>:</code> expression.</p>
<pre>
interface NewExpression &lt;: Expression {
    type:&nbsp;"NewExpression";
    callee: Expression;
    arguments: [ Expression ] | null;
}</pre>
<p>A <code>new</code> expression.</p>
<pre>
interface CallExpression &lt;: Expression {
    type:&nbsp;"CallExpression";
    callee: Expression;
    arguments: [ Expression ];
}</pre>
<p>A function or method call expression.</p>
<pre>
interface MemberExpression &lt;: Expression {
    type:&nbsp;"MemberExpression";
    object: Expression;
    property: Identifier | Expression;
    computed : boolean;
}</pre>
<p>一个member表达式. If <code>computed === true</code>, the node corresponds to a computed <code>e1[e2]</code> expression and property is an <code>Expression</code>. If <code>computed === false</code>, the node corresponds to a static <code>e1.x</code> expression and property is an <code>Identifier</code>.</p>
<pre>
interface YieldExpression &lt;: Expression {
    argument:&nbsp;Expression |&nbsp;null;
}
</pre>
<p>A&nbsp;<code>yield</code> expression.</p>
<div class="note">
  <strong>注:</strong>&nbsp;<code>yield</code> expressions 是SpiderMonkey特有的.</div>
<pre>
interface ComprehensionExpression &lt;: Expression {
    body:&nbsp;Expression;
    blocks:&nbsp;[ ComprehensionBlock ];
    filter:&nbsp;Expression |&nbsp;null;
}
</pre>
<p>An <a href="/en/JavaScript/Guide/Obsolete_Pages/Working_with_Arrays#Array_comprehensions" title="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Working_with_Arrays#Array_comprehensions">array comprehension</a>. The <code>blocks</code> array corresponds to the sequence of <code>for</code> and <code>for each</code> blocks. The optional <code>filter</code> expression corresponds to the final <code>if</code> clause, if present.</p>
<div class="note">
  <strong>注:</strong> Array comprehensions 是SpiderMonkey特有的.</div>
<pre>
interface GeneratorExpression &lt;: Expression {
    body:&nbsp;Expression;
    blocks:&nbsp;[ ComprehensionBlock ];
    filter:&nbsp;Expression |&nbsp;null;
}
</pre>
<p>A <a href="/en/JavaScript/Guide/Iterators_and_Generators#Generator_expressions" title="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Iterators_and_Generators#Generator_expressions">generator expression</a>. As with array comprehensions, the <code>blocks</code> array corresponds to the sequence of <code>for</code> and <code>for each</code> blocks, and the optional <code>filter</code> expression corresponds to the final <code>if</code> clause, if present.</p>
<div class="note">
  <strong>注:</strong> Generator expressions 是SpiderMonkey特有的.</div>
<pre>
interface GraphExpression &lt;: Expression {
    index:&nbsp;uint32;
    expression:&nbsp;Literal;
}
</pre>
<p>A&nbsp;<a href="/en/JavaScript/Sharp_variables_in_JavaScript" title="https://developer.mozilla.org/en/Sharp_variables_in_JavaScript">graph expression</a>, aka "sharp literal," such as <code>#1={ self:&nbsp;#1# }</code>.</p>
<div class="note">
  <strong>注:</strong> Graph expressions 是SpiderMonkey特有的.</div>
<pre>
interface GraphIndexExpression &lt;: Expression {
    index:&nbsp;uint32;
}
</pre>
<p>一个<a href="/en/JavaScript/Sharp_variables_in_JavaScript" title="https://developer.mozilla.org/en/Sharp_variables_in_JavaScript">graph索引表达式</a>,又称为"井号变量",比如<code>#1#</code>.</p>
<div class="note">
  <strong>注:</strong> Graph索引表达式</div>
<div class="note">
  Graph索引表达式是SpiderMonkey特有的.</div>
<pre>
interface LetExpression &lt;: Expression {
    type:&nbsp;"LetExpression";
    head: [ { id: Pattern, init: Expression | null } ];
    body: Expression;
}
</pre>
<p>一个<code>let表达式</code>.</p>
<div class="note">
  <strong>注:</strong> <code>let</code>表达式是SpiderMonkey特有的.</div>
<h3 id="Patterns">模式</h3>
<pre>
interface Pattern &lt;: Node { }
</pre>
<p>JavaScript 1.7 introduced <a href="/en/JavaScript/New_in_JavaScript/1.7#Destructuring_assignment_%28Merge_into_own_page.2fsection%29" title="https://developer.mozilla.org/en/new_in_javascript_1.7#Destructuring_assignment_(Merge_into_own_page.2fsection)">destructuring assignment and binding</a> forms. All binding forms (such as function parameters, variable declarations, and <code>catch</code> block headers), accept array and object destructuring patterns in addition to plain identifiers. The left-hand sides of assignment expressions can be arbitrary expressions, but in the case where the expression is an object or array literal, it is interpreted by SpiderMonkey as a destructuring pattern.</p>
<p>Since the left-hand side of an assignment can in general be any expression, in an assignment context, a pattern can be any expression. In binding positions (such as function parameters, variable declarations, and <code>catch</code> headers), patterns can only be identifiers in the base case, not arbitrary expressions.</p>
<pre>
interface ObjectPattern &lt;: Pattern {
    type: "ObjectPattern";
    properties: [ { key: Literal | Identifier, value: Pattern } ];
}
</pre>
<p>An object-destructuring pattern. A literal property in an object pattern can have either a string or number as its <code>value</code>.</p>
<pre>
interface ArrayPattern &lt;: Pattern {
    type: "ArrayPattern";
    elements: [ Pattern | null ];
}
</pre>
<p>An array-destructuring pattern.</p>
<h3 id="Clauses">子句</h3>
<pre>
interface SwitchCase &lt;: Node {
    type:&nbsp;"SwitchCase";
    test: Expression | null;
    consequent: [ Statement ];
}
</pre>
<p>一个<code>case</code> (if <code>test</code> is an <code>Expression</code>) or <code>default</code> (if <code>test === null</code>)&nbsp;clause in the body of a <code>switch</code>语句.</p>
<pre>
interface CatchClause &lt;: Node {
    type:&nbsp;"CatchClause";
    param: Pattern;
    guard: Expression | null;
    body: BlockStatement;
}
</pre>
<p>A&nbsp;<code>catch</code> clause following a <code>try</code> block. The optional <code>guard</code> property corresponds to the optional expression guard on the bound variable.</p>
<div class="note">
  <strong>注:</strong> The guard expression is SpiderMonkey-specific.</div>
<pre>
interface ComprehensionBlock &lt;: Node {
    left:&nbsp;Pattern;
    right:&nbsp;Expression;
    each:&nbsp;boolean;
}
</pre>
<p>A&nbsp;<code>for</code> or <code>for each</code> block in an array comprehension or generator expression.</p>
<div class="note">
  <strong>注:</strong> Array comprehensions and generator expressions 是SpiderMonkey特有的.</div>
<h3 class="r"><nobr>杂项</nobr></h3>
<pre>
interface Identifier &lt;: Node, Expression, Pattern {
    type:&nbsp;"Identifier";
    name: string;
}
</pre>
<p>An identifier. Note that an identifier may be an expression or a destructuring pattern.</p>
<pre>
interface Literal &lt;: Node, Expression {
    type:&nbsp;"Literal";
    value: string | boolean | null | number | RegExp;
}
</pre>
<p>A&nbsp;literal token. Note that a literal can be an expression.</p>
<pre>
enum UnaryOperator {
    "-" | "+" | "!" | "~" | "typeof" | "void" | "delete"
}
</pre>
<p>A unary operator token.</p>
<pre>
enum BinaryOperator {
    "==" | "!=" | "===" | "!=="
         | "&lt;" | "&lt;=" | "&gt;" | "&gt;="
         | "&lt;&lt;" | "&gt;&gt;" | "&gt;&gt;&gt;"
         | "+" | "-" | "*" | "/" | "%"
         | "|" | "^" | "in"
         | "instanceof" | ".."
}
</pre>
<p>A&nbsp;binary operator token.</p>
<div class="note">
  <strong>注:</strong> The <code>..</code> operator is E4X-specific.</div>
<pre>
enum LogicalOperator {
    "||" | "&amp;&amp;"
}
</pre>
<p>A logical operator token.</p>
<pre>
enum AssignmentOperator {
    "=" | "+=" | "-=" | "*=" | "/=" | "%="
        | "&lt;&lt;=" | "&gt;&gt;=" | "&gt;&gt;&gt;="
        | "|=" | "^=" | "&amp;="
}
</pre>
<p>An assignment operator token.</p>
<pre>
enum UpdateOperator {
    "++" | "--"
}
</pre>
<p>An update (increment or decrement) operator token.</p>
<h3 id="E4X">E4X</h3>
<p>下面介绍一下为E4X提供支持的节点类型.</p>
<div class="note">
  <strong>注:</strong>&nbsp;E4X不是ECMAScript规范(<a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-262.htm" title="http://www.ecma-international.org/publications/standards/Ecma-262.htm">ECMA-262</a>)的一部分,它是一个单独的标准(<a class="external" href="http://www.ecma-international.org/publications/standards/Ecma-357.htm" title="http://www.ecma-international.org/publications/standards/Ecma-357.htm">ECMA-357</a>).</div>
<h4 id="Declarations">声明</h4>
<pre>
interface XMLDefaultDeclaration &lt;: Declaration {
    type: "XMLDefaultDeclaration";
    namespace: Expression;
}
</pre>
<p>一个默认<code>xml命名空间</code>声明</p>
<h4 id="Expressions">表达式</h4>
<pre>
interface XMLAnyName &lt;: Expression {
    type: "XMLAnyName";
}
</pre>
<p>The special E4X wildcard pseudo-identifier <code>*</code>.</p>
<pre>
interface XMLQualifiedIdentifier &lt;: Expression {
    type: "XMLQualifiedIdentifier";
    left: Identifier |&nbsp;XMLAnyName;
    right: Identifier | Expression;
    computed: boolean;
}
</pre>
<p>An E4X&nbsp;qualified identifier, i.e., a pseudo-identifier using the namespace separator <code>::</code>. If the qualified identifier has a computed name (i.e., the <code>id::[expr]</code> form), then <code>computed</code> is <code>true</code> and the <code>right</code> property is an expression.</p>
<pre>
interface XMLFunctionQualifiedIdentifier &lt;: Expression {
    type: "XMLFunctionQualifiedIdentifier";
    right: Identifier | Expression;
    computed: boolean;
}
</pre>
<p>An E4X&nbsp;identifier qualified by the <code>function</code> keyword, e.g. <code>function::id</code>.</p>
<div class="note">
  <strong>注:</strong>&nbsp;<code>function</code>-qualified identifiers 是SpiderMonkey特有的.</div>
<pre>
interface XMLAttributeSelector &lt;: Expression {
    type: "XMLAttributeSelector";
    attribute: Expression;
}
</pre>
<p>An E4X&nbsp;attribute selector expression, i.e., an <code>@</code> expression.</p>
<pre>
interface XMLFilterExpression &lt;: Expression {
    type: "XMLFilterExpression";
    left: Expression;
    right: Expression;
}
</pre>
<p>An E4X&nbsp;list filter expression, i.e., an expression of the form <code>expr.(expr)</code>.</p>
<pre>
interface XMLElement &lt;: XML, Expression {
    type: "XMLElement";
    contents: [ XML ];
}
</pre>
<p>An E4X literal representing a single XML&nbsp;element.</p>
<pre>
interface XMLList &lt;: XML, Expression {
    type: "XMLList";
    contents: [ XML ];
}
</pre>
<p>An E4X&nbsp;literal representing a list of XML&nbsp;elements.</p>
<h4 id="XML">XML</h4>
<pre>
interface XML &lt;: Node { }
</pre>
<p>XML&nbsp;data.</p>
<pre>
interface XMLEscape &lt;: XML {
    type "XMLEscape";
    expression: Expression;
}
</pre>
<p>XML&nbsp;data with an escaped JavaScript expression.</p>
<pre>
interface XMLText &lt;: XML {
    type: "XMLText";
    text: string;
}
</pre>
<p>Literal XML&nbsp;text.</p>
<pre>
interface XMLStartTag &lt;: XML {
    type: "XMLStartTag";
    contents: [ XML ];
}
</pre>
<p>An XML&nbsp;start tag.</p>
<pre>
interface XMLEndTag &lt;: XML {
    type: "XMLEndTag";
    contents: [ XML ];
}
</pre>
<p>An XML&nbsp;end tag.</p>
<pre>
interface XMLPointTag &lt;: XML {
    type: "XMLPointTag";
    contents: [ XML ];
}
</pre>
<p>An XML&nbsp;point tag.</p>
<pre>
interface XMLName &lt;: XML {
    type: "XMLName";
    contents: string | [ XML ];
}
</pre>
<p>An XML&nbsp;name.</p>
<pre>
interface XMLAttribute &lt;: XML {
    type: "XMLAttribute";
    value: string;
}
</pre>
<p>An XML&nbsp;attribute value.</p>
<pre>
interface XMLCdata &lt;: XML {
    type: "XMLCdata";
    contents: string;
}
</pre>
<p>An XML&nbsp;CDATA&nbsp;node.</p>
<pre>
interface XMLComment &lt;: XML {
    type: "XMLComment";
    contents: string;
}
</pre>
<p>An XML&nbsp;comment.</p>
<pre>
interface XMLProcessingInstruction &lt;: XML {
    type: "XMLProcessingInstruction";
    target: string;
    contents: string | null;
}
</pre>
<p>An XML&nbsp;processing instruction.</p>
<h2 id="Builder_objects">Builder objects</h2>
<p>The optional <strong><code>builder</code></strong> parameter to <code>Reflect.parse()</code> makes it possible to construct user-specified data from the parser, rather than the default <code>Node</code> objects. Builder objects may contain any of the callback methods described in this section.</p>
<p>Each callback can produce any custom, user-defined datatype; these are referred to below as <code>CustomExpression</code>, <code>CustomStatement</code>, etc.</p>
<div class="note">
  <strong>注:</strong>&nbsp;Because this library uses <code>null</code> for optional nodes, it is recommended that user-defined datatypes <strong>not</strong> use <code>null</code> as a representation of an AST node.</div>
<p>If the <strong><code>loc</code></strong> option is enabled (see the <a href="/en/SpiderMonkey/Parser_API#Reflect.parse(src.5b.2c_options.5d)" title="en/SpiderMonkey/Parser API#Reflect.parse(src.5b.2c options.5d)">Reflect.parse() options</a> above), then each callback is provided with the source location information of the parsed node as an extra parameter.</p>
<p>All builder callbacks are optional. When a callback is missing, the default format is used, but the provided builder methods are still used recursively for sub-nodes.</p>
<h3 id="Programs">Programs</h3>
<h5 id="program(body.5B.2C_loc.5D)"><code>program(body[, loc])</code></h5>
<pre>
body:&nbsp;[ CustomStatement ]
loc: SourceLocation
</pre>
<p><strong>返回:</strong> CustomProgram</p>
<p>Callback to produce a custom program node.</p>
<h3 id="Statements">Statements</h3>
<h5 id="emptyStatement(.5Bloc.5D)"><code>emptyStatement([loc])</code></h5>
<pre>
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom empty statement node.</p>
<h5 id="blockStatement(body.5B.2C_loc.5D)"><code>blockStatement(body[, loc])</code></h5>
<pre>
body:&nbsp;CustomStatement
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom block statement node.</p>
<h5 id="expressionStatement(expr.5B.2C_loc.5D)"><code>expressionStatement(expr[, loc])</code></h5>
<pre>
expr:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom expression statement node.</p>
<h5 id="labeledStatement(label.2C_body.5B.2C_loc.5D)"><code>labeledStatement(label, body[, loc])</code></h5>
<pre>
label:&nbsp;CustomIdentifier
body:&nbsp;CustomStatement
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom labeled statement node.</p>
<h5 id="ifStatement(test.2C_cons.2C_alt.5B.2C_loc.5D)"><code>ifStatement(test, cons, alt[, loc])</code></h5>
<pre>
test:&nbsp;CustomExpression
cons:&nbsp;CustomStatement
alt:&nbsp;CustomStatement |&nbsp;null
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>if</code> statement node.</p>
<h5 id="switchStatement(disc.2C_cases.2C_isLexical.5B.2C_loc.5D)"><code>switchStatement(disc, cases, isLexical[, loc])</code></h5>
<pre>
disc:&nbsp;CustomExpression
cases:&nbsp;[ CustomSwitchCase ]
isLexical:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>switch</code> statement node. The <strong><code>isLexical</code></strong> flag is metadata indicating whether the <code>switch</code> statement contains any unnested <code>let</code> declarations (and therefore introduces a new lexical scope).</p>
<h5 id="whileStatement(test.2C_body.5B.2C_loc.5D)"><code>whileStatement(test, body[, loc])</code></h5>
<pre>
test:&nbsp;CustomExpression
body:&nbsp;CustomStatement
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>while</code> statement node.</p>
<h5 id="doWhileStatement(body.2C_test.5B.2C_loc.5D)"><code>doWhileStatement(body, test[, loc])</code></h5>
<pre>
body:&nbsp;CustomStatement
test:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>do</code>-<code>while</code> statement node.</p>
<h5 id="forStatement(init.2C_test.2C_update.2C_body.5B.2C_loc.5D)"><code>forStatement(init, test, update, body[, loc])</code></h5>
<pre>
init:&nbsp;CustomVariableDeclaration |&nbsp;CustomExpression |&nbsp;null
test:&nbsp;CustomExpression |&nbsp;null
update:&nbsp;CustomExpression |&nbsp;null
body:&nbsp;CustomStatement
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>for</code> statement node.</p>
<h5 id="forInStatement(left.2C_right.2C_body.2C_isForEach.5B.2C_loc.5D)"><code>forInStatement(left, right, body, isForEach[, loc])</code></h5>
<pre>
left:&nbsp;CustomVariableDeclaration |&nbsp;CustomExpression
right:&nbsp;CustomExpression
body:&nbsp;CustomStatement
isForEach:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>for</code>-<code>in</code> statement node. The <strong><code>isForEach</code></strong> flag indicates whether the node is a <code>for each</code> statement.</p>
<h5 id="breakStatement(label.5B.2C_loc.5D)"><code>breakStatement(label[, loc])</code></h5>
<pre>
label:&nbsp;CustomIdentifier |&nbsp;null
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>break</code> statement node.</p>
<h5 id="continueStatement(label.5B.2C_loc.5D)"><code>continueStatement(label[, loc])</code></h5>
<pre>
label:&nbsp;CustomIdentifier |&nbsp;null
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>continue</code> statement node.</p>
<h5 id="withStatement(obj.2C_body.5B.2C_loc.5D)"><code>withStatement(obj, body[, loc])</code></h5>
<pre>
obj:&nbsp;CustomExpression
body:&nbsp;CustomStatement
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>with</code> statement node.</p>
<h5 id="returnStatement(arg.5B.2C_loc.5D)"><code>returnStatement(arg[, loc])</code></h5>
<pre>
arg:&nbsp;CustomExpression |&nbsp;null
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>return</code> statement node.</p>
<h5 id="tryStatement(body.2C_handlers.2C_fin.5B.2C_loc.5D)"><code>tryStatement(body, handlers, fin[, loc])</code></h5>
<pre>
body:&nbsp;CustomStatement
handlers:&nbsp;[ CustomCatchClause ]
fin:&nbsp;CustomStatement |&nbsp;null
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>try</code> statement node.</p>
<h5 id="throwStatement(arg.5B.2C_loc.5D)"><code>throwStatement(arg[, loc])</code></h5>
<pre>
arg:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>throw</code> statement node.</p>
<h5 id="debuggerStatement(.5Bloc.5D)"><code>debuggerStatement([loc])</code></h5>
<pre>
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>debugger</code> statement node.</p>
<h5 id="letStatement(head.2C_body.5B.2C_loc.5D)"><code>letStatement(head, body[, loc])</code></h5>
<pre>
head:&nbsp;[ CustomDeclarator ]
body:&nbsp;CustomStatement
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>let</code> statement node.</p>
<h3 id=".E5.A3.B0.E6.98.8E">声明</h3>
<h5 id="functionDeclaration(name.2C_args.2C_body.2C_isGenerator.2C_isExpression.5B.2C_loc.5D)"><code>functionDeclaration(name, args, body, isGenerator, isExpression[, loc])</code></h5>
<pre>
name:&nbsp;string
args:&nbsp;[ CustomPattern ]
body:&nbsp;CustomStatement |&nbsp;CustomExpression
isGenerator:&nbsp;boolean
isExpression:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomDeclaration</p>
<p>Callback to produce a custom function declaration node.</p>
<h5 id="variableDeclaration(kind.2C_dtors.5B.2C_loc.5D)"><code>variableDeclaration(kind, dtors[, loc])</code></h5>
<pre>
kind:&nbsp;"const"&nbsp;|&nbsp;"let"&nbsp;|&nbsp;"var"
dtors:&nbsp;[ CustomDeclarator ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomDeclaration</p>
<p>Callback to produce a custom variable declaration node.</p>
<h5 id="variableDeclarator(patt.2C_init.5B.2C_loc.5D)"><code>variableDeclarator(patt, init[, loc])</code></h5>
<pre>
patt:&nbsp;CustomPattern
init:&nbsp;CustomExpression |&nbsp;null
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomDeclarator</p>
<p>Callback to produce a custom variable declarator node.</p>
<h3 id=".E8.A1.A8.E8.BE.BE.E5.BC.8F">表达式</h3>
<h5 id="sequenceExpression(exprs.5B.2C_loc.5D)"><code>sequenceExpression(exprs[, loc])</code></h5>
<pre>
exprs:&nbsp;[ CustomExpression ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom sequence expression node.</p>
<h5 id="conditionalExpression(test.2C_cons.2C_alt.5B.2C_loc.5D)"><code>conditionalExpression(test, cons, alt[, loc])</code></h5>
<pre>
test:&nbsp;CustomExpression
cons:&nbsp;CustomExpression
alt:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom conditional expression node.</p>
<h5 id="unaryExpression(op.2C_arg.2C_isPrefix.5B.2C_loc.5D)"><code>unaryExpression(op, arg, isPrefix[, loc])</code></h5>
<pre>
op:&nbsp;UnaryOperator
arg:&nbsp;CustomExpression
isPrefix:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom unary expression node.</p>
<h5 id="binaryExpression(op.2C_left.2C_right.5B.2C_loc.5D)"><code>binaryExpression(op, left, right[, loc])</code></h5>
<pre>
op:&nbsp;BinaryOperator
left:&nbsp;CustomExpression
right:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom binary expression node.</p>
<h5 id="assignmentExpression(op.2C_left.2C_right.5B.2C_loc.5D)"><code>assignmentExpression(op, left, right[, loc])</code></h5>
<pre>
op:&nbsp;AssignmentOperator
left:&nbsp;CustomExpression
right:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom assignment expression node.</p>
<h5 id="logicalExpression(op.2C_left.2C_right.5B.2C_loc.5D)"><code>logicalExpression(op, left, right[, loc])</code></h5>
<pre>
op:&nbsp;LogicalOperator
left:&nbsp;CustomExpression
right:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom logical expression node.</p>
<h5 id="updateExpression(op.2C_arg.2C_isPrefix.5B.2C_loc.5D)"><code>updateExpression(op, arg, isPrefix[, loc])</code></h5>
<pre>
op:&nbsp;UpdateOperator
arg:&nbsp;CustomExpression
isPrefix:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom update expression node.</p>
<h5 id="newExpression(callee.2C_args.5B.2C_loc.5D)"><code>newExpression(callee, args[, loc])</code></h5>
<pre>
callee:&nbsp;CustomExpression
args:&nbsp;[ CustomExpression ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>new</code>-expression node.</p>
<h5 id="callExpression(callee.2C_args.5B.2C_loc.5D)"><code>callExpression(callee, args[, loc])</code></h5>
<pre>
callee:&nbsp;CustomExpression
args:&nbsp;[ CustomExpression ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom function call node.</p>
<h5 id="memberExpression(obj.2C_prop.2C_isComputed.5B.2C_loc.5D)"><code>memberExpression(obj, prop, isComputed[, loc])</code></h5>
<pre>
obj:&nbsp;CustomExpression
prop:&nbsp;CustomIdentifier |&nbsp;CustomExpression
isComputed:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom member expression node.</p>
<h5 id="functionExpression(name.2C_args.2C_body.2C_isGenerator.2C_isExpression.5B.2C_loc.5D)"><code>functionExpression(name, args, body, isGenerator, isExpression[, loc])</code></h5>
<pre>
name:&nbsp;CustomIdentifier |&nbsp;null
args:&nbsp;[ CustomPattern ]
body:&nbsp;CustomStatement |&nbsp;CustomExpression
isGenerator:&nbsp;boolean
isExpression:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom function expression node.</p>
<h5 id="arrayExpression(elts.5B.2C_loc.5D)"><code>arrayExpression(elts[, loc])</code></h5>
<pre>
elts:&nbsp;[ CustomExpression |&nbsp;null ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom array expression node.</p>
<h5 id="objectExpression(props.5B.2C_loc.5D)"><code>objectExpression(props[, loc])</code></h5>
<pre>
props:&nbsp;[ CustomObjectProperty ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom object expression node.</p>
<h5 id="thisExpression(.5Bloc.5D)"><code>thisExpression([loc])</code></h5>
<pre>
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>this</code> expression node.</p>
<h5 id="graphExpression(index.2C_expr.5B.2C_loc.5D)"><code>graphExpression(index, expr[, loc])</code></h5>
<pre>
index:&nbsp;uint32 &gt;= 1
expr:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>graph</code> expression node.</p>
<h5 id="graphIndexExpression(index.5B.2C_loc.5D)"><code>graphIndexExpression(index[, loc])</code></h5>
<pre>
index:&nbsp;uint32 &gt;= 1
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>graph index</code> expression node.</p>
<h5 id="comprehensionExpression(body.2C_blocks.2C_filter.5B.2C_loc.5D)"><code>comprehensionExpression(body, blocks, filter[, loc])</code></h5>
<pre>
body:&nbsp;CustomExpression
blocks:&nbsp;[ CustomComprehensionBlock ]
filter:&nbsp;CustomExpression |&nbsp;null
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>comprehension</code> expression node.</p>
<h5 id="generatorExpression(body.2C_blocks.2C_filter.5B.2C_loc.5D)"><code>generatorExpression(body, blocks, filter[, loc])</code></h5>
<pre>
body:&nbsp;CustomExpression
blocks:&nbsp;[ CustomComprehensionBlock ]
filter:&nbsp;CustomExpression |&nbsp;null
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>generator</code> expression node.</p>
<h5 id="yieldExpression(arg.5B.2C_loc.5D)"><code>yieldExpression(arg[, loc])</code></h5>
<pre>
arg:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>yield</code> expression node.</p>
<h5 id="letExpression(head.2C_body.5B.2C_loc.5D)"><code>letExpression(head, body[, loc])</code></h5>
<pre>
head:&nbsp;[ CustomDeclarator ]
body:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>let</code> expression node.</p>
<h3 id="Patterns">Patterns</h3>
<h5 id="arrayPattern(elts.5B.2C_loc.5D)"><code>arrayPattern(elts[, loc])</code></h5>
<pre>
elts:&nbsp;[ CustomPattern |&nbsp;null ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomPattern</p>
<p>Callback to produce a custom array destructuring pattern node.</p>
<h5 id="objectPattern(props.5B.2C_loc.5D)"><code>objectPattern(props[, loc])</code></h5>
<pre>
props:&nbsp;[ CustomPropertyPattern ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomPattern</p>
<p>Callback to produce a custom object destructuring pattern node.</p>
<h5 id="propertyPattern(key.2C_patt.5B.2C_loc.5D)"><code>propertyPattern(key, patt[, loc])</code></h5>
<pre>
key:&nbsp;CustomLiteral |&nbsp;CustomIdentifier
patt:&nbsp;CustomPattern
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomPropertyPattern</p>
<p>Callback to produce a custom object property destructuring pattern node.</p>
<h3 id="Clauses">Clauses</h3>
<h5 id="switchCase(test.2C_cons.5B.2C_loc.5D)"><code>switchCase(test, cons[, loc])</code></h5>
<pre>
test:&nbsp;CustomExpression |&nbsp;null
cons:&nbsp;[ CustomStatement ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomSwitchCase</p>
<p>Callback to produce a custom <code>case</code> or <code>default</code> clause node. The <strong><code>test</code></strong> argument is <code>null</code> if and only if the node is a <code>default</code> clause.</p>
<h5 id="catchClause(arg.2C_guard.2C_body.5B.2C_loc.5D)"><code>catchClause(arg, guard, body[, loc])</code></h5>
<pre>
arg:&nbsp;CustomPattern
guard:&nbsp;CustomExpression
body:&nbsp;CustomStatement
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomCatchClause</p>
<p>Callback to produce a custom <code>catch</code> clause node.</p>
<h5 id="comprehensionBlock(left.2C_right.2C_isForEach.5B.2C_loc.5D)"><code>comprehensionBlock(left, right, isForEach[, loc])</code></h5>
<pre>
left:&nbsp;CustomPattern
right:&nbsp;CustomExpression
isForEach:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomComprehensionBlock</p>
<p>Callback to produce a custom comprehension block node. The <strong><code>isForEach</code></strong> flag indicates whether the node is a <code>for each</code> block.</p>
<h3 id="Miscellaneous">Miscellaneous</h3>
<h5 id="identifier(name.5B.2C_loc.5D)"><code>identifier(name[, loc])</code></h5>
<pre>
name:&nbsp;string
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomIdentifier/CustomPattern/CustomExpression</p>
<p>Callback to produce a custom identifier node.</p>
<h5 id="literal(val.5B.2C_loc.5D)"><code>literal(val[, loc])</code></h5>
<pre>
val:&nbsp;string | boolean |&nbsp;null |&nbsp;number |&nbsp;RegExp
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomLiteral / CustomExpression</p>
<p>Callback to produce a custom literal node.</p>
<h5 id="property(kind.2C_key.2C_val.5B.2C_loc.5D)"><code>property(kind, key, val[, loc])</code></h5>
<pre>
kind:&nbsp;"init"&nbsp;|&nbsp;"get"&nbsp;|&nbsp;"set"
key:&nbsp;CustomLiteral |&nbsp;CustomIdentifier
val:&nbsp;CustomExpression
loc:&nbsp;SourceLocation 
</pre>
<p><strong>返回:</strong> CustomObjectProperty</p>
<p>Callback to produce a custom object property initializer node.</p>
<h3 id="E4X">E4X</h3>
<h4 id="Declarations">Declarations</h4>
<h5 id="xmlDefaultDeclaration(ns.5B.2C_loc.5D)"><code>xmlDefaultDeclaration(ns[, loc])</code></h5>
<pre>
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomDeclaration</p>
<p>Callback to produce a custom XML&nbsp;default namespace declaration node.</p>
<h4 id="Expressions">Expressions</h4>
<h5 id="xmlAnyName(.5Bloc.5D)"><code>xmlAnyName([loc])</code></h5>
<pre>
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXMLAnyName/CustomXML/CustomExpression</p>
<p>Callback to produce a custom XML node for the wildcard pseudo-identifier <code>*</code>.</p>
<h5 id="xmlAttributeSelector(expr.5B.2C_loc.5D)"><code>xmlAttributeSelector(expr[, loc])</code></h5>
<pre>
expr:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML/CustomExpression</p>
<p>Callback to produce a custom XML&nbsp;attribute selector node.</p>
<h5 id="xmlFilterExpression(left.2C_right.5B.2C_loc.5D)"><code>xmlFilterExpression(left, right[, loc])</code></h5>
<pre>
left:&nbsp;CustomExpression
right:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML/CustomExpression</p>
<p>Callback to produce a custom XML&nbsp;filter expression node.</p>
<h5 id="xmlQualifiedIdentifier(left.2C_right.2C_isComputed.5B.2C_loc.5D)"><code>xmlQualifiedIdentifier(left, right, isComputed[, loc])</code></h5>
<pre>
left:&nbsp;CustomIdentifier |&nbsp;CustomXMLAnyName
right:&nbsp;CustomIdentifier |&nbsp;CustomExpression
isComputed:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML/CustomExpression</p>
<p>Callback to produce a custom qualified identifier node.</p>
<h5 id="xmlFunctionQualifiedIdentifier(right.2C_isComputed.5B.2C_loc.5D)"><code>xmlFunctionQualifiedIdentifier(right, isComputed[, loc])</code></h5>
<pre>
right:&nbsp;CustomIdentifier |&nbsp;CustomExpression
isComputed:&nbsp;boolean
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML/CustomExpression</p>
<p>Callback to produce a custom XML&nbsp;<code>function</code>-qualified identifier node.</p>
<h5 id="xmlElement(contents.5B.2C_loc.5D)"><code>xmlElement(contents[, loc])</code></h5>
<pre>
contents:&nbsp;[ CustomXML&nbsp;]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML&nbsp;/ CustomExpression</p>
<p>Callback to produce a custom XML&nbsp;element node.</p>
<h5 id="xmlList(contents.5B.2C_loc.5D)"><code>xmlList(contents[, loc])</code></h5>
<pre>
contents:&nbsp;[ CustomXML&nbsp;]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML/CustomExpression</p>
<p>Callback to produce a custom XML&nbsp;list node.</p>
<h4 id="XML">XML</h4>
<h5 id="xmlEscape(expr.5B.2C_loc.5D)"><code>xmlEscape(expr[, loc])</code></h5>
<pre>
expr:&nbsp;CustomExpression
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;escape node.</p>
<h5 id="xmlText(text.5B.2C_loc.5D)"><code>xmlText(text[, loc])</code></h5>
<pre>
text:&nbsp;string
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;text node.</p>
<h5 id="xmlStartTag(contents.5B.2C_loc.5D)"><code>xmlStartTag(contents[, loc])</code></h5>
<pre>
contents:&nbsp;[ CustomXML&nbsp;]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;start-tag node.</p>
<h5 id="xmlEndTag(contents.5B.2C_loc.5D)"><code>xmlEndTag(contents[, loc])</code></h5>
<pre>
contents:&nbsp;[ CustomXML&nbsp;]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;end-tag node.</p>
<h5 id="xmlPointTag(contents.5B.2C_loc.5D)"><code>xmlPointTag(contents[, loc])</code></h5>
<pre>
contents:&nbsp;[ CustomXML&nbsp;]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;point tag node.</p>
<h5 id="xmlName(contents.5B.2C_loc.5D)"><code>xmlName(contents[, loc])</code></h5>
<pre>
contents:&nbsp;string |&nbsp;[ CustomXML ]
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;name node.</p>
<h5 id="xmlAttribute(value.5B.2C_loc.5D)"><code>xmlAttribute(value[, loc])</code></h5>
<pre>
value:&nbsp;string
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;attribute node.</p>
<h5 id="xmlCdata(contents.5B.2C_loc.5D)"><code>xmlCdata(contents[, loc])</code></h5>
<pre>
contents:&nbsp;string
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;<code>CDATA</code> node.</p>
<h5 id="xmlComment(contents.5B.2C_loc.5D)"><code>xmlComment(contents[, loc])</code></h5>
<pre>
contents:&nbsp;string
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;comment node.</p>
<h5 id="xmlProcessingInstruction(target.2C_contents.5B.2C_loc.5D)"><code>xmlProcessingInstruction(target, contents[, loc])</code></h5>
<pre>
target:&nbsp;string
contents:&nbsp;string |&nbsp;null
loc:&nbsp;SourceLocation
</pre>
<p><strong>返回:</strong> CustomXML</p>
<p>Callback to produce a custom XML&nbsp;processing instruction node.</p>
恢复到这个版本