Skip to main content

stylex_transform/transform/fold/
fold_decl.rs

1use swc_core::{
2  common::comments::Comments,
3  ecma::{ast::Decl, utils::drop_span, visit::FoldWith},
4};
5
6use crate::StyleXTransform;
7
8impl<C> StyleXTransform<C>
9where
10  C: Comments,
11{
12  pub(crate) fn fold_decl_impl(&mut self, decl: Decl) -> Decl {
13    match &decl {
14      Decl::Class(class_decl) => {
15        let class_decl_ident = drop_span(class_decl.ident.clone());
16
17        if !self
18          .state
19          .class_name_declarations
20          .contains(&class_decl_ident)
21        {
22          self.state.class_name_declarations.push(class_decl_ident);
23        }
24      },
25      Decl::Fn(fn_decl) => {
26        let fn_decl_ident = drop_span(fn_decl.ident.clone());
27
28        if !self
29          .state
30          .function_name_declarations
31          .contains(&fn_decl_ident)
32        {
33          self.state.function_name_declarations.push(fn_decl_ident);
34        }
35      },
36      _ => {},
37    }
38
39    decl.fold_children_with(self)
40  }
41}