Skip to main content

stylex_transform/shared/enums/data_structures/
flat_compiled_styles_value.rs

1use swc_core::ecma::ast::Expr;
2
3use crate::shared::structures::base_css_type::BaseCSSType;
4use stylex_structures::pair::Pair;
5use stylex_types::structures::injectable_style::InjectableStyle;
6
7use stylex_enums::css_syntax::CSSSyntax;
8
9#[derive(Debug, PartialEq, Clone, Hash)]
10pub enum FlatCompiledStylesValue {
11  String(String),
12  KeyValue(Pair),
13  KeyValues(Vec<Pair>),
14  Null,
15  InjectableStyle(InjectableStyle),
16  Bool(bool),
17  Tuple(String, Box<Expr>, Option<BaseCSSType>),
18  CSSType(String, CSSSyntax, String),
19}
20
21impl FlatCompiledStylesValue {
22  pub(crate) fn as_tuple(&self) -> Option<(&String, &Expr, &Option<BaseCSSType>)> {
23    match self {
24      FlatCompiledStylesValue::Tuple(key, value, css_type) => Some((key, value, css_type)),
25      _ => None,
26    }
27  }
28
29  pub(crate) fn as_string(&self) -> Option<&String> {
30    match self {
31      FlatCompiledStylesValue::String(value) => Some(value),
32      _ => None,
33    }
34  }
35
36  pub(crate) fn as_injectable_style(&self) -> Option<&InjectableStyle> {
37    match self {
38      FlatCompiledStylesValue::InjectableStyle(value) => Some(value),
39      _ => None,
40    }
41  }
42
43  pub(crate) fn _as_bool(&self) -> Option<&bool> {
44    match self {
45      FlatCompiledStylesValue::Bool(value) => Some(value),
46      _ => None,
47    }
48  }
49
50  pub(crate) fn _as_null(&self) -> Option<()> {
51    match self {
52      FlatCompiledStylesValue::Null => Some(()),
53      _ => None,
54    }
55  }
56
57  pub(crate) fn as_key_value(&self) -> Option<&Pair> {
58    match self {
59      FlatCompiledStylesValue::KeyValue(value) => Some(value),
60      _ => None,
61    }
62  }
63  pub(crate) fn as_key_values(&self) -> Option<&Vec<Pair>> {
64    match self {
65      FlatCompiledStylesValue::KeyValues(value) => Some(value),
66      _ => None,
67    }
68  }
69}