diff --git a/crates/oxc_semantic/src/checker/javascript.rs b/crates/oxc_semantic/src/checker/javascript.rs index 78991a20cbf44..13cae88b0b719 100644 --- a/crates/oxc_semantic/src/checker/javascript.rs +++ b/crates/oxc_semantic/src/checker/javascript.rs @@ -245,11 +245,19 @@ pub fn check_identifier_reference(ident: &IdentifierReference, ctx: &SemanticBui // It is a Syntax Error if ContainsArguments of ClassStaticBlockStatementList is true. if ident.name == "arguments" { + let mut previous_node_address = ctx.nodes.get_node(ctx.current_node_id).address(); for node_kind in ctx.nodes.ancestor_kinds(ctx.current_node_id) { match node_kind { AstKind::Function(_) => break, - AstKind::PropertyDefinition(_) => { - return ctx.error(unexpected_arguments("class field initializer", ident.span)); + AstKind::PropertyDefinition(prop) => { + if prop + .value + .as_ref() + .is_some_and(|value| value.address() == previous_node_address) + { + return ctx + .error(unexpected_arguments("class field initializer", ident.span)); + } } AstKind::StaticBlock(_) => { return ctx @@ -257,6 +265,7 @@ pub fn check_identifier_reference(ident: &IdentifierReference, ctx: &SemanticBui } _ => {} } + previous_node_address = node_kind.address(); } } } diff --git a/tasks/coverage/snapshots/parser_babel.snap b/tasks/coverage/snapshots/parser_babel.snap index 6631d111b4ebb..63d4ba56a4aa0 100644 --- a/tasks/coverage/snapshots/parser_babel.snap +++ b/tasks/coverage/snapshots/parser_babel.snap @@ -2,7 +2,7 @@ commit: 4cc3d888 parser_babel Summary: AST Parsed : 2422/2440 (99.26%) -Positive Passed: 2395/2440 (98.16%) +Positive Passed: 2396/2440 (98.20%) Negative Passed: 1685/1752 (96.18%) Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/private-in/invalid-private-followed-by-in-2/input.js @@ -266,17 +266,6 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/s 2 │ {} ╰──── -Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/arguments-in-key/input.js - - × 'arguments' is not allowed in class field initializer - ╭─[babel/packages/babel-parser/test/fixtures/es2022/class-properties/arguments-in-key/input.js:3:6] - 2 │ class A { - 3 │ [arguments] = 2; - · ───────── - 4 │ } - ╰──── - help: Assign the 'arguments' variable to a temporary variable outside - Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/new-target/input.js × Unexpected new.target expression diff --git a/tasks/coverage/snapshots/semantic_babel.snap b/tasks/coverage/snapshots/semantic_babel.snap index 37d1fc73433ff..4c91957def2ec 100644 --- a/tasks/coverage/snapshots/semantic_babel.snap +++ b/tasks/coverage/snapshots/semantic_babel.snap @@ -2,7 +2,7 @@ commit: 4cc3d888 semantic_babel Summary: AST Parsed : 2440/2440 (100.00%) -Positive Passed: 2006/2440 (82.21%) +Positive Passed: 2007/2440 (82.25%) semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/valid-assignment-target-type/input.js Cannot assign to this expression @@ -101,9 +101,6 @@ Symbol scope ID mismatch for "_x": after transform: SymbolId(1): ScopeId(1) rebuilt : SymbolId(2): ScopeId(0) -semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/arguments-in-key/input.js -'arguments' is not allowed in class field initializer - semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/await-identifier-in-computed-property-inside-params-of-function-inside-params-of-async-function/input.js Bindings mismatch: after transform: ScopeId(0): ["_asyncToGenerator", "_defineProperty"]