1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
mod ast;

pub use crate::ast::css;
use crate::ast::css::Ast as CssAst;
pub use crate::ast::javascript;
use crate::ast::javascript::Ast as JsAst;

/**
 *  AST used in first class Module
 */
#[derive(Debug, Clone, Hash)]
pub enum RspackAst {
  JavaScript(JsAst),
  Css(CssAst),
}

impl RspackAst {
  pub fn as_javascript(&self) -> Option<&JsAst> {
    match self {
      RspackAst::JavaScript(program) => Some(program),
      RspackAst::Css(_) => None,
    }
  }

  pub fn as_css(&self) -> Option<&CssAst> {
    match self {
      RspackAst::Css(stylesheet) => Some(stylesheet),
      RspackAst::JavaScript(_) => None,
    }
  }
}