fix(parser): unexpected ts type annotation in get/set (#1942)

fix: https://github.com/oxc-project/oxc/issues/1939
This commit is contained in:
Dunqing 2024-01-08 15:07:43 +08:00 committed by GitHub
parent b97a536df7
commit b50c5ec623
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 1 deletions

View file

@ -294,6 +294,10 @@ impl<'a> Parser<'a> {
}
Ok(definition)
} else {
// getter and setter has no ts type annotation
if !kind.is_method() {
return Err(self.unexpected());
}
let definition = self.parse_class_property_definition(
span,
key,

View file

@ -0,0 +1,5 @@
class Foo {
get x: () => {
return 5;
}
}

View file

@ -0,0 +1,3 @@
class Foo {
set x: (v: number) => {}
}

View file

@ -1,12 +1,28 @@
parser_misc Summary:
AST Parsed : 9/9 (100.00%)
Positive Passed: 9/9 (100.00%)
Negative Passed: 3/3 (100.00%)
Negative Passed: 5/5 (100.00%)
× Unexpected token
╭─[fail/oxc-169.js:1:1]
1 │ 1<(V=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V=uIV=82<<t-j0<(V=$<LBI<(V=ut<I<(V=$<LBI<(V<II>
╰────
× Unexpected token
╭─[fail/oxc-1942-1.ts:1:1]
1 │ class Foo {
2 │ get x: () => {
· ─
3 │ return 5;
╰────
× Unexpected token
╭─[fail/oxc-1942-2.ts:1:1]
1 │ class Foo {
2 │ set x: (v: number) => {}
· ─
3 │ }
╰────
× Empty parenthesized expression
╭─[fail/oxc-232.js:1:1]
1 │ x = (/* a */)