在AST抽象语法树中,JavaScript的语法节点分为两种类型:语句和表达式。
语句和表达式均继承自ASTNode
一、语句相关 Statement
所有语句相关的类,均继承自Stmt类。
| 样例 | 抽象个体 | 抽象整体 |
|---|---|---|
| document.write(“TEag1e”); | Expr ; | ExprStmt |
| Label : Stmt | LabeledStmt | |
| ; | ; | EmptyStmt |
| break Label ; | BreakStmt | |
| case Expr : Stmt… | Case | |
| catch( Identifier ) { Stmt… } | CatchClause | |
| class Identifier extends Expr { MemberDeclaration… } | ClassDeclStmt | |
| const Identifier = Expr ; | ConstDeclStmt | |
| continue Label ; | ContinueStmt | |
| debugger; | DebuggerStmt | |
| declare global { Stmt… } | GlobalAugmentationDeclaration | |
| declare module StringLiteral { Stmt… } | ExternalModuleDeclaration | |
| default: Stmt… | Case | |
| do Stmt while ( Expr ) | DoWhileStmt | |
| enum Identifier { MemberDeclaration… } | EnumDeclaration | |
| export * from StringLiteral | BulkReExportDeclaration | |
| export default ClassDeclStmt | ExportDefaultDeclaration | |
| export default Expr ; | ExportDefaultDeclaration | |
| export default FunctionDeclStmt | ExportDefaultDeclaration | |
| export { ExportSpecifier… }; | ExportNamedDeclaration | |
| export DeclStmt | ExportNamedDeclaration | |
| export = Expr ; | ExportAssignDeclaration | |
| export as namespace Identifier ; | ExportAsNamespaceDeclaration | |
| for ( Expr ; Expr ; Expr ) Stmt | ForStmt | |
| for ( VarAccess in Expr ) Stmt | ForInStmt | |
| for ( VarAccess of Expr ) Stmt | ForOfStmt | |
| function Identifier ( Parameter… ) { Stmt… } | FunctionDeclStmt | |
| if ( Expr ) Stmt else Stmt | IfStmt | |
| import { ImportSpecifier… from StringLiteral | ImportDeclaration | |
| import Identifier = Expr ; | ImportEqualsDeclaration | |
| interface Identifier { MemberDeclaration… } | InterfaceDeclaration | |
| let Identifier = Expr ; | LetStmt | |
| namespace Identifier { Stmt… } | NamespaceDeclaration | |
| return Expr ; | ReturnStmt | |
| switch ( Expr ) { Case… } | SwitchStmt | |
| throw Expr ; | ThrowStmt | |
| try { Stmt… } CatchClause… finally { Stmt… } | TryStmt | |
| type Identifier = TypeExpr ; | TypeAliasDeclaration | |
| var Identifier = Expr ; | VarDeclStmt | |
| while ( Expr ) Stmt | WhileStmt | |
| with ( Expr ) Stmt | WithStmt | |
| { Stmt… } | BlockStmt |
二、表达式相关 Expression
文本常量 Literals
| Expression syntax | CodeQL class |
|---|---|
| TRUE | BooleanLiteral |
| 23 | NumberLiteral |
| 4.2 | NumberLiteral |
| “Hello” | StringLiteral |
| /ab*c?/ | RegExpLiteral |
| null | NullLiteral |
标识符 Identifiers
所有标识符相关的类,均继承自Identifier类
VarRef 变量引用
在如下示例中,document可以认为是VarRef
document.write(document.location);
Label
在如下示例中,write和location可以认为是Label
document.write(document.location);
主表达式 Primary expressions
| 代码示例 | Expression syntax | CodeQL class |
|---|---|---|
| this | ThisExpr | |
| [ Expr… ] | ArrayExpr | |
| { Property… } | ObjectExpr | |
| function ( Parameter… ) { Stmt… } | FunctionExpr | |
| ( Parameter… ) => Expr | ArrowFunctionExpr | |
| ( Expr ) | ParExpr | |
… |
TemplateLiteral | |
Expr … |
TaggedTemplateExpr |
属性 Properties
属性访问 Property accesses
所有语句相关的类,均继承自PropAccess类。
| 代码示例 | Expression syntax | CodeQL class |
|---|---|---|
| document.location | Expr . Identifier | DotExpr |
| Expr [ Expr ] | IndexExpr |
函数调用和New Function calls and new
所有语句相关的类,均继承自InvokeExpr类。
| 代码示例 | Expression syntax | CodeQL class |
|---|---|---|
| Expr ( Expr… ) | CallExpr | |
| document.write(document.location) | Expr . Identifier ( Expr… ) | MethodCallExpr |
| new Expr ( Expr… ) | NewExpr |
一元表达式 Unary expressions
两元表达式 Binary expressions
赋值表达式 Assignment expressions
自更新表达式 Update expressions
其他 Miscellaneous
案例
document.write(document.location.href.charCodeAt(0));
