Statements and Declarations

A statement can be one of the following:

  1. type Statement = BlockStatement | BreakStatement | ContinueStatement |
  2. DebuggerStatement | DoWhileStatement | EmptyStatement |
  3. ExpressionStatement | ForStatement | ForInStatement |
  4. ForOfStatement | FunctionDeclaration | IfStatement |
  5. LabeledStatement | ReturnStatement | SwitchStatement |
  6. ThrowStatement | TryStatement | VariableDeclaration |
  7. WhileStatement | WithStatement;

A declaration can be one of the following:

  1. type Declaration = ClassDeclaration | FunctionDeclaration | VariableDeclaration;

A statement list item is either a statement or a declaration:

  1. type StatementListItem = Declaration | Statement;

Block Statement

A series of statements enclosed by a pair of curly braces form a block statement:

  1. interface BlockStatement {
  2. type: 'BlockStatement';
  3. body: StatementListItem[];
  4. }

Break Statement

  1. interface BreakStatement {
  2. type: 'BreakStatement';
  3. label: Identifier | null;
  4. }

Class Declaration

  1. interface ClassDeclaration {
  2. type: 'ClassDeclaration';
  3. id: Identifier | null;
  4. superClass: Identifier | null;
  5. body: ClassBody;
  6. }

Continue Statement

  1. interface ContinueStatement {
  2. type: 'ContinueStatement';
  3. label: Identifier | null;
  4. }

Debugger Statement

  1. interface DebuggerStatement {
  2. type: 'DebuggerStatement';
  3. }

Do-While Statement

  1. interface DoWhileStatement {
  2. type: 'DoWhileStatement';
  3. body: Statement;
  4. test: Expression;
  5. }

Empty Statement

  1. interface EmptyStatement {
  2. type: 'EmptyStatement';
  3. }

Expression Statement

  1. interface ExpressionStatement {
  2. type: 'ExpressionStatement';
  3. expression: Expression;
  4. directive?: string;
  5. }

When the expression statement represents a directive (such as "use strict"), then the directive property will contain the directive string.

For Statement

  1. interface ForStatement {
  2. type: 'ForStatement';
  3. init: Expression | VariableDeclaration | null;
  4. test: Expression | null;
  5. update: Expression | null;
  6. body: Statement;
  7. }

For-In Statement

  1. interface ForInStatement {
  2. type: 'ForInStatement';
  3. left: Expression;
  4. right: Expression;
  5. body: Statement;
  6. each: false;
  7. }

For-Of Statement

  1. interface ForOfStatement {
  2. type: 'ForOfStatement';
  3. left: Expression;
  4. right: Expression;
  5. body: Statement;
  6. }

Function Declaration

  1. interface FunctionDeclaration {
  2. type: 'FunctionDeclaration';
  3. id: Identifier | null;
  4. params: FunctionParameter[];
  5. body: BlockStatement;
  6. generator: boolean;
  7. async: boolean;
  8. expression: false;
  9. }

with

  1. type FunctionParameter = AssignmentPattern | Identifier | BindingPattern;

If Statement

  1. interface IfStatement {
  2. type: 'IfStatement';
  3. test: Expression;
  4. consequent: Statement;
  5. alternate?: Statement;
  6. }

Labelled Statement

A statement prefixed by a label becomes a labelled statement:

  1. interface LabeledStatement {
  2. type: 'LabeledStatement';
  3. label: Identifier;
  4. body: Statement;
  5. }

Return Statement

  1. interface ReturnStatement {
  2. type: 'ReturnStatement';
  3. argument: Expression | null;
  4. }

Switch Statement

  1. interface SwitchStatement {
  2. type: 'SwitchStatement';
  3. discriminant: Expression;
  4. cases: SwitchCase[];
  5. }

with

  1. interface SwitchCase {
  2. type: 'SwitchCase';
  3. test: Expression | null;
  4. consequent: Statement[];
  5. }

Throw Statement

  1. interface ThrowStatement {
  2. type: 'ThrowStatement';
  3. argument: Expression;
  4. }

Try Statement

  1. interface TryStatement {
  2. type: 'TryStatement';
  3. block: BlockStatement;
  4. handler: CatchClause | null;
  5. finalizer: BlockStatement | null;
  6. }

with

  1. interface CatchClause {
  2. type: 'CatchClause';
  3. param: Identifier | BindingPattern;
  4. body: BlockStatement;
  5. }

Variable Declaration

  1. interface VariableDeclaration {
  2. type: 'VariableDeclaration';
  3. declarations: VariableDeclarator[];
  4. kind: 'var' | 'const' | 'let';
  5. }

with

  1. interface VariableDeclarator {
  2. type: 'VariableDeclarator';
  3. id: Identifier | BindingPattern;
  4. init: Expression | null;
  5. }

While Statement

  1. interface WhileStatement {
  2. type: 'WhileStatement';
  3. test: Expression;
  4. body: Statement;
  5. }

With Statement

  1. interface WithStatement {
  2. type: 'WithStatement';
  3. object: Expression;
  4. body: Statement;
  5. }