swc_ecma_lexer/common/parser/
is_directive.rs

1use swc_ecma_ast::{ModuleItem, Stmt};
2
3pub trait IsDirective {
4    fn as_ref(&self) -> Option<&Stmt>;
5    fn is_use_strict(&self) -> bool {
6        self.as_ref().is_some_and(Stmt::is_use_strict)
7    }
8}
9
10impl<T> IsDirective for Box<T>
11where
12    T: IsDirective,
13{
14    fn as_ref(&self) -> Option<&Stmt> {
15        T::as_ref(&**self)
16    }
17}
18
19impl IsDirective for Stmt {
20    fn as_ref(&self) -> Option<&Stmt> {
21        Some(self)
22    }
23}
24
25impl IsDirective for ModuleItem {
26    fn as_ref(&self) -> Option<&Stmt> {
27        match *self {
28            ModuleItem::Stmt(ref s) => Some(s),
29            _ => None,
30        }
31    }
32}