Parser API

  • Revision slug: SpiderMonkey/Parser_API
  • Revision title: Parser API
  • Revision id: 36053
  • Created:
  • Creator: berkerpeksag
  • Is current revision? No
  • Comment 2 words added, 2 words removed

Revision Content

{{ gecko_minversion_header("7.0") }}

Recent builds of the standalone SpiderMonkey shell include a reflection of the SpiderMonkey parser, made available as a JavaScript API. This makes it easier to write tools in JavaScript that manipulate JavaScript source programs, such as syntax highlighters, static analyses, translators, compilers, obfuscators, etc.

Example:

> 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})

It is also available since Firefox 7; it can be imported into the global object via:

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

or into a specified object via:

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

Built-in objects

Whether in SpiderMonkey shell or Firefox (after importing), the global singleton object Reflect currently contains just the parse method.

Properties of the Reflect object

The Reflect object currently consists of a single method.

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
When loc is true, the parser includes source location information in the returned AST nodes.
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
The initial line number to use for source location information.
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.

Node objects

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";
    elements: [ Statement ];
}

A complete program source tree.

Functions

interface Function <: Node {
    id: Identifier | null;
    params: [ Pattern ];
    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.

Note: Expression closures are SpiderMonkey-specific.

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).

Note: Generators are SpiderMonkey-specific.

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

Statements

interface Statement <: Node { }

Any statement.

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

An empty statement, i.e., a solitary semicolon.

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

A block statement, i.e., a sequence of statements surrounded by braces.

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

An expression statement, i.e., a statement consisting of a single expression.

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

An if statement.

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

A labeled statement, i.e., a statement prefixed by a break/continue label.

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

A break statement.

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

continue statement.

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

with statement.

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

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

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

A return statement.

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

A throw statement.

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

A try statement.

Note: Multiple catch clauses are SpiderMonkey-specific.
interface WhileStatement <: Statement {
    type: "WhileStatement";
    test: Expression;
    body: Statement;
}

A while statement.

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

A do/while statement.

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

A for statement.

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

A for/in statement, or, if each is true, a for each/in statement.

Note: The for each form is SpiderMonkey-specific.
interface LetStatement <: Statement {
    type: "LetStatement";
    head: [ { id: Pattern, init: Expression | null } ];
    body: Statement;
}

let statement.

Note: The let statement form is SpiderMonkey-specific.
interface DebuggerStatement <: Statement {
    type: "DebuggerStatement";
}

A debugger statement.

Note: The debugger statement is new in ECMAScript 5th edition, although SpiderMonkey has supported it for years.

Declarations

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.

Note: Declarations in arbitrary nested scopes are SpiderMonkey-specific.
interface FunctionDeclaration <: Function, Declaration {
    type: "FunctionDeclaration";
    id: Identifier;
    params: [ Pattern ];
    body: BlockStatement | Expression;
    meta: { thunk: boolean,
            closed: boolean,
            generator: boolean,
            expression: boolean };
}

A function declaration.

Note: The id field cannot be null.
interface VariableDeclaration <: Declaration {
    type: "VariableDeclaration";
    declarations: [ VariableDeclarator ];
    kind: "var" | "let" | "const";
}

A variable declaration, via one of var, let, or const.

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

A variable declarator.

Note: The id field cannot be null.
Note: let and const are SpiderMonkey-specific.

Expressions

interface Expression <: Node, Pattern { }

Any expression node. Since the left-hand side of an assignment may be any expression in general, an expression can also be a pattern.

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

this expression.

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

An array expression.

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

An object expression. A literal property in an object expression can have either a string or number as its value. Ordinary property initializers have a kind value "init"; getters and setters have the kind values "get" and "set", respectively.

interface FunctionExpression <: Function, Expression {
    type: "FunctionExpression";
    id: Identifier | null;
    params: [ Pattern ];
    body: BlockStatement | Expression;
    meta: { thunk: boolean,
            closed: boolean,
            generator: boolean,
            expression: boolean };
}

A function expression.

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

A sequence expression, i.e., a comma-separated sequence of expressions.

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;
}

A binary operator 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;
}

A logical operator expression.

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

A conditional expression, i.e., a ternary ?/: expression.

interface NewExpression <: Expression {
    type: "NewExpression";
    constructor: 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;
}

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

interface YieldExpression <: Expression {
    argument: Expression | null;
}

yield expression.

Note: yield expressions are SpiderMonkey-specific.
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.

Note: Array comprehensions are SpiderMonkey-specific.
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.

Note: Generator expressions are SpiderMonkey-specific.
interface GraphExpression <: Expression {
    index: uint32;
    expression: Literal;
}

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

Note: Graph expressions are SpiderMonkey-specific.
interface GraphIndexExpression <: Expression {
    index: uint32;
}

graph index expression, aka "sharp variable," such as #1#.

Note: Graph index expressions are SpiderMonkey-specific.
interface LetExpression <: Expression {
    type: "LetExpression";
    head: [ { id: Pattern, init: Expression | null } ];
    body: Expression;
}

let expression.

Note: The let expression form is SpiderMonkey-specific.

Patterns

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: [ Identifier | Pattern | null ];
}

An array-destructuring pattern.

Clauses

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

A case (if test is an Expression) or default (if test === null) clause in the body of a switch statement.

interface 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.

Note: 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.

Note: Array comprehensions and generator expressions are SpiderMonkey-specific.

Miscellaneous

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.

interface UnaryOperator <: Node {
    type: "UnaryOperator";
    token: "-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
}

