BOOLEAN_TO_JSVAL
DOUBLE_TO_JSVAL
INT_FITS_IN_JSVAL
INT_TO_JSVAL
JS::Add*Root
JS::AutoIdArray
JS::AutoSaveExceptionState
JS::AutoValueArray
JS::AutoVectorRooter
JS::BooleanValue
JS::Call
JS::CallArgs
JS::CloneFunctionObject
JS::Compile
JS::CompileFunction
JS::CompileOffThread
JS::CompileOptions
JS::Construct
JS::CreateError
JS::CurrentGlobalOrNull
JS::DeflateStringToUTF8Buffer
JS::DoubleNaNValue
JS::DoubleValue
JS::Evaluate
JS::FalseValue
JS::Float32Value
JS::GetDeflatedUTF8StringLength
JS::GetFirstArgumentAsTypeHint
JS::GetSelfHostedFunction
JS::Handle
JS::HandleValueArray
JS::IdentifyStandardInstance
JS::Int32Value
JS::IsCallable
JS::MutableHandle
JS::NewFunctionFromSpec
JS::NullHandleValue
JS::NullValue
JS::NumberValue
JS::ObjectOrNullValue
JS::ObjectValue
JS::OrdinaryToPrimitive
JS::PersistentRooted
JS::PropertySpecNameEqualsId
JS::PropertySpecNameIsSymbol
JS::PropertySpecNameToPermanentId
JS::ProtoKeyToId
JS::Remove*Root
JS::Rooted
JS::SetLargeAllocationFailureCallback
JS::SetOutOfMemoryCallback
JS::SourceBufferHolder
JS::StringValue
JS::SymbolValue
JS::ToBoolean
JS::ToInt32
JS::ToInt64
JS::ToNumber
JS::ToPrimitive
JS::ToString
JS::ToUint16
JS::ToUint32
JS::ToUint64
JS::TrueHandleValue
JS::TrueValue
JS::UndefinedHandleValue
JS::UndefinedValue
JS::Value
JSAutoByteString
JSAutoCompartment
JSBool
JSCheckAccessOp
JSClass
JSClass.call
JSClass.flags
JSConstDoubleSpec
JSConvertOp
JSDeletePropertyOp
JSEnumerateOp
JSErrorFormatString
JSErrorReport
JSExceptionState
JSExnType
JSExtendedClass
JSExtendedClass.outerObject
JSExtendedClass.wrappedObject
JSFUN_BOUND_METHOD
JSFUN_GLOBAL_PARENT
JSFastNative
JSFinalizeOp
JSFreeOp
JSFunction
JSFunctionSpec
JSGetObjectOps
JSHasInstanceOp
JSID_EMPTY
JSID_IS_EMPTY
JSID_IS_GCTHING
JSID_IS_INT
JSID_IS_STRING
JSID_IS_SYMBOL
JSID_IS_VOID
JSID_IS_ZERO
JSID_VOID
JSIdArray
JSIteratorOp
JSMarkOp
JSNative
JSNewEnumerateOp
JSNewResolveOp
JSObject
JSObjectOp
JSObjectOps.defaultValue
JSObjectOps.defineProperty
JSObjectOps.destroyObjectMap
JSObjectOps.dropProperty
JSObjectOps.enumerate
JSObjectOps.getAttributes
JSObjectOps.getProperty
JSObjectOps.getRequiredSlot
JSObjectOps.lookupProperty
JSObjectOps.newObjectMap
JSObjectOps.setProto
JSObjectPrincipalsFinder
JSPRINCIPALS_HOLD
JSPrincipals
JSPrincipalsTranscoder
JSProperty
JSPropertyDescriptor
JSPropertyOp
JSPropertySpec
JSProtoKey
JSReserveSlotsOp
JSResolveOp
JSRuntime
JSSecurityCallbacks.contentSecurityPolicyAllows
JSString
JSStringFinalizer
JSTraceOp
JSType
JSVAL_IS_BOOLEAN
JSVAL_IS_DOUBLE
JSVAL_IS_GCTHING
JSVAL_IS_INT
JSVAL_IS_NULL
JSVAL_IS_NUMBER
JSVAL_IS_OBJECT
JSVAL_IS_PRIMITIVE
JSVAL_IS_STRING
JSVAL_IS_VOID
JSVAL_LOCK
JSVAL_NULL
JSVAL_ONE
JSVAL_TO_BOOLEAN
JSVAL_TO_DOUBLE
JSVAL_TO_GCTHING
JSVAL_TO_INT
JSVAL_TO_OBJECT
JSVAL_TO_STRING
JSVAL_TRUE
JSVAL_UNLOCK
JSVAL_VOID
JSVAL_ZERO
JSVersion
JSXDRObjectOp
JS_ASSERT_STRING_IS_FLAT
JS_Add*Root
JS_AddArgumentFormatter
JS_AddExternalStringFinalizer
JS_AddFinalizeCallback
JS_AliasElement
JS_AliasProperty
JS_AlreadyHasOwnProperty
JS_BeginRequest
JS_BindCallable
JS_BufferIsCompilableUnit
JS_CStringsAreUTF8
JS_CallFunction
JS_CheckAccess
JS_CheckForInterrupt
JS_ClearContextThread
JS_ClearDateCaches
JS_ClearNewbornRoots
JS_ClearNonGlobalObject
JS_ClearPendingException
JS_ClearRegExpStatics
JS_ClearScope
JS_CloneFunctionObject
JS_CompareStrings
JS_CompileFileHandleForPrincipals
JS_CompileFileHandleForPrincipalsVersion
JS_CompileFunction
JS_CompileFunctionForPrincipals
JS_CompileScript
JS_CompileScriptForPrincipals
JS_CompileUCFunctionForPrincipalsVersion
JS_CompileUTF8File
JS_CompileUTF8FileHandle
JS_ConcatStrings
JS_ConstructObject
JS_ContextIterator
JS_ConvertArguments
JS_ConvertArgumentsVA
JS_ConvertValue
JS_DecompileFunction
JS_DecompileFunctionBody
JS_DecompileScript
JS_DecompileScriptObject
JS_DeepFreezeObject
JS_DefaultValue
JS_DefineConstDoubles
JS_DefineElement
JS_DefineFunction
JS_DefineFunctions
JS_DefineObject
JS_DefineOwnProperty
JS_DefineProperties
JS_DefineProperty
JS_DefinePropertyWithTinyId
JS_DeleteElement
JS_DeleteElement2
JS_DeleteProperty
JS_DeleteProperty2
JS_DestroyContext
JS_DestroyIdArray
JS_DestroyRuntime
JS_DestroyScript
JS_DoubleIsInt32
JS_DoubleToInt32
JS_DropExceptionState
JS_DumpHeap
JS_DumpNamedRoots
JS_EncodeCharacters
JS_EncodeString
JS_EncodeStringToBuffer
JS_EnterCompartment
JS_EnterCrossCompartmentCall
JS_EnterLocalRootScope
JS_Enumerate
JS_EnumerateDiagnosticMemoryRegions
JS_EnumerateResolvedStandardClasses
JS_EnumerateStandardClasses
JS_ErrorFromException
JS_EvaluateScript
JS_EvaluateScriptForPrincipals
JS_ExecuteRegExp
JS_ExecuteScript
JS_ExecuteScriptPart
JS_ExecuteScriptVersion
JS_FORGET_STRING_FLATNESS
JS_FS
JS_FileEscapedString
JS_Finish
JS_FlattenString
JS_FlushCaches
JS_ForgetLocalRoot
JS_ForwardGetPropertyTo
JS_FreezeObject
JS_GC
JS_GET_CLASS
JS_GetArrayLength
JS_GetArrayPrototype
JS_GetClass
JS_GetClassObject
JS_GetClassPrototype
JS_GetCompartmentPrivate
JS_GetConstructor
JS_GetContextPrivate
JS_GetContextThread
JS_GetDefaultFreeOp
JS_GetElement
JS_GetEmptyString
JS_GetEmptyStringValue
JS_GetErrorPrototype
JS_GetExternalStringClosure
JS_GetExternalStringFinalizer
JS_GetFlatStringChars
JS_GetFunctionArity
JS_GetFunctionCallback
JS_GetFunctionFlags
JS_GetFunctionId
JS_GetFunctionName
JS_GetFunctionObject
JS_GetFunctionPrototype
JS_GetFunctionScript
JS_GetGCParameter
JS_GetGlobalForCompartmentOrNull
JS_GetGlobalForObject
JS_GetGlobalForObject3
JS_GetGlobalForScopeChain
JS_GetGlobalObject
JS_GetImplementationVersion
JS_GetInstancePrivate
JS_GetInternedStringChars
JS_GetLatin1FlatStringChars
JS_GetLatin1InternedStringChars
JS_GetLatin1StringCharsAndLength
JS_GetLocaleCallbacks
JS_GetNaNValue
JS_GetObjectPrototype
JS_GetObjectRuntime
JS_GetOptions
JS_GetOwnPropertyDescriptor
JS_GetParent
JS_GetParentRuntime
JS_GetPendingException
JS_GetPositiveInfinityValue
JS_GetPrivate
JS_GetProperty
JS_GetPropertyAttributes
JS_GetPropertyAttrsGetterAndSetter
JS_GetPropertyDefault
JS_GetPropertyDescriptor
JS_GetPrototype
JS_GetRegExpFlags
JS_GetRegExpSource
JS_GetReservedSlot
JS_GetRuntime
JS_GetRuntimePrivate
JS_GetScopeChain
JS_GetSecurityCallbacks
JS_GetStringBytes
JS_GetStringCharAt
JS_GetStringChars
JS_GetStringCharsAndLength
JS_GetStringEncodingLength
JS_GetStringLength
JS_GetTwoByteExternalStringChars
JS_GetTypeName
JS_GetVersion
JS_HasArrayLength
JS_HasElement
JS_HasInstance
JS_HasOwnProperty
JS_HasProperty
JS_IdArrayGet
JS_IdArrayLength
JS_IdToProtoKey
JS_IdToValue
JS_Init
JS_InitCTypesClass
JS_InitClass
JS_InitStandardClasses
JS_InstanceOf
JS_InternJSString
JS_InternString
JS_IsArrayObject
JS_IsAssigning
JS_IsBuiltinEvalFunction
JS_IsBuiltinFunctionConstructor
JS_IsConstructing
JS_IsConstructing_PossiblyWithGivenThisObject
JS_IsConstructor
JS_IsExceptionPending
JS_IsExtensible
JS_IsExternalString
JS_IsGlobalObject
JS_IsIdentifier
JS_IsNative
JS_IsNativeFunction
JS_IsRunning
JS_IsStopIteration
JS_IterateCompartments
JS_LeaveCompartment
JS_LeaveCrossCompartmentCall
JS_LeaveLocalRootScope
JS_LeaveLocalRootScopeWithResult
JS_LinkConstructorAndPrototype
JS_Lock
JS_LockGCThing
JS_LookupElement
JS_LookupProperty
JS_LooselyEqual
JS_MakeStringImmutable
JS_MapGCRoots
JS_MaybeGC
JS_New
JS_NewArrayObject
JS_NewCompartmentAndGlobalObject
JS_NewContext
JS_NewDateObject
JS_NewDateObjectMsec
JS_NewDependentString
JS_NewDouble
JS_NewDoubleValue
JS_NewExternalString
JS_NewFunction
JS_NewGlobalObject
JS_NewNumberValue
JS_NewObject
JS_NewObjectForConstructor
JS_NewPlainObject
JS_NewPropertyIterator
JS_NewRegExpObject
JS_NewRuntime
JS_NewScriptObject
JS_NewStringCopyN
JS_NewStringCopyZ
JS_NewUCString
JS_NextProperty
JS_Now
JS_NumberValue
JS_ObjectIsDate
JS_ObjectIsFunction
JS_ObjectIsRegExp
JS_PSGS
JS_ParseJSON
JS_PopArguments
JS_PreventExtensions
JS_PropertyStub
JS_PushArguments
JS_PutEscapedString
JS_Remove*Root
JS_RemoveExternalStringFinalizer
JS_RemoveRootRT
JS_ReportError
JS_ReportErrorNumber
JS_ReportOutOfMemory
JS_ReportPendingException
JS_ResolveStandardClass
JS_RestoreExceptionState
JS_SET_TRACING_DETAILS
JS_SameValue
JS_SaveExceptionState
JS_SaveFrameChain
JS_ScheduleGC
JS_SealObject
JS_SetAllNonReservedSlotsToUndefined
JS_SetArrayLength
JS_SetBranchCallback
JS_SetCallReturnValue2
JS_SetCheckObjectAccessCallback
JS_SetCompartmentNameCallback
JS_SetContextCallback
JS_SetDefaultLocale
JS_SetDestroyCompartmentCallback
JS_SetElement
JS_SetErrorReporter
JS_SetExtraGCRoots
JS_SetFunctionCallback
JS_SetGCCallback
JS_SetGCParametersBasedOnAvailableMemory
JS_SetGCZeal
JS_SetGlobalObject
JS_SetICUMemoryFunctions
JS_SetInterruptCallback
JS_SetNativeStackQuota
JS_SetObjectPrincipalsFinder
JS_SetOperationCallback
JS_SetOptions
JS_SetParent
JS_SetPendingException
JS_SetPrincipalsTranscoder
JS_SetPrivate
JS_SetProperty
JS_SetPropertyAttributes
JS_SetPrototype
JS_SetRegExpInput
JS_SetScriptStackQuota
JS_SetThreadStackLimit
JS_SetVersion
JS_SetVersionForCompartment
JS_ShutDown
JS_StrictlyEqual
JS_StringEqualsAscii
JS_StringHasBeenInterned
JS_StringHasLatin1Chars
JS_StringIsFlat
JS_StringToVersion
JS_SuspendRequest
JS_THREADSAFE
JS_ThrowStopIteration
JS_ToggleOptions
JS_TracerInit
JS_TypeOfValue
JS_Unlock
JS_ValueToBoolean
JS_ValueToECMAInt32
JS_ValueToFunction
JS_ValueToId
JS_ValueToInt32
JS_ValueToNumber
JS_ValueToObject
JS_ValueToSource
JS_ValueToString
JS_VersionToString
JS_YieldRequest
JS_freeop
JS_malloc
JS_updateMallocCounter
OBJECT_TO_JSVAL
PRIVATE_TO_JSVAL
Property attributes
STRING_TO_JSVAL
Stored value
jschar
jsdouble
jsid
jsint
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.
NOTE: This page describes SpiderMonkey-specific behavior and might be incomplete. Visit ESTree spec for a community AST standard that includes latest ECMAScript features and is backward-compatible with SpiderMonkey format.
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)
Whether in SpiderMonkey shell or Firefox (after importing), the global singleton object Reflect
currently contains just the parse
method.
Reflect
objectThe 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. |
||
target | String | Default: script |
A type of the parsing target, can be either script or module. |
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; }
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.
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).
If the expression
flag is true
, the function is an expression closure and the body
field is an expression.
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; }
A continue
statement.
interface WithStatement <: Statement { type: "WithStatement"; object: Expression; body: Statement; }
A 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; handler: CatchClause | null; guardedHandlers: [ CatchClause ]; finalizer: BlockStatement | null; }
A try
statement.
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.
for each
form is SpiderMonkey-specific.interface ForOfStatement <: Statement { type: "ForOfStatement"; left: VariableDeclaration | Expression; right: Expression; body: Statement; }
A for
/of
statement.
interface LetStatement <: Statement { type: "LetStatement"; head: [ VariableDeclarator ]; body: Statement; }
A let
statement.
let
statement form is SpiderMonkey-specific.interface DebuggerStatement <: Statement { type: "DebuggerStatement"; }
A debugger
statement.
debugger
statement is new in ECMAScript 5th edition, although SpiderMonkey has supported it for years.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.
interface FunctionDeclaration <: Function, Declaration { type: "FunctionDeclaration"; id: Identifier; params: [ Pattern ]; defaults: [ Expression ]; rest: Identifier | null; body: BlockStatement | Expression; generator: boolean; expression: boolean; }
A function declaration.
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.
id
field cannot be null
.let
and const
are SpiderMonkey-specific.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"; }
A this
expression.
interface ArrayExpression <: Expression { type: "ArrayExpression"; elements: [ Expression | null ]; }
An array expression.
interface ObjectExpression <: Expression { type: "ObjectExpression"; properties: [ Property ]; }
An object expression.
interface Property <: Node { type: "Property"; 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; }
A function expression.
interface ArrowExpression <: Function, Expression { type: "ArrowExpression"; params: [ Pattern ]; defaults: [ Expression ]; rest: Identifier | null; body: BlockStatement | Expression; generator: boolean; expression: boolean; }
A fat arrow function expression, i.e., `let foo = (bar) => { /* body */ }`.
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: Pattern; 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"; callee: Expression; arguments: [ Expression ]; }
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 { type: "YieldExpression"; argument: Expression | null; }
A yield
expression.
yield
expressions are SpiderMonkey-specific.interface ComprehensionExpression <: Expression { type: "ComprehensionExpression"; body: Expression; blocks: [ ComprehensionBlock | ComprehensionIf ]; 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.
interface GeneratorExpression <: Expression { type: "GeneratorExpression"; body: Expression; blocks: [ ComprehensionBlock | ComprehensionIf ]; 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.
interface GraphExpression <: Expression { type: "GraphExpression"; index: uint32; expression: Literal; }
A graph expression, aka "sharp literal," such as #1={ self: #1# }
.
interface GraphIndexExpression <: Expression { type: "GraphIndexExpression"; index: uint32; }
A graph index expression, aka "sharp variable," such as #1#
.
interface LetExpression <: Expression { type: "LetExpression"; head: [ VariableDeclarator ]; body: Expression; }
A let
expression.
let
expression form is SpiderMonkey-specific.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 ]; }
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; }
A catch
clause following a try
block. The optional guard
property corresponds to the optional expression guard on the bound variable.
interface ComprehensionBlock <: Node { type: "ComprehensionBlock"; left: Pattern; right: Expression; each: boolean; }
A for
or for each
block in an array comprehension or generator expression.
interface ComprehensionIf <: Node { type: "ComprehensionIf"; test: Expression; }
An if
filter in an array comprehension or generator filter.
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.
..
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.
This section describes node types that are provided for E4X support. E4X has since been removed as of Gecko 21.
Obsolete
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
interface XMLDefaultDeclaration <: Declaration { type: "XMLDefaultDeclaration"; namespace: Expression; }
A default xml namespace
declaration.
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 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.
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.
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.
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.
program(body[, loc])
body: [ CustomStatement ] loc: SourceLocation
Returns: CustomProgram
Callback to produce a custom program node.
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 unnested 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.
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.
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 | CustomComprehensionIf ] filter: CustomExpression | null loc: SourceLocation
Returns: CustomExpression
Callback to produce a custom comprehension
expression node.
generatorExpression(body, blocks, filter[, loc])
body: CustomExpression blocks: [ CustomComprehensionBlock | CustomComprehensionIf ] 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.
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.
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.
comprehensionIf(test[, loc])
test: CustomExpression loc: SourceLocation
Returns: CustomComprehensionIf
Callback to produce a custom comprehension if node.
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.
xmlDefaultDeclaration(ns[, loc])
loc: SourceLocation
Returns: CustomDeclaration
Callback to produce a custom XML default namespace declaration node.
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.
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.