Scripts and Modules
A program can be either a script or a module.
- interface Program {
- type: 'Program';
- sourceType: 'script';
- body: StatementListItem[];
- }
- interface Program {
- type: 'Program';
- sourceType: 'module';
- body: ModuleItem[];
- }
with
- type StatementListItem = Declaration | Statement;
- type ModuleItem = ImportDeclaration | ExportDeclaration | StatementListItem;
Import Declaration
- type ImportDeclaration {
- type: 'ImportDeclaration';
- specifiers: ImportSpecifier[];
- source: Literal;
- }
with
- interface ImportSpecifier {
- type: 'ImportSpecifier' | 'ImportDefaultSpecifier' | 'ImportNamespaceSpecifier';
- local: Identifier;
- imported?: Identifier;
- }
Export Declaration
An export declaration can be in the form of a batch, a default, or a named declaration.
- type ExportDeclaration = ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration;
Each possible export declaration is described as follows:
- interface ExportAllDeclaration {
- type: 'ExportAllDeclaration';
- source: Literal;
- }
- interface ExportDefaultDeclaration {
- type: 'ExportDefaultDeclaration';
- declaration: Identifier | BindingPattern | ClassDeclaration | Expression | FunctionDeclaration;
- }
- interface ExportNamedDeclaration {
- type: 'ExportNamedDeclaration';
- declaration: ClassDeclaration | FunctionDeclaration | VariableDeclaration;
- specifiers: ExportSpecifier[];
- source: Literal;
- }
with
- interface ExportSpecifier {
- type: 'ExportSpecifier';
- exported: Identifier;
- local: Identifier;
- };