swc_estree_compat/babelify/
ident.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
54
55
56
57
58
59
60
61
62
63
use copyless::BoxHelper;
use swc_ecma_ast::{BindingIdent, Ident, IdentName, PrivateName};
use swc_estree_ast::{Identifier, PrivateName as BabelPrivateName};

use crate::babelify::{Babelify, Context};

impl Babelify for BindingIdent {
    type Output = Identifier;

    fn babelify(self, ctx: &Context) -> Self::Output {
        Identifier {
            type_annotation: self
                .type_ann
                .map(|ann| Box::alloc().init(ann.babelify(ctx).into())),
            ..self.id.babelify(ctx)
        }
    }
}

impl Babelify for Ident {
    type Output = Identifier;

    fn babelify(self, ctx: &Context) -> Self::Output {
        Identifier {
            base: ctx.base(self.span),
            name: self.sym,
            optional: Some(self.optional),
            decorators: Default::default(),
            type_annotation: Default::default(),
        }
    }
}

impl Babelify for IdentName {
    type Output = Identifier;

    fn babelify(self, ctx: &Context) -> Self::Output {
        Identifier {
            base: ctx.base(self.span),
            name: self.sym,
            optional: Default::default(),
            decorators: Default::default(),
            type_annotation: Default::default(),
        }
    }
}

impl Babelify for PrivateName {
    type Output = BabelPrivateName;

    fn babelify(self, ctx: &Context) -> Self::Output {
        BabelPrivateName {
            base: ctx.base(self.span),
            id: Identifier {
                base: ctx.base(self.span),
                name: self.name,
                decorators: Default::default(),
                optional: Default::default(),
                type_annotation: None,
            },
        }
    }
}