diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index 3ec7820d9dddc..ffee6f1ee916d 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -981,7 +981,7 @@ 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() { + if stmt.r#await && is_in_class_static_block(ctx) { ctx.error(diagnostics::class_static_block_for_await(stmt.span)); } } diff --git a/tasks/coverage/misc/fail/semantic-for-await-in-block-in-static-block.mjs b/tasks/coverage/misc/fail/semantic-for-await-in-block-in-static-block.mjs new file mode 100644 index 0000000000000..16493bde2119c --- /dev/null +++ b/tasks/coverage/misc/fail/semantic-for-await-in-block-in-static-block.mjs @@ -0,0 +1,7 @@ +class C { + static { + { + for await (const x of y) {} + } + } +} diff --git a/tasks/coverage/snapshots/parser_misc.snap b/tasks/coverage/snapshots/parser_misc.snap index 2b51317fe2d8d..ca663f2031cc0 100644 --- a/tasks/coverage/snapshots/parser_misc.snap +++ b/tasks/coverage/snapshots/parser_misc.snap @@ -1,7 +1,7 @@ parser_misc Summary: AST Parsed : 65/65 (100.00%) Positive Passed: 65/65 (100.00%) -Negative Passed: 134/134 (100.00%) +Negative Passed: 135/135 (100.00%) × Cannot assign to 'arguments' in strict mode ╭─[misc/fail/arguments-eval.ts:1:10] @@ -3807,6 +3807,14 @@ Negative Passed: 134/134 (100.00%) ╰──── help: Wrap this code in a block or use a module + × Cannot use 'for await' in class static initialization block + ╭─[misc/fail/semantic-for-await-in-block-in-static-block.mjs:4:7] + 3 │ { + 4 │ for await (const x of y) {} + · ─────────────────────────── + 5 │ } + ╰──── + × Expected switch clause ╭─[misc/fail/switch-invalid-clause.js:2:3] 1 │ switch (foo) {