mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
Add { Load, Resolve }
This commit is contained in:
parent
4550f7e1af
commit
f17e49934c
@ -15,6 +15,7 @@ swc_ecma_ast = { version = "0.17.0", path ="../ast" }
|
||||
swc_atoms = { version = "0.2.0", path ="../../atoms" }
|
||||
swc_common = { version = "0.5.0", path ="../../common" }
|
||||
swc_ecma_parser = { version = "0.19", path ="../parser", features = ["verify"] }
|
||||
anyhow = "1.0.26"
|
||||
once_cell = "1"
|
||||
scoped-tls = "1"
|
||||
unicode-xid = "0.2"
|
||||
|
@ -36,7 +36,9 @@ mod macros;
|
||||
pub mod constructor;
|
||||
mod factory;
|
||||
pub mod ident;
|
||||
pub mod load;
|
||||
pub mod options;
|
||||
pub mod resolve;
|
||||
mod value;
|
||||
pub mod var;
|
||||
|
||||
|
20
ecmascript/utils/src/load.rs
Normal file
20
ecmascript/utils/src/load.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use anyhow::Error;
|
||||
use std::{path::Path, sync::Arc};
|
||||
use swc_common::SourceFile;
|
||||
use swc_ecma_ast::Module;
|
||||
|
||||
pub trait Load {
|
||||
fn load(&self, path: &Path) -> Result<(Arc<SourceFile>, Module), Error>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized + Load> Load for Box<T> {
|
||||
fn load(&self, path: &Path) -> Result<(Arc<SourceFile>, Module), Error> {
|
||||
T::load(self, path)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized + Load> Load for &'a T {
|
||||
fn load(&self, path: &Path) -> Result<(Arc<SourceFile>, Module), Error> {
|
||||
T::load(self, path)
|
||||
}
|
||||
}
|
20
ecmascript/utils/src/resolve.rs
Normal file
20
ecmascript/utils/src/resolve.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use anyhow::Error;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub trait Resolve {
|
||||
/// Returned filename will be hashed if possible and used to generate module
|
||||
/// id.
|
||||
fn resolve(&self, base: &Path, import: &str) -> Result<PathBuf, Error>;
|
||||
}
|
||||
|
||||
impl<T: ?Sized + Resolve> Resolve for Box<T> {
|
||||
fn resolve(&self, base: &Path, import: &str) -> Result<PathBuf, Error> {
|
||||
T::resolve(self, base, import)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ?Sized + Resolve> Resolve for &'a T {
|
||||
fn resolve(&self, base: &Path, import: &str) -> Result<PathBuf, Error> {
|
||||
T::resolve(self, base, import)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user