Abstract syntax tree classes for working with JavaScript and TypeScript programs¶
CodeQL has a large selection of classes for representing the abstract syntax tree of JavaScript and TypeScript programs.
The abstract syntax tree (AST) represents the syntactic structure of a program. Nodes on the AST represent elements such as statements and expressions.
Statement classes¶
This table lists subclasses of Stmt representing ECMAScript and TypeScript statements.
Expression classes¶
There is a large number of expression classes, so we present them by category. All classes in this section are subclasses of Expr, except where noted otherwise.
Literals¶
All classes in this subsection are subclasses of Literal.
Expression syntax | CodeQL class |
---|---|
true |
BooleanLiteral |
23 |
NumberLiteral |
4.2 |
NumberLiteral |
"Hello" |
StringLiteral |
/ab*c?/ |
RegExpLiteral |
null |
NullLiteral |
Identifiers¶
All identifiers are represented by the class Identifier, which has subclasses to represent specific kinds of identifiers:
- VarAccess: an identifier that refers to a variable
- VarDecl: an identifier that declares a variable, for example
x
invar x = "hi"
or infunction(x) { }
- VarRef: a VarAccess or a VarDecl
- Label: an identifier that refers to a statement label or a property, not a variable; in the following examples,
l
andp
are labels:break l;
l: for(;;) {}
x.p
{ p: 42 }
Primary expressions¶
All classes in this subsection are subclasses of Expr.
Expression syntax | CodeQL class | Superclasses | Remarks |
---|---|---|---|
this |
ThisExpr | ||
[ Expr… ] |
ArrayExpr | ||
{ Property… } |
ObjectExpr | ||
function ( Parameter… ) { Stmt… } |
FunctionExpr | Function | |
( Parameter… ) => Expr |
ArrowFunctionExpr | Function | |
( Expr ) |
ParExpr | ||
` … ` |
TemplateLiteral | an element in a TemplateLiteral is either a TemplateElement representing a constant template element, or some other expression representing an interpolated expression of the form ${ Expr } |
|
Expr ` … ` |
TaggedTemplateExpr | an element in a TaggedTemplateExpr is either a TemplateElement representing a constant template element, or some other expression representing an interpolated expression of the form ${ Expr } |
Properties¶
All classes in this subsection are subclasses of Property. Note that Property is not a subclass of Expr.
Property syntax | CodeQL class | Superclasses |
---|---|---|
Identifier : Expr |
ValueProperty | |
get Identifier () { Stmt… } |
PropertyGetter | PropertyAccessor |
set Identifier ( Identifier ) { Stmt… } |
PropertySetter | PropertyAccessor |
Property accesses¶
All classes in this subsection are subclasses of PropAccess.
Expression syntax | CodeQL class |
---|---|
Expr . Identifier |
DotExpr |
Expr [ Expr ] |
IndexExpr |
Function calls and new
¶
All classes in this subsection are subclasses of InvokeExpr.
Expression syntax | CodeQL class | Remarks |
---|---|---|
Expr ( Expr… ) |
CallExpr | |
Expr . Identifier ( Expr… ) |
MethodCallExpr | this also includes calls of the form Expr [ Expr ] ( Expr… ) |
new Expr ( Expr… ) |
NewExpr |
Unary expressions¶
All classes in this subsection are subclasses of UnaryExpr.
Expression syntax | CodeQL class |
---|---|
~ Expr |
BitNotExpr |
- Expr |
NegExpr |
+ Expr |
PlusExpr |
! Expr |
LogNotExpr |
typeof Expr |
TypeofExpr |
void Expr |
VoidExpr |
delete Expr |
DeleteExpr |
... Expr |
SpreadElement |
Binary expressions¶
All classes in this subsection are subclasses of BinaryExpr.
Expression syntax | CodeQL class | Superclasses |
---|---|---|
Expr * Expr |
MulExpr | |
Expr / Expr |
DivExpr | |
Expr % Expr |
ModExpr | |
Expr ** Expr |
ExpExpr | |
Expr + Expr |
AddExpr | |
Expr - Expr |
SubExpr | |
Expr << Expr |
LShiftExpr | |
Expr >> Expr |
RShiftExpr | |
Expr >>> Expr |
URShiftExpr | |
Expr && Expr |
LogAndExpr | |
Expr || Expr |
LogOrExpr | |
Expr < Expr |
LTExpr | Comparison |
Expr > Expr |
GTExpr | Comparison |
Expr <= Expr |
LEExpr | Comparison |
Expr >= Expr |
GEExpr | Comparison |
Expr == Expr |
EqExpr | EqualityTest, Comparison |
Expr != Expr |
NEqExpr | EqualityTest, Comparison |
Expr === Expr |
StrictEqExpr | EqualityTest, Comparison |
Expr !== Expr |
StrictNEqExpr | EqualityTest, Comparison |
Expr & Expr |
BitAndExpr | |
Expr | Expr |
BitOrExpr | |
Expr ^ Expr |
XOrExpr | |
Expr in Expr |
InExpr | |
Expr instanceof Expr |
InstanceofExpr |
Assignment expressions¶
All classes in this table are subclasses of Assignment.
Expression syntax | CodeQL class | Superclasses |
---|---|---|
Expr = Expr |
AssignExpr | |
Expr += Expr |
AssignAddExpr | CompoundAssignExpr |
Expr -= Expr |
AssignSubExpr | CompoundAssignExpr |
Expr *= Expr |
AssignMulExpr | CompoundAssignExpr |
Expr **= Expr |
AssignExpExpr | CompoundAssignExpr |
Expr /= Expr |
AssignDivExpr | CompoundAssignExpr |
Expr %= Expr |
AssignModExpr | CompoundAssignExpr |
Expr &= Expr |
AssignAndExpr | CompoundAssignExpr |
Expr |= Expr |
AssignOrExpr | CompoundAssignExpr |
Expr ^= Expr |
AssignXOrExpr | CompoundAssignExpr |
Expr <<= Expr |
AssignLShiftExpr | CompoundAssignExpr |
Expr >>= Expr |
AssignRShiftExpr | CompoundAssignExpr |
Expr >>>= Expr |
AssignURShiftExpr | CompoundAssignExpr |
Update expressions¶
All classes in this table are subclasses of UpdateExpr.
Expression syntax | CodeQL class |
---|---|
Expr ++ |
PostIncExpr |
Expr -- |
PostDecExpr |
++ Expr |
PreIncExpr |
-- Expr |
PreDecExpr |