A unary operator token.

interface BinaryOperator <: Node {
    type: "BinaryOperator";
    token: "==" | "!=" | "===" | "!=="
            | "<" | "<=" | ">" | ">="
            | "<<" | ">>" | ">>>"
            | "+" | "-" | "*" | "/" | "%"
            | "|" | "^" | "^"
            | "in" | "instanceof"
            | "..";
}

A binary operator token.

Note: The .. operator is E4X-specific.
nterface LogicalOperator <: Node {
    type: "LogicalOperator";
    token: "||" | "&&";
}

A logical operator token.

interface AssignmentOperator <: Node {
    type: "AssignmentOperator";
    token: "=" | "+=" | "-=" | "*=" | "/=" | "%="
            | "<<=" | ">>=" | ">>>="
            | "|=" | "^=" | "&=";
}

An assignment operator token.

interface UpdateOperator <: Node {
    type: "UpdateOperator";
    token: "++" | "--";
}

An update (increment or decrement) operator token.

E4X

This section describes node types that are provided for E4X support.

Note: E4X is not part of the ECMAScript standard (ECMA-262), but is a separate standard of its own (ECMA-357).

Declarations

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

A default xml namespace declaration.

Expressions

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.

Note: function-qualified identifiers are SpiderMonkey-specific.
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.

Note: 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

Returns: CustomProgram

Callback to produce a custom program node.

Statements

emptyStatement([loc])
loc: SourceLocation

Returns: CustomStatement

Callback to produce a custom empty statement node.

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

Returns: CustomStatement

Callback to produce a custom block statement node.

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

Returns: CustomStatement

Callback to produce a custom expression statement node.

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

Returns: CustomStatement

Callback to produce a custom labeled statement node.

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

Returns: CustomStatement

Callback to produce a custom if statement node.

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

Returns: CustomStatement

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

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

Returns: CustomStatement

Callback to produce a custom while statement node.

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

Returns: 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

Returns: 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

Returns: 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

Returns: CustomStatement

Callback to produce a custom break statement node.

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

Returns: CustomStatement

Callback to produce a custom continue statement node.

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

Returns: CustomStatement

Callback to produce a custom with statement node.

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

Returns: CustomStatement

Callback to produce a custom return statement node.

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

Returns: CustomStatement

Callback to produce a custom try statement node.

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

Returns: CustomStatement

Callback to produce a custom throw statement node.

debuggerStatement([loc])
loc: SourceLocation

Returns: CustomStatement

Callback to produce a custom debugger statement node.

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

Returns: CustomStatement

Callback to produce a custom let statement node.

Declarations

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

Returns: CustomDeclaration

Callback to produce a custom function declaration node.

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

Returns: CustomDeclaration

Callback to produce a custom variable declaration node.

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

Returns: CustomDeclarator

Callback to produce a custom variable declarator node.

Expressions

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

Returns: CustomExpression

Callback to produce a custom sequence expression node.

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

Returns: CustomExpression

Callback to produce a custom conditional expression node.

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

Returns: CustomExpression

Callback to produce a custom unary expression node.

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

Returns: CustomExpression

Callback to produce a custom binary expression node.

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

Returns: CustomExpression

Callback to produce a custom assignment expression node.

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

Returns: CustomExpression

Callback to produce a custom logical expression node.

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

Returns: CustomExpression

Callback to produce a custom update expression node.

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

Returns: CustomExpression

Callback to produce a custom new-expression node.

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

Returns: CustomExpression

Callback to produce a custom function call node.

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

Returns: 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

Returns: CustomExpression

Callback to produce a custom function expression node.

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

Returns: CustomExpression

Callback to produce a custom array expression node.

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

Returns: CustomExpression

Callback to produce a custom object expression node.

thisExpression([loc])
loc: SourceLocation

Returns: CustomExpression

Callback to produce a custom this expression node.

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

Returns: CustomExpression

Callback to produce a custom graph expression node.

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

Returns: CustomExpression

Callback to produce a custom graph index expression node.

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

Returns: CustomExpression

Callback to produce a custom comprehension expression node.

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

Returns: CustomExpression

Callback to produce a custom generator expression node.

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

Returns: CustomExpression

Callback to produce a custom yield expression node.

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

Returns: CustomExpression

Callback to produce a custom let expression node.

Patterns

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

Returns: CustomPattern

Callback to produce a custom array destructuring pattern node.

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

Returns: CustomPattern

Callback to produce a custom object destructuring pattern node.

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

Returns: CustomPropertyPattern

Callback to produce a custom object property destructuring pattern node.

Clauses

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

Returns: 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

Returns: CustomCatchClause

Callback to produce a custom catch clause node.

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

Returns: 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

Returns: CustomIdentifier / CustomPattern / CustomExpression

Callback to produce a custom identifier node.

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

Returns: 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 

Returns: CustomObjectProperty

Callback to produce a custom object property initializer node.

E4X

Declarations

xmlDefaultDeclaration(ns[, loc])
loc: SourceLocation

Returns: CustomDeclaration

Callback to produce a custom XML default namespace declaration node.

Expressions

xmlAnyName([loc])
loc: SourceLocation

Returns: CustomXMLAnyName / CustomXML / CustomExpression

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

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

Returns: CustomXML / CustomExpression

Callback to produce a custom XML attribute selector node.

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

Returns: 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

Returns: CustomXML / CustomExpression

Callback to produce a custom qualified identifier node.

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

Returns: CustomXML / CustomExpression

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

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

Returns: CustomXML / CustomExpression

