use swc_atoms::Atom;
bitflags::bitflags! {
#[derive(Debug, Clone, Copy, Default)]
pub struct Context: u32 {
const IgnoreError = 1 << 0;
const Module = 1 << 1;
const CanBeModule = 1 << 2;
const Strict = 1 << 3;
const ForLoopInit = 1 << 4;
const ForAwaitLoopInit = 1 << 5;
const IncludeInExpr = 1 << 6;
const InAsync = 1 << 7;
const InGenerator = 1 << 8;
const InStaticBlock = 1 << 9;
const IsContinueAllowed = 1 << 10;
const IsBreakAllowed = 1 << 11;
const InType = 1 << 12;
const ShouldNotLexLtOrGtAsType = 1 << 13;
const InDeclare = 1 << 14;
const InCondExpr = 1 << 15;
const WillExpectColonForCond = 1 << 16;
const InClass = 1 << 17;
const InClassField = 1 << 18;
const InFunction = 1 << 19;
const InsideNonArrowFunctionScope = 1 << 20;
const InParameters = 1 << 21;
const HasSuperClass = 1 << 22;
const InPropertyName = 1 << 23;
const InForcedJsxContext = 1 << 24;
const AllowDirectSuper = 1 << 25;
const IgnoreElseClause = 1 << 26;
const DisallowConditionalTypes = 1 << 27;
const AllowUsingDecl = 1 << 28;
const TopLevel = 1 << 29;
const TsModuleBlock = 1 << 30;
const DisallowFlowAnonFnType = 1 << 31;
}
}
impl Context {
#[cfg_attr(not(feature = "verify"), inline(always))]
pub fn is_reserved_word(self, word: &Atom) -> bool {
if !cfg!(feature = "verify") {
return false;
}
match &**word {
"let" => self.contains(Context::Strict),
"await" => {
self.contains(Context::InAsync)
|| self.contains(Context::InStaticBlock)
|| self.contains(Context::Module)
}
"yield" => self.contains(Context::InGenerator) || self.contains(Context::Strict),
"null" | "true" | "false" | "break" | "case" | "catch" | "continue" | "debugger"
| "default" | "do" | "export" | "else" | "finally" | "for" | "function" | "if"
| "return" | "switch" | "throw" | "try" | "var" | "const" | "while" | "with"
| "new" | "this" | "super" | "class" | "extends" | "import" | "in" | "instanceof"
| "typeof" | "void" | "delete" => true,
"enum" => true,
"implements" | "package" | "protected" | "interface" | "private" | "public"
if self.contains(Context::Strict) =>
{
true
}
_ => false,
}
}
}