Skip to main content

stylex_transform/transform/stylex/
transform_stylex_call.rs

1use swc_core::{
2  common::comments::Comments,
3  ecma::ast::{CallExpr, Callee, Expr},
4};
5
6use crate::{
7  StyleXTransform,
8  shared::utils::core::{stylex::stylex, stylex_merge::stylex_merge},
9};
10use stylex_structures::named_import_source::ImportSources;
11
12impl<C> StyleXTransform<C>
13where
14  C: Comments,
15{
16  pub(crate) fn transform_stylex_call(&mut self, call: &mut CallExpr) -> Option<Expr> {
17    match &call.callee {
18      Callee::Expr(expr) => match expr.as_ref() {
19        Expr::Ident(ident) => {
20          if self
21            .state
22            .stylex_import
23            .contains(&ImportSources::Regular(ident.sym.to_string()))
24            && let Some(value) = stylex_merge(call, stylex, &mut self.state)
25          {
26            return Some(value);
27          }
28          None
29        },
30        _ => None,
31      },
32      _ => None,
33    }
34  }
35}