1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use std::sync::Arc;

use anyhow::Error;
use swc_atoms::Atom;
#[allow(unused_imports)]
use swc_common::{
    sync::{Send, Sync},
    FileName,
};

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Resolution {
    pub filename: FileName,
    pub slug: Option<Atom>,
}

pub trait Resolve: Send + Sync {
    fn resolve(&self, base: &FileName, module_specifier: &str) -> Result<Resolution, Error>;
}

macro_rules! impl_ref {
    ($R:ident, $T:ty) => {
        impl<$R> Resolve for $T
        where
            R: ?Sized + Resolve,
        {
            fn resolve(&self, base: &FileName, src: &str) -> Result<Resolution, Error> {
                (**self).resolve(base, src)
            }
        }
    };
}

impl_ref!(R, &'_ R);
impl_ref!(R, Box<R>);
impl_ref!(R, Arc<R>);