-
-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
81 changed files
with
1,941 additions
and
620 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Export declaration AST nodes. | ||
//! | ||
//! This module contains `export` declaration AST nodes. | ||
//! | ||
//! More information: | ||
//! - [MDN documentation][mdn] | ||
//! - [ECMAScript specification][spec] | ||
//! | ||
//! [spec]: https://tc39.es/ecma262/#sec-exports | ||
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export | ||
use boa_interner::Sym; | ||
|
||
/// An export declaration AST node. | ||
/// | ||
/// More information: | ||
/// - [ECMAScript specification][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#prod-ExportDeclaration | ||
#[derive(Debug, Clone, Copy)] | ||
pub enum ExportDeclaration { | ||
/// List of exports. | ||
ExportList, | ||
} | ||
|
||
/// Export specifier | ||
/// | ||
/// More information: | ||
/// - [ECMAScript specification][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#prod-ExportSpecifier | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct ExportSpecifier { | ||
export_name: Sym, | ||
alias: Option<Sym>, | ||
} | ||
|
||
impl ExportSpecifier { | ||
/// Creates a new [`ExportSpecifier`]. | ||
#[inline] | ||
#[must_use] | ||
pub const fn new(export_name: Sym, alias: Option<Sym>) -> Self { | ||
Self { export_name, alias } | ||
} | ||
|
||
/// Gets the original export name. | ||
#[inline] | ||
#[must_use] | ||
pub const fn export_name(self) -> Sym { | ||
self.export_name | ||
} | ||
|
||
/// Gets an optional export alias for the export. | ||
#[inline] | ||
#[must_use] | ||
pub const fn alias(self) -> Option<Sym> { | ||
self.alias | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
//! Import declaration AST nodes. | ||
//! | ||
//! This module contains `import` declaration AST nodes. | ||
//! | ||
//! More information: | ||
//! - [MDN documentation][mdn] | ||
//! - [ECMAScript specification][spec] | ||
//! | ||
//! [spec]: https://tc39.es/ecma262/#sec-imports | ||
//! [mdn]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import | ||
use crate::expression::Identifier; | ||
use boa_interner::Sym; | ||
|
||
/// An import declaration AST node. | ||
/// | ||
/// More information: | ||
/// - [ECMAScript specification][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#prod-ImportDeclaration | ||
#[derive(Debug, Clone)] | ||
pub enum ImportDeclaration { | ||
/// Full module import (`import "module-name"`). | ||
Module(Sym), | ||
/// Namespace import (`import * as name from "module-name"`), with an optional default export | ||
/// binding. | ||
Namespace { | ||
/// Optional default export for the namespace import. | ||
default_export: Option<Identifier>, | ||
/// Alias for the namespace import. | ||
alias: Identifier, | ||
/// From clause. | ||
from_clause: FromClause, | ||
}, | ||
/// Import list (`import { export1, export2 as alias2} from "module-name"`), with an optional | ||
/// default export binding. | ||
ImportList { | ||
/// Optional default export for the import list. | ||
default_export: Option<Identifier>, | ||
/// List of imports. | ||
import_list: Box<[ImportSpecifier]>, | ||
/// From clause. | ||
from_clause: FromClause, | ||
}, | ||
} | ||
|
||
impl ImportDeclaration { | ||
/// Creates a new namespace import declaration. | ||
#[inline] | ||
pub fn namespace<F>( | ||
default_export: Option<Identifier>, | ||
alias: Identifier, | ||
from_clause: F, | ||
) -> Self | ||
where | ||
F: Into<FromClause>, | ||
{ | ||
Self::Namespace { | ||
default_export, | ||
alias, | ||
from_clause: from_clause.into(), | ||
} | ||
} | ||
|
||
/// Creates a new namespace import declaration. | ||
#[inline] | ||
pub fn import_list<L, F>( | ||
default_export: Option<Identifier>, | ||
import_list: L, | ||
from_clause: F, | ||
) -> Self | ||
where | ||
L: Into<Box<[ImportSpecifier]>>, | ||
F: Into<FromClause>, | ||
{ | ||
Self::ImportList { | ||
default_export, | ||
import_list: import_list.into(), | ||
from_clause: from_clause.into(), | ||
} | ||
} | ||
} | ||
|
||
/// Import specifier | ||
/// | ||
/// More information: | ||
/// - [ECMAScript specification][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#prod-ImportSpecifier | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct ImportSpecifier { | ||
import_name: Sym, | ||
alias: Option<Identifier>, | ||
} | ||
|
||
impl ImportSpecifier { | ||
/// Creates a new [`ImportSpecifier`]. | ||
#[inline] | ||
#[must_use] | ||
pub const fn new(import_name: Sym, alias: Option<Identifier>) -> Self { | ||
Self { import_name, alias } | ||
} | ||
|
||
/// Gets the original import name. | ||
#[inline] | ||
#[must_use] | ||
pub const fn import_name(self) -> Sym { | ||
self.import_name | ||
} | ||
|
||
/// Gets an optional import alias for the import. | ||
#[inline] | ||
#[must_use] | ||
pub const fn alias(self) -> Option<Identifier> { | ||
self.alias | ||
} | ||
} | ||
|
||
/// From clause AST node. | ||
/// | ||
/// More information: | ||
/// - [ECMAScript specification][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#prod-FromClause | ||
#[derive(Debug, Clone, Copy)] | ||
pub struct FromClause { | ||
module: Sym, | ||
} | ||
|
||
impl FromClause { | ||
/// Gets the module specifier for the from clause. | ||
#[inline] | ||
#[must_use] | ||
pub const fn module(self) -> Sym { | ||
self.module | ||
} | ||
} | ||
|
||
impl From<Sym> for FromClause { | ||
#[inline] | ||
fn from(s: Sym) -> Self { | ||
Self { module: s } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
//! Module item list AST nodes. | ||
//! | ||
//! More information: | ||
//! - [ECMAScript specification][spec] | ||
//! | ||
//! [spec]: https://tc39.es/ecma262/#sec-modules | ||
use crate::{ | ||
declaration::{ExportDeclaration, ImportDeclaration}, | ||
StatementListItem, | ||
}; | ||
|
||
/// Module item list AST node. | ||
/// | ||
/// It contains a list of | ||
/// | ||
/// More information: | ||
/// - [ECMAScript specification][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#prod-ModuleItemList | ||
#[derive(Debug, Clone)] | ||
pub struct ModuleItemList { | ||
items: Box<[ModuleItem]>, | ||
} | ||
|
||
impl ModuleItemList { | ||
/// Gets the list of module items. | ||
#[inline] | ||
#[must_use] | ||
pub const fn items(&self) -> &[ModuleItem] { | ||
&self.items | ||
} | ||
} | ||
|
||
impl<T> From<T> for ModuleItemList | ||
where | ||
T: Into<Box<[ModuleItem]>>, | ||
{ | ||
#[inline] | ||
fn from(items: T) -> Self { | ||
Self { | ||
items: items.into(), | ||
} | ||
} | ||
} | ||
|
||
/// Module item AST node. | ||
/// | ||
/// This is an extension over a [`StatementList`], which can also include multiple | ||
/// [`ImportDeclaration`] and [`ExportDeclaration`] nodes. | ||
/// | ||
/// More information: | ||
/// - [ECMAScript specification][spec] | ||
/// | ||
/// [spec]: https://tc39.es/ecma262/#prod-ModuleItem | ||
#[derive(Debug, Clone)] | ||
pub enum ModuleItem { | ||
/// See [`ImportDeclaration`]. | ||
ImportDeclaration(ImportDeclaration), | ||
/// See [`ExportDeclaration`]. | ||
ExportDeclaration(ExportDeclaration), | ||
/// See [`StatementListItem`]. | ||
StatementListItem(StatementListItem), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.