Scripts and Modules

A program can be either a script or a module.

  1. interface Program {
  2. type: 'Program';
  3. sourceType: 'script';
  4. body: StatementListItem[];
  5. }
  6.  
  7. interface Program {
  8. type: 'Program';
  9. sourceType: 'module';
  10. body: ModuleItem[];
  11. }

with

  1. type StatementListItem = Declaration | Statement;
  2. type ModuleItem = ImportDeclaration | ExportDeclaration | StatementListItem;

Import Declaration

  1. type ImportDeclaration {
  2. type: 'ImportDeclaration';
  3. specifiers: ImportSpecifier[];
  4. source: Literal;
  5. }

with

  1. interface ImportSpecifier {
  2. type: 'ImportSpecifier' | 'ImportDefaultSpecifier' | 'ImportNamespaceSpecifier';
  3. local: Identifier;
  4. imported?: Identifier;
  5. }

Export Declaration

An export declaration can be in the form of a batch, a default, or a named declaration.

  1. type ExportDeclaration = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration;

Each possible export declaration is described as follows:

  1. interface ExportAllDeclaration {
  2. type: 'ExportAllDeclaration';
  3. source: Literal;
  4. }
  5.  
  6. interface ExportDefaultDeclaration {
  7. type: 'ExportDefaultDeclaration';
  8. declaration: Identifier | BindingPattern | ClassDeclaration | Expression | FunctionDeclaration;
  9. }
  10.  
  11. interface ExportNamedDeclaration {
  12. type: 'ExportNamedDeclaration';
  13. declaration: ClassDeclaration | FunctionDeclaration | VariableDeclaration;
  14. specifiers: ExportSpecifier[];
  15. source: Literal;
  16. }

with

  1. interface ExportSpecifier {
  2. type: 'ExportSpecifier';
  3. exported: Identifier;
  4. local: Identifier;
  5. };