Skip to main content

stylex_transform/transform/fold/
fold_export_decl.rs

1use swc_core::{
2  common::comments::Comments,
3  ecma::{
4    ast::{Decl, ExportDecl},
5    visit::FoldWith,
6  },
7};
8
9use crate::{StyleXTransform, shared::utils::common::increase_ident_count_by_count};
10use stylex_enums::core::TransformationCycle;
11
12impl<C> StyleXTransform<C>
13where
14  C: Comments,
15{
16  pub(crate) fn fold_export_decl_impl(&mut self, export_decl: ExportDecl) -> ExportDecl {
17    if self.state.cycle == TransformationCycle::Skip {
18      return export_decl;
19    }
20
21    if self.state.cycle == TransformationCycle::StateFilling
22      && let Decl::Var(var_decl) = &export_decl.decl
23    {
24      for decl in &var_decl.decls {
25        if let Some(ident) = decl.name.as_ident() {
26          // HACK: For preventing removing named export declarations need to increase the count by 2.
27          increase_ident_count_by_count(&mut self.state, ident, 2);
28        }
29      }
30    }
31
32    export_decl.fold_children_with(self)
33  }
34}