CodeQL documentation

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.

Statement syntax

CodeQL class

Superclasses

Remarks

Expr ;

ExprStmt

Label : Stmt

LabeledStmt

;

EmptyStmt

break Label ;

BreakStmt

JumpStmt, BreakOrContinueStmt

case Expr : Stmt

Case

can only occur as child of a SwitchStmt

catch( Identifier ) { Stmt}

CatchClause

ControlStmt

can only occur as child of a TryStmt

class Identifier extends Expr { MemberDeclaration}

ClassDeclStmt

ClassDefinition, ClassOrInterface, TypeParameterized

const Identifier = Expr ;

ConstDeclStmt

DeclStmt

continue Label ;

ContinueStmt

JumpStmt, BreakOrContinueStmt

debugger;

DebuggerStmt

declare global { Stmt}

GlobalAugmentationDeclaration

declare module StringLiteral { Stmt}

ExternalModuleDeclaration

default: Stmt

Case

can only occur as child of a SwitchStmt; use isDefault to distinguish default from case

do Stmt while ( Expr )

DoWhileStmt

ControlStmt, LoopStmt

enum Identifier { MemberDeclaration}

EnumDeclaration

NamespaceDefinition

export * from StringLiteral

BulkReExportDeclaration

ReExportDeclaration, ExportDeclaration

export default ClassDeclStmt

ExportDefaultDeclaration

ExportDeclaration

export default Expr ;

ExportDefaultDeclaration

ExportDeclaration

export default FunctionDeclStmt

ExportDefaultDeclaration

ExportDeclaration

export { ExportSpecifier};

ExportNamedDeclaration

ExportDeclaration

export DeclStmt

ExportNamedDeclaration

ExportDeclaration

export = Expr ;

ExportAssignDeclaration

export as namespace Identifier ;

ExportAsNamespaceDeclaration

for ( Expr ; Expr ; Expr ) Stmt

ForStmt

ControlStmt, LoopStmt

for ( VarAccess in Expr ) Stmt

ForInStmt

ControlStmt, LoopStmt, EnhancedForLoop

for ( VarAccess of Expr ) Stmt

ForOfStmt

ControlStmt, LoopStmt, EnhancedForLoop

function Identifier ( Parameter) { Stmt}

FunctionDeclStmt

Function

if ( Expr ) Stmt else Stmt

IfStmt

ControlStmt

import { ImportSpecifierfrom StringLiteral

ImportDeclaration

Import

import Identifier = Expr ;

ImportEqualsDeclaration

interface Identifier { MemberDeclaration}

InterfaceDeclaration

InterfaceDefinition, ClassOrInterface, TypeParameterized

let Identifier = Expr ;

LetStmt

DeclStmt

namespace Identifier { Stmt}

NamespaceDeclaration

NamespaceDefinition

return Expr ;

ReturnStmt

JumpStmt

switch ( Expr ) { Case}

SwitchStmt

ControlStmt

throw Expr ;

ThrowStmt

JumpStmt

try { Stmt} CatchClausefinally { Stmt}

TryStmt

ControlStmt

type Identifier = TypeExpr ;

TypeAliasDeclaration

TypeParameterized

var Identifier = Expr ;

VarDeclStmt

DeclStmt

while ( Expr ) Stmt

WhileStmt

ControlStmt, LoopStmt

with ( Expr ) Stmt

WithStmt

ControlStmt

{ Stmt}

BlockStmt

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 in var x = "hi" or in function(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 and p 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

Miscellaneous

All classes in this table are subclasses of Expr.

Expression syntax

CodeQL class

Expr ? Expr : Expr

ConditionalExpr

Expr ,, Expr

SeqExpr

await Expr

AwaitExpr

yield Expr

YieldExpr

Further reading

  • © GitHub, Inc.
  • Terms
  • Privacy