diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index aeb05f981ef9b..cf52593c7a149 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -979,7 +979,7 @@ pub fn check_for_of_statement(stmt: &ForOfStatement, ctx: &SemanticBuilder<'_>) // ClassStaticBlockBody : ClassStaticBlockStatementList // It is a Syntax Error if ClassStaticBlockStatementList Contains await is true. if stmt.r#await && ctx.scoping.scope_flags(ctx.current_scope_id).is_class_static_block() { - ctx.error(diagnostics::class_static_block_await(stmt.span)); + ctx.error(diagnostics::class_static_block_for_await(stmt.span)); } } diff --git a/crates/oxc_semantic/src/diagnostics.rs b/crates/oxc_semantic/src/diagnostics.rs index 2208fea298b9d..575069b8247cb 100644 --- a/crates/oxc_semantic/src/diagnostics.rs +++ b/crates/oxc_semantic/src/diagnostics.rs @@ -41,6 +41,12 @@ pub fn class_static_block_await(span: Span) -> OxcDiagnostic { OxcDiagnostic::error("Cannot use await in class static initialization block").with_label(span) } +#[cold] +pub fn class_static_block_for_await(span: Span) -> OxcDiagnostic { + OxcDiagnostic::error("Cannot use 'for await' in class static initialization block") + .with_label(span) +} + #[cold] pub fn reserved_keyword(x0: &str, span1: Span) -> OxcDiagnostic { OxcDiagnostic::error(format!("The keyword '{x0}' is reserved")).with_label(span1) diff --git a/tasks/coverage/snapshots/parser_typescript.snap b/tasks/coverage/snapshots/parser_typescript.snap index c9c0e8973d577..c1088cc0ce063 100644 --- a/tasks/coverage/snapshots/parser_typescript.snap +++ b/tasks/coverage/snapshots/parser_typescript.snap @@ -13834,7 +13834,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc 14 │ } ╰──── - × Cannot use await in class static initialization block + × Cannot use 'for await' in class static initialization block ╭─[typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts:5:5] 4 │ static { 5 │ ╭─▶ for await (const nn of nums) { @@ -13843,7 +13843,7 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc 8 │ } ╰──── - × Cannot use await in class static initialization block + × Cannot use 'for await' in class static initialization block ╭─[typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts:14:7] 13 │ static { 14 │ ╭─▶ for await (const nn of nums) {