diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index ae4e224ce..723e9a7c4 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -179,6 +179,10 @@ pub const STRICT_MODE_NAMES: Set<&'static str> = phf_set! { }; fn check_identifier<'a>(name: &Atom, span: Span, node: &AstNode<'a>, ctx: &SemanticBuilder<'a>) { + // ts module block allows revered keywords + if ctx.current_scope_flags().is_ts_module_block() { + 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() { diff --git a/crates/oxc_syntax/src/scope.rs b/crates/oxc_syntax/src/scope.rs index d7c118435..545a91ed6 100644 --- a/crates/oxc_syntax/src/scope.rs +++ b/crates/oxc_syntax/src/scope.rs @@ -52,6 +52,10 @@ impl ScopeFlags { self.contains(Self::ClassStaticBlock) } + pub fn is_ts_module_block(&self) -> bool { + self.contains(Self::TsModuleBlock) + } + pub fn is_var(&self) -> bool { self.intersects(Self::Var) } diff --git a/tasks/coverage/parser_typescript.snap b/tasks/coverage/parser_typescript.snap index 3c60c3ee1..9fcf4516b 100644 --- a/tasks/coverage/parser_typescript.snap +++ b/tasks/coverage/parser_typescript.snap @@ -3955,14 +3955,6 @@ Expect to Parse: "conformance/externalModules/topLevelAwait.2.ts" · ───── ╰──── - × The keyword 'await' is reserved - ╭─[conformance/externalModules/topLevelAwait.2.ts:3:1] - 3 │ - 4 │ declare namespace foo { const await: any; } - · ───── - 5 │ - ╰──── - × The keyword 'await' is reserved ╭─[conformance/externalModules/topLevelAwait.2.ts:6:1] 6 │ // await allowed in import=namespace when not a module @@ -15634,14 +15626,6 @@ Expect to Parse: "conformance/salsa/plainJSRedeclare3.ts" · ───── ╰──── - × The keyword 'await' is reserved - ╭─[conformance/externalModules/topLevelAwaitErrors.12.ts:4:1] - 4 │ export {}; - 5 │ declare namespace foo { const await: any; } - · ───── - 6 │ - ╰──── - × The keyword 'await' is reserved ╭─[conformance/externalModules/topLevelAwaitErrors.12.ts:7:1] 7 │ // await disallowed in import=namespace when in a module