Bug 209675 - [JSC] public-class-field should accept "get" / "set" fields
Summary: [JSC] public-class-field should accept "get" / "set" fields
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Yusuke Suzuki
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-27 12:16 PDT by Yusuke Suzuki
Modified: 2021-02-01 02:41 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2020-03-27 12:16:31 PDT
Example code.

class A {
static
async
get
test() { }
}
Comment 1 Yusuke Suzuki 2020-03-27 12:17:41 PDT
Exception: SyntaxError: Unexpected identifier 'get'. Expected an opening '(' before a method's parameter list.
Comment 2 Caio Lima 2020-03-28 08:25:22 PDT
(In reply to Yusuke Suzuki from comment #1)
> Exception: SyntaxError: Unexpected identifier 'get'. Expected an opening '('
> before a method's parameter list.

This is a tricky one, but I'm not sure if this is a legit bug. The message may sound  confusing, but we could see this as the following program when we apply automatic semicolon insertion (ASI):

```
class A {
static
async;
get
test() { }
}
```

Since we don't support static class fields yet, the syntax error seems correct, given it is expected `function` or `PropertyName` after `async`(https://tc39.es/ecma262/#prod-AsyncFunctionDeclaration). A case that we could derivate from given example that parses correctly is:

```
class A {
async
get
test() { }
}
```

This should result in an object with field `async` and `get test`. We can define `get`
and `set` as field, but a `FieldDefinition` requires a semicolon (https://tc39.es/proposal-class-fields/#prod-ClassElement). Since `get` or `set` aren't restricted tokens, there is no ASI there and they are parsed as a setter/getter definition. I remember adding some tests for cases of `get`, `set`, `async` and `static` as field names, but I need to double check if it was here or in Test262. Anyway, increasing test coverage is almost never a bad idea.
Comment 3 Yusuke Suzuki 2021-02-01 02:41:13 PST
It is fixed at some point.