#[derive(Clone, Copy)]
pub(super) enum FunctionKind {
Function { is_async: bool, is_generator: bool },
Arrow { is_async: bool },
}
impl FunctionKind {
pub(super) fn is_async(self) -> bool {
match self {
Self::Function { is_async, .. } | Self::Arrow { is_async } => is_async,
}
}
pub(super) fn is_generator(self) -> bool {
matches!(
self,
Self::Function {
is_generator: true,
..
}
)
}
pub(super) fn is_arrow(self) -> bool {
matches!(self, Self::Arrow { .. })
}
}
#[derive(Clone, Copy)]
pub(super) enum StatementGrammar {
Statement,
StatementListItem,
ModuleItem,
}
impl StatementGrammar {
pub(super) fn permits_declaration(self) -> bool {
matches!(self, Self::StatementListItem | Self::ModuleItem)
}
}
pub(super) trait BlockBodyItem: From<swc_ecma_ast::Stmt> {
const GRAMMAR: StatementGrammar;
}
impl BlockBodyItem for swc_ecma_ast::Stmt {
const GRAMMAR: StatementGrammar = StatementGrammar::StatementListItem;
}
impl BlockBodyItem for swc_ecma_ast::ModuleItem {
const GRAMMAR: StatementGrammar = StatementGrammar::ModuleItem;
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Default)]
pub(super) struct GrammarContext: u8 {
const In = 1 << 0;
const Yield = 1 << 1;
const Await = 1 << 2;
const Return = 1 << 3;
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Default)]
pub(super) struct BoundaryContext: u8 {
const CanBeModule = 1 << 0;
const TopLevel = 1 << 1;
const InsideNonArrowFunctionScope = 1 << 2;
const InParameters = 1 << 3;
const InClass = 1 << 4;
const InClassField = 1 << 5;
const InStaticBlock = 1 << 6;
const AllowDirectSuper = 1 << 7;
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub(super) enum SyntaxContext {
#[default]
Program,
Parameters,
FunctionBody,
Nested,
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Default)]
pub(super) struct StatementContext: u8 {
const IsContinueAllowed = 1 << 0;
const IsBreakAllowed = 1 << 1;
const IgnoreElseClause = 1 << 2;
const AllowUsingDecl = 1 << 3;
}
}
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Default)]
pub(super) struct TypeContext: u8 {
const InDeclare = 1 << 0;
const WillExpectColonForCond = 1 << 1;
const DisallowConditionalTypes = 1 << 2;
const TsModuleBlock = 1 << 3;
const DisallowFlowAnonFnType = 1 << 4;
const InType = 1 << 5;
const TsContainerBody = 1 << 6;
}
}