swc_estree_compat/babelify/
ident.rs1use copyless::BoxHelper;
2use swc_ecma_ast::{BindingIdent, Ident, IdentName, PrivateName};
3use swc_estree_ast::{Identifier, PrivateName as BabelPrivateName};
4
5use crate::babelify::{Babelify, Context};
6
7impl Babelify for BindingIdent {
8 type Output = Identifier;
9
10 fn babelify(self, ctx: &Context) -> Self::Output {
11 Identifier {
12 type_annotation: self
13 .type_ann
14 .map(|ann| Box::alloc().init(ann.babelify(ctx).into())),
15 ..self.id.babelify(ctx)
16 }
17 }
18}
19
20impl Babelify for Ident {
21 type Output = Identifier;
22
23 fn babelify(self, ctx: &Context) -> Self::Output {
24 Identifier {
25 base: ctx.base(self.span),
26 name: self.sym,
27 optional: Some(self.optional),
28 decorators: Default::default(),
29 type_annotation: Default::default(),
30 }
31 }
32}
33
34impl Babelify for IdentName {
35 type Output = Identifier;
36
37 fn babelify(self, ctx: &Context) -> Self::Output {
38 Identifier {
39 base: ctx.base(self.span),
40 name: self.sym,
41 optional: Default::default(),
42 decorators: Default::default(),
43 type_annotation: Default::default(),
44 }
45 }
46}
47
48impl Babelify for PrivateName {
49 type Output = BabelPrivateName;
50
51 fn babelify(self, ctx: &Context) -> Self::Output {
52 BabelPrivateName {
53 base: ctx.base(self.span),
54 id: Identifier {
55 base: ctx.base(self.span),
56 name: self.name,
57 decorators: Default::default(),
58 optional: Default::default(),
59 type_annotation: None,
60 },
61 }
62 }
63}