Expressions and Patterns

A binding pattern can be one of the following:

  1. type BindingPattern = ArrayPattern | ObjectPattern;

An expression can be one of the following:

  1. type Expression = ThisExpression | Identifier | Literal |
  2. ArrayExpression | ObjectExpression | FunctionExpression | ArrowFunctionExpression | ClassExpression |
  3. TaggedTemplateExpression | MemberExpression | Super | MetaProperty |
  4. NewExpression | CallExpression | UpdateExpression | AwaitExpression | UnaryExpression |
  5. BinaryExpression | LogicalExpression | ConditionalExpression |
  6. YieldExpression | AssignmentExpression | SequenceExpression;

Array Pattern

  1. interface ArrayPattern {
  2. type: 'ArrayPattern';
  3. elements: ArrayPatternElement[];
  4. }

with

  1. type ArrayPatternElement = AssignmentPattern | Identifier | BindingPattern | RestElement | null;
  2.  
  3. interface RestElement {
  4. type: 'RestElement';
  5. argument: Identifier | BindingPattern;
  6. }

Assignment Pattern

  1. interface AssignmentPattern {
  2. type: 'AssignmentPattern';
  3. left: Identifier | BindingPattern;
  4. right: Expression;
  5. }

Object Pattern

  1. interface ObjectPattern {
  2. type: 'ObjectPattern';
  3. properties: Property[];
  4. }

This Expression

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

Identifier

  1. interface Identifier {
  2. type: 'Identifier';
  3. name: string;
  4. }

Literal

  1. interface Literal {
  2. type: 'Literal';
  3. value: boolean | number | string | RegExp | null;
  4. raw: string;
  5. regex?: { pattern: string, flags: string };
  6. }

The regex property only applies to regular expression literals.

Array Expression

  1. interface ArrayExpression {
  2. type: 'ArrayExpression';
  3. elements: ArrayExpressionElement[];
  4. }

where

  1. type ArrayExpressionElement = Expression | SpreadElement;

Object Expression

  1. interface ObjectExpression {
  2. type: 'ObjectExpression';
  3. properties: Property[];
  4. }

where

  1. interface Property {
  2. type: 'Property';
  3. key: Expression;
  4. computed: boolean;
  5. value: Expression | null;
  6. kind: 'get' | 'set' | 'init';
  7. method: false;
  8. shorthand: boolean;
  9. }

Function Expression

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

with

  1. type FunctionParameter = AssignmentPattern | Identifier | BindingPattern;

The value of generator is true for a generator expression.

Arrow Function Expression

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

Class Expression

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

with

  1. interface ClassBody {
  2. type: 'ClassBody';
  3. body: MethodDefinition[];
  4. }
  5.  
  6. interface MethodDefinition {
  7. type: 'MethodDefinition';
  8. key: Expression | null;
  9. computed: boolean;
  10. value: FunctionExpression | null;
  11. kind: 'method' | 'constructor';
  12. static: boolean;
  13. }

Tagged Template Expression

  1. interface TaggedTemplateExpression {
  2. type: 'TaggedTemplateExpression';
  3. readonly tag: Expression;
  4. readonly quasi: TemplateLiteral;
  5. }

with

  1. interface TemplateElement {
  2. type: 'TemplateElement';
  3. value: { cooked: string; raw: string };
  4. tail: boolean;
  5. }
  6.  
  7. interface TemplateLiteral {
  8. type: 'TemplateLiteral';
  9. quasis: TemplateElement[];
  10. expressions: Expression[];
  11. }

Member Expression

  1. interface MemberExpression {
  2. type: 'MemberExpression';
  3. computed: boolean;
  4. object: Expression;
  5. property: Expression;
  6. }

Super

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

MetaProperty

  1. interface MetaProperty {
  2. type: 'MetaProperty';
  3. meta: Identifier;
  4. property: Identifier;
  5. }

Call and New Expressions

  1. interface CallExpression {
  2. type: 'CallExpression';
  3. callee: Expression;
  4. arguments: ArgumentListElement[];
  5. }
  6.  
  7. interface NewExpression {
  8. type: 'NewExpression';
  9. callee: Expression;
  10. arguments: ArgumentListElement[];
  11. }

with

  1. type ArgumentListElement = Expression | SpreadElement;
  2.  
  3. interface SpreadElement {
  4. type: 'SpreadElement';
  5. argument: Expression;
  6. }

Update Expression

  1. interface UpdateExpression {
  2. type: 'UpdateExpression';
  3. operator: '++' | '--';
  4. argument: Expression;
  5. prefix: boolean;
  6. }

Await Expression

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

Unary Expression

  1. interface UnaryExpression {
  2. type: 'UnaryExpression';
  3. operator: '+' | '-' | '~' | '!' | 'delete' | 'void' | 'typeof';
  4. argument: Expression;
  5. prefix: true;
  6. }

Binary Expression

  1. interface BinaryExpression {
  2. type: 'BinaryExpression';
  3. operator: 'instanceof' | 'in' | '+' | '-' | '*' | '/' | '%' | '**' |
  4. '|' | '^' | '&' | '==' | '!=' | '===' | '!==' |
  5. '<' | '>' | '<=' | '<<' | '>>' | '>>>';
  6. left: Expression;
  7. right: Expression;
  8. }

Logical Expression

  1. interface LogicalExpression {
  2. type: 'LogicalExpression';
  3. operator: '||' | '&&';
  4. left: Expression;
  5. right: Expression;
  6. }

Conditional Expression

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

Yield Expression

  1. interface YieldExpression {
  2. type: 'YieldExpression';
  3. argument: Expression | null;
  4. delegate: boolean;
  5. }

Assignment Expression

  1. interface AssignmentExpression {
  2. type: 'AssignmentExpression';
  3. operator: '=' | '*=' | '**=' | '/=' | '%=' | '+=' | '-=' |
  4. '<<=' | '>>=' | '>>>=' | '&=' | '^=' | '|=';
  5. left: Expression;
  6. right: Expression;
  7. }

Sequence Expression

  1. interface SequenceExpression {
  2. type: 'SequenceExpression';
  3. expressions: Expression[];
  4. }