Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/oxc_semantic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
45 changes: 20 additions & 25 deletions crates/oxc_semantic/src/checker/javascript.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ptr;

use memchr::memchr_iter;
use phf::{Set, phf_set};
use rustc_hash::FxHashMap;

use oxc_allocator::GetAddress;
Expand Down Expand Up @@ -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,
Expand All @@ -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));
_ => {}
}
}

Expand Down
Loading