A node can have three different types of attributes. An attribute containing another node, an attribute containing an array of other nodes, or an attribute containing a primitive value such as a boolean, string, or number.
Use grasp --help syntax
for an overview of the syntax, and grasp --help node-type
(eg. grasp --help if
) for more about information about a node type.
Skip to statements, expressions, declarations, clauses, or categories of node types.
Based on the Mozilla SpiderMonkey AST format.
Misc
program (Program)
- node array attributes:
- body
note:
The root node of a JavaScript program's AST.
ident (Identifier)
- primitive attributes:
- name
example:
literal (Literal)
- primitive attributes:
- value (val)
examples:
regex (RegExpLiteral)
- primitive attributes:
- regex
example:
prop (Property)
- node attributes:
- key, value (val)
- primitive attributes:
- kind
syntax:
key: value
example:
note:
An object expression (obj) has a list of properties, each being a property.
spread (SpreadElement)
- node attributes:
- argument (arg)
template-element (TemplateElement)
- primitive attributes:
- tail, value (val)
Statements
empty (EmptyStatement)
example:
block (BlockStatement)
- node array attributes:
- body
syntax:
{ statement_1 statement_2 ... statement_n }
example:
exp-statement (ExpressionStatement)
- node attributes:
- expression (exp)
syntax:
expression;
example:
note:
When an expression is used where a statement should be, it is wrapped in an expression statement.
if (IfStatement)
- node attributes:
- test, consequent (then), alternate (alt, else)
syntax:
if (test) consequent [else alternate]
examples:
label (LabeledStatement)
- node attributes:
- label, body
syntax:
label: body;
example:
break (BreakStatement)
- node attributes:
- label
syntax:
break [label];
examples:
continue (ContinueStatement)
- node attributes:
- label
syntax:
continue [label];
examples:
with (WithStatement)
- node attributes:
- object (obj), body
syntax:
with (object) body
example:
switch (SwitchStatement)
- node attributes:
- discriminant
- node array attributes:
- cases
syntax:
switch (discriminant) { case_1 case_2 ... case_n }
example:
return (ReturnStatement)
- node attributes:
- argument (arg)
syntax:
return argument;
example:
throw (ThrowStatement)
- node attributes:
- argument (arg)
syntax:
throw argument;
example:
try (TryStatement)
- node attributes:
- block, handler, finalizer
syntax:
try block [handler] [finally finalizer]
example:
while (WhileStatement)
- node attributes:
- test, body
syntax:
while (test) body
example:
do-while (DoWhileStatement)
- node attributes:
- test, body
syntax:
do body while (test);
example:
for (ForStatement)
- node attributes:
- init, test, update, body
syntax:
for ([init]; [test]; [update]) body
example:
for-in (ForInStatement)
- node attributes:
- left (l), right (r), body
syntax:
for (left in right) body
example:
for-of (ForOfStatement)
- node attributes:
- left (l), right (r), body
syntax:
for (left of right) body
example:
debugger (DebuggerStatement)
syntax:
debugger;
example:
Declarations
func-dec (FunctionDeclaration)
- node attributes:
- id, body
- node array attributes:
- params
- primitive attributes:
- generator
syntax:
function id([param_1], [param_2], [..., param_3]) body
example:
note:
A function declaration contrasts with a function expression (func-exp).
var-decs (VariableDeclaration)
- node array attributes:
- declarations (decs)
- primitive attributes:
- kind
syntax:
var declaration_1[, declaration_2, ..., declaration_n]
example:
note:
Each declaration is a variable declarator (var-dec).
var-dec (VariableDeclarator)
- node attributes:
- id, init
syntax:
id = init
example:
Expressions
this (ThisExpression)
example:
super (Super)
example:
arr (ArrayExpression)
- node array attributes:
- elements (els)
syntax:
[element_0, element_1, ..., element_n]
examples:
obj (ObjectExpression)
- node array attributes:
- properties (props)
syntax:
{ property_1, property_2, ..., property_n }
examples:
func-exp (FunctionExpression)
- node attributes:
- id, body
- node array attributes:
- params
- primitive attributes:
- generator
syntax:
function [id]([param_1], [param_2], [..., param_3]) body
example:
note:
A function expression contrasts with a function declaration (func-dec).
arrow (ArrowFunctionExpression)
- node attributes:
- id, body
- node array attributes:
- params
- primitive attributes:
- generator, expression (exp)
syntax:
([param_1], [param_2], [..., param_3]) => body
example:
seq (SequenceExpression)
- node array attributes:
- expressions (exps)
syntax:
expression_1, expression_2, ..., expression_n
example:
yield (YieldExpression)
- node attributes:
- argument (arg)
syntax:
yield argument
example:
unary (UnaryExpression)
- node attributes:
- argument (arg)
syntax:
operatorargument
examples:
bi (BinaryExpression)
- node attributes:
- left (l), right (r)
- primitive attributes:
- operator (op)
syntax:
left operator right
example:
assign (AssignmentExpression)
- node attributes:
- left (l), right (r)
- primitive attributes:
- operator (op)
syntax:
left operator right
example:
update (UpdateExpression)
- node attributes:
- argument (arg)
- primitive attributes:
- operator (op), prefix
syntax:
argumentoperator or, if prefix operatorargument
examples:
logic (LogicalExpression)
- node attributes:
- left (l), right (r)
- primitive attributes:
- operator (op)
syntax:
left operator right
example:
cond (ConditionalExpression)
- node attributes:
- test, consequent (then), alternate (alt, else)
syntax:
test ? consequent : alternate
example:
new (NewExpression)
- node attributes:
- callee
- node array attributes:
- arguments (args)
syntax:
new callee(argument_1, argument_2, ..., argument_n)
example:
call (CallExpression)
- node attributes:
- callee
- node array attributes:
- arguments (args)
syntax:
callee(argument_1, argument_2, ..., argument_n)
example:
member (MemberExpression)
- node attributes:
- object (obj), property (prop)
- primitive attributes:
- computed
syntax:
object.property
example:
template-literal (TemplateLiteral)
- node array attributes:
- quasis, expressions (exps)
tagged-template-exp (TaggedTemplateExpression)
- node attributes:
- tag, quasi
Clauses
switch-case (SwitchCase)
- node attributes:
- test
- node array attributes:
- consequent (then)
syntax:
case test | default : consequent
examples:
catch (CatchClause)
- node attributes:
- param, body
syntax:
catch (param) body
example:
Patterns
assign-prop (AssignmentProperty)
- node attributes:
- key, value (val)
- primitive attributes:
- kind, method
obj-pattern (ObjectPattern)
- node array attributes:
- properties (props)
array-pattern (ArrayPattern)
- node array attributes:
- elements (els)
rest-element (RestElement)
- node attributes:
- argument (arg)
assign-pattern (AssignmentPattern)
- node attributes:
- left (l), right (r)
Classes
class-body (ClassBody)
- node array attributes:
- body
method (MethodDefinition)
- node attributes:
- key, value (val)
- primitive attributes:
- kind, computed, static
class-dec (ClassDeclaration)
- node attributes:
- id, superClass, body
class-exp (ClassExpression)
- node attributes:
- id, superClass, body
meta-property (MetaProperty)
- node attributes:
- meta, property (prop)
Modules
module-dec (ModuleDeclaration)
module-specifier (ModuleSpecifier)
- node attributes:
- local
Imports
import-dec (ImportDeclaration)
- node attributes:
- source
- node array attributes:
- specifiers
import-specifier (ImportSpecifier)
- node attributes:
- local, imported
import-default-specifier (ImportDefaultSpecifier)
- node attributes:
- local
import-namespace-specifier (ImportNamespaceSpecifier)
- node attributes:
- local
Exports
export-named-dec (ExportNamedDeclaration)
- node attributes:
- declaration, source
- node array attributes:
- specifiers
export-specifier (ExportSpecifier)
- node attributes:
- local, exported
export-default-specifier (ExportDefaultDeclaration)
- node attributes:
- declaration
export-namespace-specifier (ExportAllDeclarationSpecifier)
- node attributes:
- source
Categories
Categories of node types - use grasp --help categories
for an overview, and grasp --help category-name
for further information about a specific category.
statement (Statement)
- empty
- block
- exp-statement
- if
- label
- break
- continue
- with
- switch
- return
- throw
- try
- while
- do-while
- for
- for-in
- for-of
- debugger
dec (Declaration)
- func-dec
- var-decs
- var-dec
exp (Expression)
- this
- super
- arr
- obj
- func-exp
- arrow
- seq
- yield
- unary
- bi
- assign
- update
- logic
- cond
- new
- call
- member
- template-literal
- tagged-template-exp
clause (Clause)
- switch-case
- catch
biop (BiOp)
- bi
- logic
- assign
func (Function)
- func-dec
- func-exp
for-loop (ForLoop)
- for
- for-in
- for-of
while-loop (WhileLoop)
- do-while
- while
loop (Loop)
- for
- for-in
- for-of
- do-while
- while
class (Class)
- class-exp
- class-exp