Skip to main content

stylex_transform/transform/fold/
fold_stmts.rs

1use swc_core::{
2  common::comments::Comments,
3  ecma::{ast::Stmt, visit::FoldWith},
4};
5
6use crate::StyleXTransform;
7use stylex_enums::core::TransformationCycle;
8
9impl<C> StyleXTransform<C>
10where
11  C: Comments,
12{
13  pub(crate) fn fold_stmts_impl(&mut self, mut stmts: Vec<Stmt>) -> Vec<Stmt> {
14    if self.state.cycle == TransformationCycle::Skip {
15      return stmts;
16    }
17
18    if self.state.cycle == TransformationCycle::Cleaning {
19      stmts.retain(|stmt| {
20        // We use `matches` macro as this match is trivial.
21        !matches!(stmt, Stmt::Empty(..))
22      });
23
24      stmts
25    } else {
26      stmts.fold_children_with(self)
27    }
28  }
29}