use super::decl::Decl;
use super::expr::{ExprRef, Ident};
use super::literal::StrLit;
use super::node::AstNode;
use super::stmt::Stmt;
use crate::span::Span;
#[derive(Debug, Clone)]
pub struct Module {
pub span: Span,
pub body: Vec<ModuleItem>,
}
#[derive(Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum ModuleItem {
Stmt(Stmt),
Decl(Decl),
Import(ImportDecl),
Export(ExportDecl),
}
#[derive(Debug, Clone)]
pub struct ImportDecl {
pub span: Span,
pub specifiers: Vec<ImportSpecifier>,
pub source: StrLit,
pub is_type_only: bool,
pub assertions: Vec<ImportAttribute>,
}
#[derive(Debug, Clone)]
pub struct ImportAttribute {
pub span: Span,
pub key: ImportAttributeKey,
pub value: StrLit,
}
#[derive(Debug, Clone)]
pub enum ImportAttributeKey {
Ident(Ident),
StrLit(StrLit),
}
#[derive(Debug, Clone)]
pub enum ImportSpecifier {
Default(ImportDefault),
Named(ImportNamed),
Namespace(ImportNamespace),
}
#[derive(Debug, Clone)]
pub struct ImportDefault {
pub span: Span,
pub local: Ident,
}
#[derive(Debug, Clone)]
pub struct ImportNamed {
pub span: Span,
pub imported: Ident,
pub local: Ident,
pub is_type_only: bool,
}
#[derive(Debug, Clone)]
pub struct ImportNamespace {
pub span: Span,
pub local: Ident,
}
#[derive(Debug, Clone)]
pub enum ExportDecl {
Named(ExportNamed),
Default(ExportDefault),
All(ExportAll),
}
#[derive(Debug, Clone)]
pub struct ExportNamed {
pub span: Span,
pub specifiers: Vec<ExportSpecifier>,
pub source: Option<StrLit>,
pub decl: Option<Box<Decl>>,
pub is_type_only: bool,
}
#[derive(Debug, Clone)]
pub struct ExportSpecifier {
pub span: Span,
pub local: Ident,
pub exported: Ident,
pub is_type_only: bool,
}
#[derive(Debug, Clone)]
pub struct ExportDefault {
pub span: Span,
pub decl: ExprRef,
pub has_assign: bool,
}
#[derive(Debug, Clone)]
pub struct ExportAll {
pub span: Span,
pub source: StrLit,
pub is_type_only: bool,
}
impl AstNode for Module {
fn span(&self) -> Span {
self.span
}
}
impl AstNode for ImportDecl {
fn span(&self) -> Span {
self.span
}
}
impl AstNode for ImportAttribute {
fn span(&self) -> Span {
self.span
}
}
impl AstNode for ImportDefault {
fn span(&self) -> Span {
self.span
}
}
impl AstNode for ImportNamed {
fn span(&self) -> Span {
self.span
}
}
impl AstNode for ImportNamespace {
fn span(&self) -> Span {
self.span
}
}
impl AstNode for ExportNamed {
fn span(&self) -> Span {
self.span
}
}
impl AstNode for ExportSpecifier {
fn span(&self) -> Span {
self.span
}
}
impl AstNode for ExportDefault {
fn span(&self) -> Span {
self.span
}
}
impl AstNode for ExportAll {
fn span(&self) -> Span {
self.span
}
}