swc_estree_compat/swcify/
mod.rs

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::fmt::Debug;

pub use self::ctx::Context;

mod class;
mod ctx;
mod expr;
mod jsx;
mod lit;
mod pat;
mod program;
mod stmt;
mod typescript;

/// Used to convert a babel ast node to
pub trait Swcify {
    type Output: Debug + Send + Sync;

    fn swcify(self, ctx: &Context) -> Self::Output;
}

impl<T> Swcify for Vec<T>
where
    T: Swcify,
{
    type Output = Vec<T::Output>;

    fn swcify(self, ctx: &Context) -> Self::Output {
        self.into_iter().map(|v| v.swcify(ctx)).collect()
    }
}

impl<T> Swcify for Option<T>
where
    T: Swcify,
{
    type Output = Option<T::Output>;

    fn swcify(self, ctx: &Context) -> Self::Output {
        self.map(|v| v.swcify(ctx))
    }
}

impl<T> Swcify for Box<T>
where
    T: Swcify,
{
    type Output = T::Output;

    fn swcify(self, ctx: &Context) -> Self::Output {
        (*self).swcify(ctx)
    }
}