stylex_transform/shared/utils/js/
check_declaration.rs1use swc_core::{
2 common::EqIgnoreSpan,
3 ecma::ast::{Expr, Ident},
4};
5
6use crate::shared::enums::data_structures::evaluate_result_value::EvaluateResultValue;
7use crate::shared::structures::state::EvaluationState;
8use stylex_constants::constants::evaluation_errors::{UNDEFINED_CONST, unsupported_expression};
9
10use super::evaluate::deopt;
11
12pub(crate) enum DeclarationType {
13 Class,
14 Function,
15}
16
17pub(crate) fn check_ident_declaration(
18 ident: &Ident,
19 declarations_map: &[(DeclarationType, &Vec<Ident>)],
20 state: &mut EvaluationState,
21 path: &Expr,
22) -> Option<EvaluateResultValue> {
23 for (decl_type, declarations) in declarations_map {
24 if declarations.iter().any(|item| item.eq_ignore_span(ident)) {
25 return deopt(
26 path,
27 state,
28 &match decl_type {
29 DeclarationType::Class => unsupported_expression("ClassDeclaration"),
30 DeclarationType::Function => unsupported_expression("FunctionDeclaration"),
31 },
32 );
33 }
34 }
35
36 deopt(path, state, UNDEFINED_CONST)
37}