diff --git a/Cargo.lock b/Cargo.lock index f51c711ae2c3b..b361d6f0251f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2345,7 +2345,6 @@ dependencies = [ "oxc_parser", "oxc_span", "oxc_syntax", - "phf", "rustc-hash", "self_cell", "serde_json", diff --git a/crates/oxc_semantic/Cargo.toml b/crates/oxc_semantic/Cargo.toml index 87ef7377ce497..b05d7a285b16b 100644 --- a/crates/oxc_semantic/Cargo.toml +++ b/crates/oxc_semantic/Cargo.toml @@ -33,14 +33,12 @@ oxc_syntax = { workspace = true } itertools = { workspace = true } memchr = { workspace = true } -phf = { workspace = true, features = ["macros"] } rustc-hash = { workspace = true } self_cell = { workspace = true } [dev-dependencies] insta = { workspace = true, features = ["glob"] } oxc_parser = { workspace = true } -phf = { workspace = true, features = ["macros"] } rustc-hash = { workspace = true } serde_json = { workspace = true } diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index e5390fb432fe7..f3c9a0548d907 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -1,7 +1,6 @@ use std::ptr; use memchr::memchr_iter; -use phf::{Set, phf_set}; use rustc_hash::FxHashMap; use oxc_allocator::GetAddress; @@ -79,18 +78,6 @@ pub fn check_duplicate_class_elements(ctx: &SemanticBuilder<'_>) { }); } -pub const STRICT_MODE_NAMES: Set<&'static str> = phf_set! { - "implements", - "interface", - "let", - "package", - "private", - "protected", - "public", - "static", - "yield", -}; - pub fn check_identifier( name: &str, span: Span, @@ -102,20 +89,28 @@ pub fn check_identifier( { return; } - if name == "await" { - // It is a Syntax Error if the goal symbol of the syntactic grammar is Module and the StringValue of IdentifierName is "await". - if ctx.source_type.is_module() { - return ctx.error(diagnostics::reserved_keyword(name, span)); + + match name { + "await" => { + // It is a Syntax Error if the goal symbol of the syntactic grammar is Module and the StringValue of IdentifierName is "await". + if ctx.source_type.is_module() { + ctx.error(diagnostics::reserved_keyword(name, span)); + } + // It is a Syntax Error if ClassStaticBlockStatementList Contains await is true. + else if ctx.scoping.scope_flags(ctx.current_scope_id).is_class_static_block() { + ctx.error(diagnostics::class_static_block_await(span)); + } } - // It is a Syntax Error if ClassStaticBlockStatementList Contains await is true. - if ctx.scoping.scope_flags(ctx.current_scope_id).is_class_static_block() { - return ctx.error(diagnostics::class_static_block_await(span)); + // TODO: Revisit this match arm when we add `Ident` and pre-hash the identifier names and see if a HashSet + // becomes better for performance again. + "implements" | "interface" | "let" | "package" | "private" | "protected" | "public" + | "static" | "yield" + if ctx.strict_mode() => + { + // It is a Syntax Error if this phrase is contained in strict mode code and the StringValue of IdentifierName is: "implements", "interface", "let", "package", "private", "protected", "public", "static", or "yield". + ctx.error(diagnostics::reserved_keyword(name, span)); } - } - - // It is a Syntax Error if this phrase is contained in strict mode code and the StringValue of IdentifierName is: "implements", "interface", "let", "package", "private", "protected", "public", "static", or "yield". - if ctx.strict_mode() && STRICT_MODE_NAMES.contains(name) { - ctx.error(diagnostics::reserved_keyword(name, span)); + _ => {} } }