- Statements and Declarations
- Block Statement
- Break Statement
- Class Declaration
- Continue Statement
- Debugger Statement
- Do-While Statement
- Empty Statement
- Expression Statement
- For Statement
- For-In Statement
- For-Of Statement
- Function Declaration
- If Statement
- Labelled Statement
- Return Statement
- Switch Statement
- Throw Statement
- Try Statement
- Variable Declaration
- While Statement
- With Statement
Statements and Declarations
A statement can be one of the following:
- type Statement = BlockStatement | BreakStatement | ContinueStatement |
- DebuggerStatement | DoWhileStatement | EmptyStatement |
- ExpressionStatement | ForStatement | ForInStatement |
- ForOfStatement | FunctionDeclaration | IfStatement |
- LabeledStatement | ReturnStatement | SwitchStatement |
- ThrowStatement | TryStatement | VariableDeclaration |
- WhileStatement | WithStatement;
A declaration can be one of the following:
- type Declaration = ClassDeclaration | FunctionDeclaration | VariableDeclaration;
A statement list item is either a statement or a declaration:
- type StatementListItem = Declaration | Statement;
Block Statement
A series of statements enclosed by a pair of curly braces form a block statement:
- interface BlockStatement {
- type: 'BlockStatement';
- body: StatementListItem[];
- }
Break Statement
- interface BreakStatement {
- type: 'BreakStatement';
- label: Identifier | null;
- }
Class Declaration
- interface ClassDeclaration {
- type: 'ClassDeclaration';
- id: Identifier | null;
- superClass: Identifier | null;
- body: ClassBody;
- }
Continue Statement
- interface ContinueStatement {
- type: 'ContinueStatement';
- label: Identifier | null;
- }
Debugger Statement
- interface DebuggerStatement {
- type: 'DebuggerStatement';
- }
Do-While Statement
- interface DoWhileStatement {
- type: 'DoWhileStatement';
- body: Statement;
- test: Expression;
- }
Empty Statement
- interface EmptyStatement {
- type: 'EmptyStatement';
- }
Expression Statement
- interface ExpressionStatement {
- type: 'ExpressionStatement';
- expression: Expression;
- directive?: string;
- }
When the expression statement represents a directive (such as "use strict"
), then the directive
property will contain the directive string.
For Statement
- interface ForStatement {
- type: 'ForStatement';
- init: Expression | VariableDeclaration | null;
- test: Expression | null;
- update: Expression | null;
- body: Statement;
- }
For-In Statement
- interface ForInStatement {
- type: 'ForInStatement';
- left: Expression;
- right: Expression;
- body: Statement;
- each: false;
- }
For-Of Statement
- interface ForOfStatement {
- type: 'ForOfStatement';
- left: Expression;
- right: Expression;
- body: Statement;
- }
Function Declaration
- interface FunctionDeclaration {
- type: 'FunctionDeclaration';
- id: Identifier | null;
- params: FunctionParameter[];
- body: BlockStatement;
- generator: boolean;
- async: boolean;
- expression: false;
- }
with
- type FunctionParameter = AssignmentPattern | Identifier | BindingPattern;
If Statement
- interface IfStatement {
- type: 'IfStatement';
- test: Expression;
- consequent: Statement;
- alternate?: Statement;
- }
Labelled Statement
A statement prefixed by a label becomes a labelled statement:
- interface LabeledStatement {
- type: 'LabeledStatement';
- label: Identifier;
- body: Statement;
- }
Return Statement
- interface ReturnStatement {
- type: 'ReturnStatement';
- argument: Expression | null;
- }
Switch Statement
- interface SwitchStatement {
- type: 'SwitchStatement';
- discriminant: Expression;
- cases: SwitchCase[];
- }
with
- interface SwitchCase {
- type: 'SwitchCase';
- test: Expression | null;
- consequent: Statement[];
- }
Throw Statement
- interface ThrowStatement {
- type: 'ThrowStatement';
- argument: Expression;
- }
Try Statement
- interface TryStatement {
- type: 'TryStatement';
- block: BlockStatement;
- handler: CatchClause | null;
- finalizer: BlockStatement | null;
- }
with
- interface CatchClause {
- type: 'CatchClause';
- param: Identifier | BindingPattern;
- body: BlockStatement;
- }
Variable Declaration
- interface VariableDeclaration {
- type: 'VariableDeclaration';
- declarations: VariableDeclarator[];
- kind: 'var' | 'const' | 'let';
- }
with
- interface VariableDeclarator {
- type: 'VariableDeclarator';
- id: Identifier | BindingPattern;
- init: Expression | null;
- }
While Statement
- interface WhileStatement {
- type: 'WhileStatement';
- test: Expression;
- body: Statement;
- }
With Statement
- interface WithStatement {
- type: 'WithStatement';
- object: Expression;
- body: Statement;
- }