Callback to produce a custom XML element node.

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

Returns: CustomXML / CustomExpression

Callback to produce a custom XML list node.

XML

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

Returns: CustomXML

Callback to produce a custom XML escape node.

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

Returns: CustomXML

Callback to produce a custom XML text node.

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

Returns: CustomXML

Callback to produce a custom XML start-tag node.

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

Returns: CustomXML

Callback to produce a custom XML end-tag node.

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

Returns: CustomXML

Callback to produce a custom XML point tag node.

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

Returns: CustomXML

Callback to produce a custom XML name node.

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

Returns: CustomXML

Callback to produce a custom XML attribute node.

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

Returns: CustomXML

Callback to produce a custom XML CDATA node.

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

Returns: CustomXML

Callback to produce a custom XML comment node.

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

Returns: CustomXML

Callback to produce a custom XML processing instruction node.

Revision Source

<p>{{ gecko_minversion_header("7.0") }}</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. This makes it easier to write tools in JavaScript that manipulate JavaScript source programs, such as syntax highlighters, static analyses, translators, compilers, obfuscators, etc.</p>
<p>Example:</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>It is also available since Firefox 7; it can be imported into the global object via:</p>
<pre>Components.utils.import("resource://gre/modules/reflect.jsm") 
</pre>
<p>or into a specified object via:</p>
<pre>Components.utils.import("resource://gre/modules/reflect.jsm", obj)
</pre>
<h2>Built-in objects</h2>
<p>Whether in SpiderMonkey shell or Firefox (after importing), the global singleton object <code>Reflect</code> currently contains just the <code>parse</code> method.</p>
<h2>Properties of the <code>Reflect</code> object</h2>
<p>The <code>Reflect</code> object currently consists of a single method.</p>
<h4><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-color: rgb(237, 242, 247); border-style: solid; border-width: 1px;"> <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: <span style="font-family: Courier New;">true</span></td> </tr> <tr> <td colspan="3">When <strong><span style="font-family: Courier New;">loc</span></strong> is <span style="font-family: Courier New;">true</span>, the parser includes source location information in the returned AST nodes.</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: <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 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: <span style="font-family: Courier New;">1</span></td> </tr> <tr> <td colspan="3">The initial line number to use for source location information.</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: <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 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>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:<br> </p>
<pre>interface Node {
    type: string;
    loc: SourceLocation | null;
}
</pre>
<p>The <code>type</code> field is a string representing the AST 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: string | null;
    start: Position;
    end: Position;
} 
</pre>
<p>Each <code>Position</code> object consists of a <code>line</code> number (1-indexed) and a <code>column</code> number (0-indexed):</p>
<pre>interface Position {
    line: uint32 &gt;= 1;
    column: uint32 &gt;= 0;
}</pre>
<h3>Programs</h3>
<pre>interface Program &lt;: Node {
    type: "Program";
    elements: [ Statement ];
}
</pre>
<p>A complete program source tree.</p>
<h3>Functions</h3>
<pre>interface Function &lt;: Node {
    id: Identifier | null;
    params: [ Pattern ];
    body: BlockStatement | Expression;
    generator: boolean;
    expression: 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>Note:</strong> Expression closures are SpiderMonkey-specific.</div>
<p>If the <span style="font-family: monospace;">ge</span><code>nerator</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>Note:</strong> Generators are SpiderMonkey-specific.</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>Statements</h3>
<pre>interface Statement &lt;: Node { }
</pre>
<p>Any statement.</p>
<pre>interface EmptyStatement &lt;: Statement {
    type: "EmptyStatement";
}
</pre>
<p>An empty statement, i.e., a solitary semicolon.</p>
<pre>interface BlockStatement &lt;: Statement {
    type: "BlockStatement";
    body: [ Statement ];
}
</pre>
<p>A block statement, i.e., a sequence of statements surrounded by braces.</p>
<pre>interface ExpressionStatement &lt;: Statement {
    type: "ExpressionStatement";
    expression: Expression;
}
</pre>
<p>An expression statement, i.e., a statement consisting of a single expression.</p>
<pre>interface IfStatement &lt;: Statement {
    type: "IfStatement";
    test: Expression;
    consequent: Statement;
    alternate: Statement | null;
}
</pre>
<p>An <code>if</code> statement.</p>
<pre>interface LabeledStatement &lt;: Statement {
    type: "LabeledStatement";
    label: Identifier;
    body: Statement;
}
</pre>
<p>A labeled statement, i.e., a statement prefixed by a <code>break</code>/<code>continue</code> label.</p>
<pre>interface BreakStatement &lt;: Statement {
    type: "BreakStatement";
    label: Identifier | null;
}
</pre>
<p>A <code>break</code> statement.</p>
<pre>interface ContinueStatement &lt;: Statement {
    type: "ContinueStatement";
    label: Identifier | null;
}
</pre>
<p>A <code>continue</code> statement.</p>
<pre>interface WithStatement &lt;: Statement {
    type: "WithStatement";
    object: Expression;
    body: Statement;
}
</pre>
<p>A <code>with</code> statement.</p>
<pre>interface SwitchStatement &lt;: Statement {
    type: "SwitchStatement";
    discriminant: Expression;
    cases: [ SwitchCase ];
    lexical: boolean;
}
</pre>
<p>A <code>switch</code> statement. 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: "ReturnStatement";
    argument: Expression | null;
}
</pre>
<p>A <code>return</code> statement.</p>
<pre>interface ThrowStatement &lt;: Statement {
    type: "ThrowStatement";
    argument: Expression;
}
</pre>
<p>A <code>throw</code> statement.</p>
<pre>interface TryStatement &lt;: Statement {
    type: "TryStatement";
    block: BlockStatement;
    handlers: [ CatchClause ];
    finalizer: BlockStatement | null;
}
</pre>
<p>A <code>try</code> statement.</p>
<div class="note"><strong>Note:</strong> Multiple <code>catch</code> clauses are SpiderMonkey-specific.</div>
<pre>interface WhileStatement &lt;: Statement {
    type: "WhileStatement";
    test: Expression;
    body: Statement;
}
</pre>
<p>A <code>while</code> statement.</p>
<pre>interface DoWhileStatement &lt;: Statement {
    type: "DoWhileStatement";
    body: Statement;
    test: Expression;
}
</pre>
<p>A <code>do</code>/<code>while</code> statement.</p>
<pre>interface ForStatement &lt;: Statement {
    type: "ForStatement";
    init: VariableDeclaration | Expression | null;
    test: Expression | null;
    update: Expression | null;
    body: Statement;
}
</pre>
<p>A <code>for</code> statement.</p>
<pre>interface ForInStatement &lt;: Statement {
    type: "ForInStatement";
    left: VariableDeclaration |  Expression;
    right: Expression;
    body: Statement;
    each: boolean;
}
</pre>
<p>A <code>for</code>/<code>in</code> statement, or, if <code>each</code> is <code>true</code>, a <code>for each</code>/<code>in</code> statement.</p>
<div class="note"><strong>Note:</strong> The <code>for each</code> form is SpiderMonkey-specific.</div>
<pre>interface LetStatement &lt;: Statement {
    type: "LetStatement";
    head: [ { id: Pattern, init: Expression | null } ];
    body: Statement;
}
</pre>
<p>A <code>let</code> statement.</p>
<div class="note"><strong>Note:</strong> The <code>let</code> statement form is SpiderMonkey-specific.</div>
<pre>interface DebuggerStatement &lt;: Statement {
    type: "DebuggerStatement";
}
</pre>
<p>A <code>debugger</code> statement.</p>
<div class="note"><strong>Note:</strong> The <code>debugger</code> statement is new in ECMAScript 5th edition, although SpiderMonkey has supported it for years.</div><h3>Declarations</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>Note:</strong> Declarations in arbitrary nested scopes are SpiderMonkey-specific.</div>
<pre>interface FunctionDeclaration &lt;: Function, Declaration {
    type: "FunctionDeclaration";
    id: Identifier;
    params: [ Pattern ];
    body: BlockStatement | Expression;
    meta: { thunk: boolean,
            closed: boolean,
            generator: boolean,
            expression: boolean };
}
</pre>
<p>A function declaration.</p>
<div class="note"><strong>Note:</strong> The <code>id</code> field cannot be <code>null</code>.</div>
<pre>interface VariableDeclaration &lt;: Declaration {
    type: "VariableDeclaration";
    declarations: [ VariableDeclarator ];
    kind: "var" | "let" | "const";
}
</pre>
<p>A variable declaration, via one of <code>var</code>, <code>let</code>, or <code>const</code>.</p>
<pre>interface VariableDeclarator &lt;: Node {
    type: "VariableDeclarator";
    id: Pattern;
    init: Expression | null;
}
</pre>
<p>A variable declarator.</p>
<div class="note"><strong>Note:</strong> The <code>id</code> field cannot be <code>null</code>.</div>
<div class="note"><strong>Note:</strong> <code>let</code> and <code>const</code> are SpiderMonkey-specific.</div><h3>Expressions</h3>
<pre>interface Expression &lt;: Node, Pattern { }</pre>
<p>Any expression node. 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: "ThisExpression";
}
</pre>
<p>A <code>this</code> expression.</p>
<pre>interface ArrayExpression &lt;: Expression {
    type: "ArrayExpression";
    elements: [ Expression | null ];
}</pre>
<p>An array expression.</p>
<pre>interface ObjectExpression &lt;: Expression {
    type: "ObjectExpression";
    properties: [ { key: Literal | Identifier,
                    value: Expression,
                    kind: "init" | "get" | "set" } ];
}</pre>
<p>An object expression. 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> and <code>"set"</code>, respectively.</p>
<pre>interface FunctionExpression &lt;: Function, Expression {
    type: "FunctionExpression";
    id: Identifier | null;
    params: [ Pattern ];
    body: BlockStatement | Expression;
    meta: { thunk: boolean,
            closed: boolean,
            generator: boolean,
            expression: boolean };
}
</pre>
<p>A function expression.</p>
<pre>interface SequenceExpression &lt;: Expression {
    type: "SequenceExpression";
    expressions: [ Expression ];
}</pre>
<p>A sequence expression, i.e., a comma-separated sequence of expressions.</p>
<pre>interface UnaryExpression &lt;: Expression {
    type: "UnaryExpression";
    operator: UnaryOperator;
    prefix: boolean;
    argument: Expression;
}</pre>
<p>A unary operator expression.</p>
<pre>interface BinaryExpression &lt;: Expression {
    type: "BinaryExpression";
    operator: BinaryOperator;
    left: Expression;
    right: Expression;
}</pre>
<p>A binary operator expression.</p>
<pre>interface AssignmentExpression &lt;: Expression {
    type: "AssignmentExpression";
    operator: AssignmentOperator;
    left: Expression;
    right: Expression;
}</pre>
<p>An assignment operator expression.</p>
<pre>interface UpdateExpression &lt;: Expression {
    type: "UpdateExpression";
    operator: UpdateOperator;
    argument: Expression;
    prefix: boolean;
}</pre>
<p>An update (increment or decrement) operator expression.</p>
<pre>interface LogicalExpression &lt;: Expression {
    type: "LogicalExpression";
    operator: LogicalOperator;
    left: Expression;
    right: Expression;
}</pre>
<p>A logical operator expression.</p>
<pre>interface ConditionalExpression &lt;: Expression {
    type: "ConditionalExpression";
    test: Expression;
    alternate: Expression;
    consequent: Expression;
}</pre>
<p>A conditional expression, i.e., a ternary <code>?</code>/<code>:</code> expression.</p>
<pre>interface NewExpression &lt;: Expression {
    type: "NewExpression";
    constructor: Expression;
    arguments: [ Expression ] | null;
}</pre>
<p>A <code>new</code> expression.</p>
<pre>interface CallExpression &lt;: Expression {
    type: "CallExpression";
    callee: Expression;
    arguments: [ Expression ];
}</pre>
<p>A function or method call expression.</p>
<pre>interface MemberExpression &lt;: Expression {
    type: "MemberExpression";
    object: Expression;
    property: Identifier | Expression;
    computed : boolean;
}</pre>
<p>A member expression. 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: Expression | null;
}
</pre>
<p>A <code>yield</code> expression.</p>
<div class="note"><strong>Note:</strong> <code>yield</code> expressions are SpiderMonkey-specific.</div>
<pre>interface ComprehensionExpression &lt;: Expression {
    body: Expression;
    blocks: [ ComprehensionBlock ];
    filter: Expression | 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>Note:</strong> Array comprehensions are SpiderMonkey-specific.</div>
<pre>interface GeneratorExpression &lt;: Expression {
    body: Expression;
    blocks: [ ComprehensionBlock ];
    filter: Expression | 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>Note:</strong> Generator expressions are SpiderMonkey-specific.</div>
<pre>interface GraphExpression &lt;: Expression {
    index: uint32;
    expression: Literal;
}
</pre>
<p>A <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: #1# }</code>.</p>
<div class="note"><strong>Note:</strong> Graph expressions are SpiderMonkey-specific.</div>
<pre>interface GraphIndexExpression &lt;: Expression {
    index: uint32;
}
</pre>
<p>A <a href="/en/JavaScript/Sharp_variables_in_JavaScript" title="https://developer.mozilla.org/en/Sharp_variables_in_JavaScript">graph index expression</a>, aka "sharp variable," such as <code>#1#</code>.</p>
<div class="note"><strong>Note:</strong> Graph index expressions are SpiderMonkey-specific.</div>
<pre>interface LetExpression &lt;: Expression {
    type: "LetExpression";
    head: [ { id: Pattern, init: Expression | null } ];
    body: Expression;
}
</pre>
<p>A <code>let</code> expression.</p>
<div class="note"><strong>Note:</strong> The <code>let</code> expression form is SpiderMonkey-specific.</div><h3>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: [ Identifier | Pattern | null ];
}
</pre>
<p>An array-destructuring pattern.</p>
<h3>Clauses</h3>
<pre>interface SwitchCase &lt;: Node {
    type: "SwitchCase";
    test: Expression | null;
    consequent: [ Statement ];
}
</pre>
<p>A <code>case</code> (if <code>test</code> is an <code>Expression</code>) or <code>default</code> (if <code>test === null</code>) clause in the body of a <code>switch</code> statement.</p>
<pre>interface CatchClause &lt;: Node {
    type: "CatchClause";
    param: Pattern;
    guard: Expression | null;
    body: BlockStatement;
}
</pre>
<p>A <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>Note:</strong> The guard expression is SpiderMonkey-specific.</div>
<pre>interface ComprehensionBlock &lt;: Node {
    left: Pattern;
    right: Expression;
    each: boolean;
}
</pre>
<p>A <code>for</code> or <code>for each</code> block in an array comprehension or generator expression.</p>
<div class="note"><strong>Note:</strong> Array comprehensions and generator expressions are SpiderMonkey-specific.</div><h3>Miscellaneous</h3>
<pre>interface Identifier &lt;: Node, Expression, Pattern {
    type: "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: "Literal";
    value: string | boolean | null | number | RegExp;
}
</pre>
<p>A literal token. Note that a literal can be an expression.</p>
<pre>interface UnaryOperator &lt;: Node {
    type: "UnaryOperator";
    token: "-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
}
</pre>
<p>A unary operator token.</p>
<pre>interface BinaryOperator &lt;: Node {
    type: "BinaryOperator";
    token: "==" | "!=" | "===" | "!=="
            | "&lt;" | "&lt;=" | "&gt;" | "&gt;="
            | "&lt;&lt;" | "&gt;&gt;" | "&gt;&gt;&gt;"
            | "+" | "-" | "*" | "/" | "%"
            | "|" | "^" | "^"
            | "in" | "instanceof"
            | "..";
}
</pre>
<p>A binary operator token.</p>
<div class="note"><strong>Note:</strong> The <code>..</code> operator is E4X-specific.</div>
<pre>nterface LogicalOperator &lt;: Node {
    type: "LogicalOperator";
    token: "||" | "&amp;&amp;";
}
</pre>
<p>A logical operator token.</p>
<pre>interface AssignmentOperator &lt;: Node {
    type: "AssignmentOperator";
    token: "=" | "+=" | "-=" | "*=" | "/=" | "%="
            | "&lt;&lt;=" | "&gt;&gt;=" | "&gt;&gt;&gt;="
            | "|=" | "^=" | "&amp;=";
}
</pre>
<p>An assignment operator token.</p>
<pre>interface UpdateOperator &lt;: Node {
    type: "UpdateOperator";
    token: "++" | "--";
}
</pre>
<p>An update (increment or decrement) operator token.</p><h3>E4X</h3>
<p>This section describes node types that are provided for E4X support.</p>
<div class="note">Note: E4X is not part of the ECMAScript standard (<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>), but is a separate standard of its own (<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>Declarations</h4>
<pre>interface XMLDefaultDeclaration &lt;: Declaration {
    type: "XMLDefaultDeclaration";
    namespace: Expression;
}
</pre>
<p>A <code>default xml namespace</code> declaration.</p>
<h4>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 | XMLAnyName;
    right: Identifier | Expression;
    computed: boolean;
}
</pre>
<p>An E4X 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 identifier qualified by the <code>function</code> keyword, e.g. <code>function::id</code>.</p>
<div class="note">Note: <code>function</code>-qualified identifiers are SpiderMonkey-specific.</div>
<pre>interface XMLAttributeSelector &lt;: Expression {
    type: "XMLAttributeSelector";
    attribute: Expression;
}
</pre>
<p>An E4X 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 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 element.</p>
<pre>interface XMLList &lt;: XML, Expression {
    type: "XMLList";
    contents: [ XML ];
}
</pre>
<p>An E4X literal representing a list of XML elements.</p>
<h4>XML</h4>
<pre>interface XML &lt;: Node { }
</pre>
<p>XML data.</p>
<pre>interface XMLEscape &lt;: XML {
    type "XMLEscape";
    expression: Expression;
}
</pre>
<p>XML data with an escaped JavaScript expression.</p>
<pre>interface XMLText &lt;: XML {
    type: "XMLText";
    text: string;
}
</pre>
<p>Literal XML text.</p>
<pre>interface XMLStartTag &lt;: XML {
    type: "XMLStartTag";
    contents: [ XML ];
}
</pre>
<p>An XML start tag.</p>
<pre>interface XMLEndTag &lt;: XML {
    type: "XMLEndTag";
    contents: [ XML ];
}
</pre>
<p>An XML end tag.</p>
<pre>interface XMLPointTag &lt;: XML {
    type: "XMLPointTag";
    contents: [ XML ];
}
</pre>
<p>An XML point tag.</p>
<pre>interface XMLName &lt;: XML {
    type: "XMLName";
    contents: string | [ XML ];
}
</pre>
<p>An XML name.</p>
<pre>interface XMLAttribute &lt;: XML {
    type: "XMLAttribute";
    value: string;
}
</pre>
<p>An XML attribute value.</p>
<pre>interface XMLCdata &lt;: XML {
    type: "XMLCdata";
    contents: string;
}
</pre>
<p>An XML CDATA node.</p>
<pre>interface XMLComment &lt;: XML {
    type: "XMLComment";
    contents: string;
}
</pre>
<p>An XML comment.</p>
<pre>interface XMLProcessingInstruction &lt;: XML {
    type: "XMLProcessingInstruction";
    target: string;
    contents: string | null;
}
</pre>
<p>An XML processing instruction.</p>
<h2>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 Node 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 CustomExpression, CustomStatement, etc.</p>
<div class="note">Note: 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>Programs</h3>
<h5><code>program(body[, loc])</code></h5>
<pre>body: [ CustomStatement ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomProgram</p>
<p>Callback to produce a custom program node.</p>
<h3>Statements</h3>
<h5><code>emptyStatement([loc])</code></h5>
<pre>loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom empty statement node.</p>
<h5><code>blockStatement(body[, loc])</code></h5>
<pre>body: CustomStatement
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom block statement node.</p>
<h5><code>expressionStatement(expr[, loc])</code></h5>
<pre>expr: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom expression statement node.</p>
<h5><code>labeledStatement(label, body[, loc])</code></h5>
<pre>label: CustomIdentifier
body: CustomStatement
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom labeled statement node.</p>
<h5><code>ifStatement(test, cons, alt[, loc])</code></h5>
<pre>test: CustomExpression
cons: CustomStatement
alt: CustomStatement | null
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>if</code> statement node.</p>
<h5><code>switchStatement(disc, cases, isLexical[, loc])</code></h5>
<pre>disc: CustomExpression
cases: [ CustomSwitchCase ]
isLexical: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</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 un-nested <code>let</code> declarations (and therefore introduces a new lexical scope).</p>
<h5><code>whileStatement(test, body[, loc])</code></h5>
<pre>test: CustomExpression
body: CustomStatement
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>while</code> statement node.</p>
<h5><code>doWhileStatement(body, test[, loc])</code></h5>
<pre>body: CustomStatement
test: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>do</code>-<code>while</code> statement node.</p>
<h5><code>forStatement(init, test, update, body[, loc])</code></h5>
<pre>init: CustomVariableDeclaration | CustomExpression | null
test: CustomExpression | null
update: CustomExpression | null
body: CustomStatement
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>for</code> statement node.</p>
<h5><code>forInStatement(left, right, body, isForEach[, loc])</code></h5>
<pre>left: CustomVariableDeclaration | CustomExpression
right: CustomExpression
body: CustomStatement
isForEach: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</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><code>breakStatement(label[, loc])</code></h5>
<pre>label: CustomIdentifier | null
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>break</code> statement node.</p>
<h5><code>continueStatement(label[, loc])</code></h5>
<pre>label: CustomIdentifier | null
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>continue</code> statement node.</p>
<h5><code>withStatement(obj, body[, loc])</code></h5>
<pre>obj: CustomExpression
body: CustomStatement
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>with</code> statement node.</p>
<h5><code>returnStatement(arg[, loc])</code></h5>
<pre>arg: CustomExpression | null
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>return</code> statement node.</p>
<h5><code>tryStatement(body, handlers, fin[, loc])</code></h5>
<pre>body: CustomStatement
handlers: [ CustomCatchClause ]
fin: CustomStatement | null
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>try</code> statement node.</p>
<h5><code>throwStatement(arg[, loc])</code></h5>
<pre>arg: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>throw</code> statement node.</p>
<h5><code>debuggerStatement([loc])</code></h5>
<pre>loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>debugger</code> statement node.</p>
<h5><code>letStatement(head, body[, loc])</code></h5>
<pre>head: [ CustomDeclarator ]
body: CustomStatement
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomStatement</p>
<p>Callback to produce a custom <code>let</code> statement node.</p>
<h3>Declarations</h3>
<h5><code>functionDeclaration(name, args, body, isGenerator, isExpression[, loc])</code></h5>
<pre>name: string
args: [ CustomPattern ]
body: CustomStatement | CustomExpression
isGenerator: boolean
isExpression: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomDeclaration</p>
<p>Callback to produce a custom function declaration node.</p>
<h5><code>variableDeclaration(kind, dtors[, loc])</code></h5>
<pre>kind: "const" | "let" | "var"
dtors: [ CustomDeclarator ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomDeclaration</p>
<p>Callback to produce a custom variable declaration node.</p>
<h5><code>variableDeclarator(patt, init[, loc])</code></h5>
<pre>patt: CustomPattern
init: CustomExpression | null
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomDeclarator</p>
<p>Callback to produce a custom variable declarator node.</p>
<h3>Expressions</h3>
<h5><code>sequenceExpression(exprs[, loc])</code></h5>
<pre>exprs: [ CustomExpression ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom sequence expression node.</p>
<h5><code>conditionalExpression(test, cons, alt[, loc])</code></h5>
<pre>test: CustomExpression
cons: CustomExpression
alt: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom conditional expression node.</p>
<h5><code>unaryExpression(op, arg, isPrefix[, loc])</code></h5>
<pre>op: UnaryOperator
arg: CustomExpression
isPrefix: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom unary expression node.</p>
<h5><code>binaryExpression(op, left, right[, loc])</code></h5>
<pre>op: BinaryOperator
left: CustomExpression
right: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom binary expression node.</p>
<h5><code>assignmentExpression(op, left, right[, loc])</code></h5>
<pre>op: AssignmentOperator
left: CustomExpression
right: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom assignment expression node.</p>
<h5><code>logicalExpression(op, left, right[, loc])</code></h5>
<pre>op: LogicalOperator
left: CustomExpression
right: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom logical expression node.</p>
<h5><code>updateExpression(op, arg, isPrefix[, loc])</code></h5>
<pre>op: UpdateOperator
arg: CustomExpression
isPrefix: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom update expression node.</p>
<h5><code>newExpression(callee, args[, loc])</code></h5>
<pre>callee: CustomExpression
args: [ CustomExpression ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>new</code>-expression node.</p>
<h5><code>callExpression(callee, args[, loc])</code></h5>
<pre>callee: CustomExpression
args: [ CustomExpression ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom function call node.</p>
<h5><code>memberExpression(obj, prop, isComputed[, loc])</code></h5>
<pre>obj: CustomExpression
prop: CustomIdentifier | CustomExpression
isComputed: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom member expression node.</p>
<h5><code>functionExpression(name, args, body, isGenerator, isExpression[, loc])</code></h5>
<pre>name: CustomIdentifier | null
args: [ CustomPattern ]
body: CustomStatement | CustomExpression
isGenerator: boolean
isExpression: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom function expression node.</p>
<h5><code>arrayExpression(elts[, loc])</code></h5>
<pre>elts: [ CustomExpression | null ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom array expression node.</p>
<h5><code>objectExpression(props[, loc])</code></h5>
<pre>props: [ CustomObjectProperty ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom object expression node.</p>
<h5><code>thisExpression([loc])</code></h5>
<pre>loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>this</code> expression node.</p>
<h5><code>graphExpression(index, expr[, loc])</code></h5>
<pre>index: uint32 &gt;= 1
expr: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom graph expression node.</p>
<h5><code>graphIndexExpression(index[, loc])</code></h5>
<pre>index: uint32 &gt;= 1
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom graph index expression node.</p>
<h5><code>comprehensionExpression(body, blocks, filter[, loc])</code></h5>
<pre>body: CustomExpression
blocks: [ CustomComprehensionBlock ]
filter: CustomExpression | null
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom comprehension expression node.</p>
<h5><code>generatorExpression(body, blocks, filter[, loc])</code></h5>
<pre>body: CustomExpression
blocks: [ CustomComprehensionBlock ]
filter: CustomExpression | null
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom generator expression node.</p>
<h5><code>yieldExpression(arg[, loc])</code></h5>
<pre>arg: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>yield</code> expression node.</p>
<h5><code>letExpression(head, body[, loc])</code></h5>
<pre>head: [ CustomDeclarator ]
body: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomExpression</p>
<p>Callback to produce a custom <code>let</code> expression node.</p>
<h3>Patterns</h3>
<h5><code>arrayPattern(elts[, loc])</code></h5>
<pre>elts: [ CustomPattern | null ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomPattern</p>
<p>Callback to produce a custom array destructuring pattern node.</p>
<h5><code>objectPattern(props[, loc])</code></h5>
<pre>props: [ CustomPropertyPattern ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomPattern</p>
<p>Callback to produce a custom object destructuring pattern node.</p>
<h5><code>propertyPattern(key, patt[, loc])</code></h5>
<pre>key: CustomLiteral | CustomIdentifier
patt: CustomPattern
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomPropertyPattern</p>
<p>Callback to produce a custom object property destructuring pattern node.</p>
<h3>Clauses</h3>
<h5><code>switchCase(test, cons[, loc])</code></h5>
<pre>test: CustomExpression | null
cons: [ CustomStatement ]
loc: SourceLocation
</pre>
<p><strong>Returns:</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><code>catchClause(arg, guard, body[, loc])</code></h5>
<pre>arg: CustomPattern
guard: CustomExpression
body: CustomStatement
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomCatchClause</p>
<p>Callback to produce a custom <code>catch</code> clause node.</p>
<h5><code>comprehensionBlock(left, right, isForEach[, loc])</code></h5>
<pre>left: CustomPattern
right: CustomExpression
isForEach: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</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>Miscellaneous</h3>
<h5><code>identifier(name[, loc])</code></h5>
<pre>name: string
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomIdentifier / CustomPattern / CustomExpression</p>
<p>Callback to produce a custom identifier node.</p>
<h5><code>literal(val[, loc])</code></h5>
<pre>val: string | boolean | null | number | RegExp
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomLiteral / CustomExpression</p>
<p>Callback to produce a custom literal node.</p>
<h5><code>property(kind, key, val[, loc])</code></h5>
<pre>kind: "init" | "get" | "set"
key: CustomLiteral | CustomIdentifier
val: CustomExpression
loc: SourceLocation 
</pre>
<p><strong>Returns:</strong> CustomObjectProperty</p>
<p>Callback to produce a custom object property initializer node.</p>
<h3>E4X</h3>
<h4>Declarations</h4>
<h5><code>xmlDefaultDeclaration(ns[, loc])</code></h5>
<pre>loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomDeclaration</p>
<p>Callback to produce a custom XML default namespace declaration node.</p>
<h4>Expressions</h4>
<h5><code>xmlAnyName([loc])</code></h5>
<pre>loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXMLAnyName / CustomXML / CustomExpression</p>
<p>Callback to produce a custom XML node for the wildcard pseudo-identifier <code>*</code>.</p>
<h5><code>xmlAttributeSelector(expr[, loc])</code></h5>
<pre>expr: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML / CustomExpression</p>
<p>Callback to produce a custom XML attribute selector node.</p>
<h5><code>xmlFilterExpression(left, right[, loc])</code></h5>
<pre>left: CustomExpression
right: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML / CustomExpression</p>
<p>Callback to produce a custom XML filter expression node.</p>
<h5><code>xmlQualifiedIdentifier(left, right, isComputed[, loc])</code></h5>
<pre>left: CustomIdentifier | CustomXMLAnyName
right: CustomIdentifier | CustomExpression
isComputed: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML / CustomExpression</p>
<p>Callback to produce a custom qualified identifier node.</p>
<h5><code>xmlFunctionQualifiedIdentifier(right, isComputed[, loc])</code></h5>
<pre>right: CustomIdentifier | CustomExpression
isComputed: boolean
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML / CustomExpression</p>
<p>Callback to produce a custom XML <code>function</code>-qualified identifier node.</p>
<h5><code>xmlElement(contents[, loc])</code></h5>
<pre>contents: [ CustomXML ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML / CustomExpression</p>
<p>Callback to produce a custom XML element node.</p>
<h5><code>xmlList(contents[, loc])</code></h5>
<pre>contents: [ CustomXML ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML / CustomExpression</p>
<p>Callback to produce a custom XML list node.</p>
<h4>XML</h4>
<h5><code>xmlEscape(expr[, loc])</code></h5>
<pre>expr: CustomExpression
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML escape node.</p>
<h5><code>xmlText(text[, loc])</code></h5>
<pre>text: string
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML text node.</p>
<h5><code>xmlStartTag(contents[, loc])</code></h5>
<pre>contents: [ CustomXML ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML start-tag node.</p>
<h5><code>xmlEndTag(contents[, loc])</code></h5>
<pre>contents: [ CustomXML ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML end-tag node.</p>
<h5><code>xmlPointTag(contents[, loc])</code></h5>
<pre>contents: [ CustomXML ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML point tag node.</p>
<h5><code>xmlName(contents[, loc])</code></h5>
<pre>contents: string | [ CustomXML ]
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML name node.</p>
<h5><code>xmlAttribute(value[, loc])</code></h5>
<pre>value: string
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML attribute node.</p>
<h5><code>xmlCdata(contents[, loc])</code></h5>
<pre>contents: string
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML CDATA node.</p>
<h5><code>xmlComment(contents[, loc])</code></h5>
<pre>contents: string
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML comment node.</p>
<h5><code>xmlProcessingInstruction(target, contents[, loc])</code></h5>
<pre>target: string
contents: string | null
loc: SourceLocation
</pre>
<p><strong>Returns:</strong> CustomXML</p>
<p>Callback to produce a custom XML processing instruction node.</p>
Revert to this revision