Skip to content

Commit f09c1db

Browse files
committed
fix(parser): allow arguments in the class field keys
1 parent 8b14ec9 commit f09c1db

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

crates/oxc_semantic/src/checker/javascript.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,27 @@ pub fn check_identifier_reference(ident: &IdentifierReference, ctx: &SemanticBui
245245
// It is a Syntax Error if ContainsArguments of ClassStaticBlockStatementList is true.
246246

247247
if ident.name == "arguments" {
248+
let mut previous_node_address = ctx.nodes.get_node(ctx.current_node_id).address();
248249
for node_kind in ctx.nodes.ancestor_kinds(ctx.current_node_id) {
249250
match node_kind {
250251
AstKind::Function(_) => break,
251-
AstKind::PropertyDefinition(_) => {
252-
return ctx.error(unexpected_arguments("class field initializer", ident.span));
252+
AstKind::PropertyDefinition(prop) => {
253+
if prop
254+
.value
255+
.as_ref()
256+
.is_some_and(|value| value.address() == previous_node_address)
257+
{
258+
return ctx
259+
.error(unexpected_arguments("class field initializer", ident.span));
260+
}
253261
}
254262
AstKind::StaticBlock(_) => {
255263
return ctx
256264
.error(unexpected_arguments("static initialization block", ident.span));
257265
}
258266
_ => {}
259267
}
268+
previous_node_address = node_kind.address();
260269
}
261270
}
262271
}

tasks/coverage/snapshots/parser_babel.snap

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ commit: 4cc3d888
22

33
parser_babel Summary:
44
AST Parsed : 2422/2440 (99.26%)
5-
Positive Passed: 2395/2440 (98.16%)
5+
Positive Passed: 2396/2440 (98.20%)
66
Negative Passed: 1685/1752 (96.18%)
77
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/private-in/invalid-private-followed-by-in-2/input.js
88

@@ -266,17 +266,6 @@ Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/core/s
266266
2 │ {}
267267
╰────
268268

269-
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/arguments-in-key/input.js
270-
271-
× 'arguments' is not allowed in class field initializer
272-
╭─[babel/packages/babel-parser/test/fixtures/es2022/class-properties/arguments-in-key/input.js:3:6]
273-
2 │ class A {
274-
3 │ [arguments] = 2;
275-
· ─────────
276-
4 │ }
277-
╰────
278-
help: Assign the 'arguments' variable to a temporary variable outside
279-
280269
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/new-target/input.js
281270

282271
× Unexpected new.target expression

tasks/coverage/snapshots/semantic_babel.snap

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ commit: 4cc3d888
22

33
semantic_babel Summary:
44
AST Parsed : 2440/2440 (100.00%)
5-
Positive Passed: 2006/2440 (82.21%)
5+
Positive Passed: 2007/2440 (82.25%)
66
semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/annex-b/enabled/valid-assignment-target-type/input.js
77
Cannot assign to this expression
88

@@ -101,9 +101,6 @@ Symbol scope ID mismatch for "_x":
101101
after transform: SymbolId(1): ScopeId(1)
102102
rebuilt : SymbolId(2): ScopeId(0)
103103

104-
semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-properties/arguments-in-key/input.js
105-
'arguments' is not allowed in class field initializer
106-
107104
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
108105
Bindings mismatch:
109106
after transform: ScopeId(0): ["_asyncToGenerator", "_defineProperty"]

0 commit comments

Comments
 (0)