Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Parser API

This article covers features introduced in SpiderMonkey 1.8.5

最近构建的独立的SpiderMonkey shell包含了SpiderMonkey解析器的反射,可以通过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.

文档标签和贡献者

 此页面的贡献者: ziyunfei
 最后编辑者: ziyunfei,