diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index a360e5d27409d..aeb05f981ef9b 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -975,6 +975,14 @@ pub fn check_for_statement_left( } } +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)); + } +} + pub fn check_class(class: &Class, ctx: &SemanticBuilder<'_>) { check_private_identifier(ctx); diff --git a/crates/oxc_semantic/src/checker/mod.rs b/crates/oxc_semantic/src/checker/mod.rs index f0ff1127d4719..445a02b56a899 100644 --- a/crates/oxc_semantic/src/checker/mod.rs +++ b/crates/oxc_semantic/src/checker/mod.rs @@ -61,6 +61,7 @@ pub fn check<'a>(kind: AstKind<'a>, ctx: &SemanticBuilder<'a>) { } AstKind::ForOfStatement(stmt) => { js::check_function_declaration(&stmt.body, false, ctx); + js::check_for_of_statement(stmt, ctx); js::check_for_statement_left(&stmt.left, false, ctx); ts::check_for_statement_left(&stmt.left, false, ctx); } diff --git a/tasks/coverage/snapshots/parser_typescript.snap b/tasks/coverage/snapshots/parser_typescript.snap index a8e19430b5b07..7bccdd1144c9d 100644 --- a/tasks/coverage/snapshots/parser_typescript.snap +++ b/tasks/coverage/snapshots/parser_typescript.snap @@ -3,7 +3,7 @@ commit: 34725489 parser_typescript Summary: AST Parsed : 9831/9834 (99.97%) Positive Passed: 9820/9834 (99.86%) -Negative Passed: 1527/2578 (59.23%) +Negative Passed: 1528/2578 (59.27%) Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/FunctionDeclaration3.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/compiler/FunctionDeclaration4.ts @@ -1006,8 +1006,6 @@ Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/c Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/classExpressions/classWithStaticFieldInParameterInitializer.2.ts -Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock23.ts - Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/constructorDeclarations/classConstructorOverloadsAccessibility.ts Expect Syntax Error: tasks/coverage/typescript/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorDefaultValuesReferencingThis.ts @@ -13820,6 +13818,24 @@ Expect to Parse: tasks/coverage/typescript/tests/cases/conformance/parser/ecmasc 14 │ } ╰──── + × Cannot use 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) { + 6 │ │ console.log(nn) + 7 │ ╰─▶ } + 8 │ } + ╰──── + + × Cannot use 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) { + 15 │ │ console.log(nn) + 16 │ ╰─▶ } + 17 │ } + ╰──── + × Unexpected token ╭─[typescript/tests/cases/conformance/classes/classStaticBlock/classStaticBlock26.ts:3:14] 2 │ static {