CodeQL 文档

用于处理 JavaScript 和 TypeScript 程序的抽象语法树类

CodeQL 提供了大量类来表示 JavaScript 和 TypeScript 程序的抽象语法树。

抽象语法树(AST)表示程序的语法结构。AST 上的节点表示语句和表达式等元素。

语句类

此表列出了 Stmt 的子类,这些子类表示 ECMAScript 和 TypeScript 语句。

语句语法 CodeQL 类 超类 备注
Expr ; ExprStmt    
Label : Stmt LabeledStmt    
; EmptyStmt    
break Label ; BreakStmt JumpStmt, BreakOrContinueStmt  
case Expr : Stmt Case   只能作为 SwitchStmt 的子项出现
catch( Identifier ) { Stmt} CatchClause ControlStmt 只能作为 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   只能作为 SwitchStmt 的子项出现;使用 isDefault 区分 defaultcase
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 标识符 ( 参数) { 语句} 函数声明语句 函数  
if ( 表达式 ) 语句 else 语句 If语句 ControlStmt  
import { 导入说明符from 字符串字面量 导入声明 导入  
import 标识符 = 表达式 ; 导入等于声明    
interface 标识符 { 成员声明} 接口声明 接口定义, 类或接口, 类型参数化  
let 标识符 = 表达式 ; Let语句 DeclStmt  
namespace 标识符 { 语句} 命名空间声明 NamespaceDefinition  
return 表达式 ; 返回语句 跳转语句  
switch ( 表达式 ) { 情况} Switch语句 ControlStmt  
throw 表达式 ; 抛出语句 跳转语句  
try { 语句} 捕获子句finally { 语句} Try语句 ControlStmt  
type 标识符 = 类型表达式 ; 类型别名声明 类型参数化  
var 标识符 = 表达式 ; Var声明语句 DeclStmt  
while ( 表达式 ) 语句 While语句 ControlStmt, LoopStmt  
with ( 表达式 ) 语句 With语句 ControlStmt  
{ 语句} 块语句    

表达式类

表达式类数量众多,因此我们按类别介绍。本节中的所有类都是 表达式 的子类,除非另有说明。

字面量

本小节中的所有类都是 字面量 的子类。

表达式语法 CodeQL 类
true 布尔字面量
23 数字字面量
4.2 数字字面量
"Hello" 字符串字面量
/ab*c?/ 正则表达式字面量
null 空字面量

标识符

所有标识符都由 标识符 类表示,该类有子类来表示特定类型的标识符

主表达式

本小节中的所有类都是 表达式 的子类。

表达式语法 CodeQL 类 超类 备注
this This表达式    
[ 表达式] 数组表达式    
{ 属性} 对象表达式    
function ( 参数) { 语句} 函数表达式 函数  
( 参数) => 表达式 箭头函数表达式 函数  
( 表达式 ) 括号表达式    
`` 模板字面量   模板字面量 中的元素要么是表示常量模板元素的 模板元素,要么是表示形式为 ${ 表达式 } 的插值表达式的其他表达式
表达式 `` 标记模板表达式   标记模板表达式 中的元素要么是表示常量模板元素的 模板元素,要么是表示形式为 ${ 表达式 } 的插值表达式的其他表达式

属性

本小节中的所有类都是 Property 的子类。请注意,Property 不是 Expr 的子类。

属性语法 CodeQL 类 超类
Identifier : Expr ValueProperty  
get Identifier () { Stmt} PropertyGetter PropertyAccessor
set Identifier ( Identifier ) { Stmt} PropertySetter PropertyAccessor

属性访问

本小节中的所有类都是 PropAccess 的子类。

表达式语法 CodeQL 类
Expr . Identifier DotExpr
Expr [ Expr ] IndexExpr

函数调用和 new

本小节中的所有类都是 InvokeExpr 的子类。

表达式语法 CodeQL 类 备注
Expr ( Expr) CallExpr  
Expr . Identifier ( Expr) MethodCallExpr 这也包括以下形式的调用:Expr [ Expr ] ( Expr)
new Expr ( Expr) NewExpr  

一元表达式

本小节中的所有类都是 UnaryExpr 的子类。

表达式语法 CodeQL 类
~ Expr BitNotExpr
- Expr NegExpr
+ Expr PlusExpr
! Expr LogNotExpr
typeof Expr TypeofExpr
void Expr VoidExpr
delete Expr DeleteExpr
... Expr SpreadElement

更新表达式

此表中的所有类都是 UpdateExpr 的子类。

表达式语法 CodeQL 类
Expr ++ PostIncExpr
Expr -- PostDecExpr
++ Expr PreIncExpr
-- Expr PreDecExpr

其他

此表中的所有类都是 Expr 的子类。

表达式语法 CodeQL 类
Expr ? Expr : Expr ConditionalExpr
Expr ,, Expr SeqExpr
await Expr AwaitExpr
yield Expr YieldExpr
  • ©GitHub, Inc.
  • 条款
  • 隐私