swc_ecma_loader/
resolve.rs

1use std::sync::Arc;
2
3use anyhow::Error;
4use swc_atoms::Atom;
5#[allow(unused_imports)]
6use swc_common::{
7    sync::{Send, Sync},
8    FileName,
9};
10
11#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
12pub struct Resolution {
13    pub filename: FileName,
14    pub slug: Option<Atom>,
15}
16
17pub trait Resolve: Send + Sync {
18    fn resolve(&self, base: &FileName, module_specifier: &str) -> Result<Resolution, Error>;
19}
20
21macro_rules! impl_ref {
22    ($R:ident, $T:ty) => {
23        impl<$R> Resolve for $T
24        where
25            R: ?Sized + Resolve,
26        {
27            fn resolve(&self, base: &FileName, src: &str) -> Result<Resolution, Error> {
28                (**self).resolve(base, src)
29            }
30        }
31    };
32}
33
34impl_ref!(R, &'_ R);
35impl_ref!(R, Box<R>);
36impl_ref!(R, Arc<R>);