fix(parser): allow in expressions in class static blocks (#26423)

Class static blocks inherit the disabled `in` context of a surrounding `for` initializer, causing valid code such as `for (class { static { a in b; } };;);` to report a missing semicolon at `in`. Enable `Context::In` while parsing the static block, with the existing context helper restoring the surrounding flags afterward.
This commit is contained in:
camc314
2026-09-07 18:06:57 +00:00
parent 598618793c
commit cfa47ab396
8 changed files with 18 additions and 13 deletions
+1 -1
View File
@@ -400,7 +400,7 @@ impl<'a, C: Config> ParserImpl<'a, C> {
fn parse_class_static_block(&mut self, start: u32) -> ClassElement<'a> {
self.bump_any(); // bump `static`
let block = self.context(
Context::Await | Context::NewTarget,
Context::In | Context::Await | Context::NewTarget,
Context::Yield | Context::Return,
Self::parse_block,
);
@@ -0,0 +1,5 @@
for (class { static { a in b; } };;);
for (let C = class { static { a in b; } };;);
// Restore the outer initializer's disabled `in` context after the static block.
for (class { static { a in b; } }.x in c);
+2 -2
View File
@@ -1,3 +1,3 @@
codegen_misc Summary:
AST Parsed : 90/90 (100.00%)
Positive Passed: 90/90 (100.00%)
AST Parsed : 91/91 (100.00%)
Positive Passed: 91/91 (100.00%)
+2 -2
View File
@@ -1,3 +1,3 @@
formatter_misc Summary:
AST Parsed : 90/90 (100.00%)
Positive Passed: 90/90 (100.00%)
AST Parsed : 91/91 (100.00%)
Positive Passed: 91/91 (100.00%)
+2 -2
View File
@@ -1,3 +1,3 @@
lexer_misc Summary:
AST Parsed : 280/280 (100.00%)
Positive Passed: 280/280 (100.00%)
AST Parsed : 281/281 (100.00%)
Positive Passed: 281/281 (100.00%)
+2 -2
View File
@@ -1,6 +1,6 @@
parser_misc Summary:
AST Parsed : 90/90 (100.00%)
Positive Passed: 90/90 (100.00%)
AST Parsed : 91/91 (100.00%)
Positive Passed: 91/91 (100.00%)
Negative Passed: 190/190 (100.00%)
× Cannot assign to 'arguments' in strict mode
+2 -2
View File
@@ -1,6 +1,6 @@
semantic_misc Summary:
AST Parsed : 90/90 (100.00%)
Positive Passed: 86/90 (95.56%)
AST Parsed : 91/91 (100.00%)
Positive Passed: 87/91 (95.60%)
semantic Error: tasks/coverage/misc/pass/declare-let-private.ts
Bindings mismatch:
after transform: ScopeId(0): ["private"]
@@ -1,3 +1,3 @@
transformer_misc Summary:
AST Parsed : 90/90 (100.00%)
Positive Passed: 90/90 (100.00%)
AST Parsed : 91/91 (100.00%)
Positive Passed: 91/91 (100.00%)