Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
feat(rome_js_parser): EcmaScript @decorators #4252
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov committed Apr 30, 2023
1 parent 35a60af commit b773a24
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
6 changes: 6 additions & 0 deletions crates/rome_js_parser/src/syntax/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,12 @@ fn parse_constructor_parameter(p: &mut JsParser, context: ExpressionContext) ->
// test_err class_constructor_parameter
// class B { constructor(protected b) {} }

// test ts ts_decorator_constructor
// class C {
// constructor(@foo readonly x: number) {}
// }
skip_ts_decorators(p);

if is_nth_at_modifier(p, 0, true) {
// test ts ts_property_parameter
// class A { constructor(private x, protected y, public z) {} }
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_js_parser/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ fn diagnostics_print_correctly() {
#[test]
pub fn quick_test() {
let code = r#"
class A {
@(dec()) private method(){}
class C {
constructor(@foo readonly x: number) {}
}
"#;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
JsModule {
interpreter_token: missing (optional),
directives: JsDirectiveList [],
items: JsModuleItemList [
JsClassDeclaration {
decorators: JsDecoratorList [],
abstract_token: missing (optional),
class_token: [email protected] "class" [] [Whitespace(" ")],
id: JsIdentifierBinding {
name_token: [email protected] "C" [] [Whitespace(" ")],
},
type_parameters: missing (optional),
extends_clause: missing (optional),
implements_clause: missing (optional),
l_curly_token: [email protected] "{" [] [],
members: JsClassMemberList [
JsConstructorClassMember {
modifiers: JsConstructorModifierList [],
name: JsLiteralMemberName {
value: [email protected] "constructor" [Newline("\n"), Whitespace(" ")] [],
},
parameters: JsConstructorParameters {
l_paren_token: [email protected] "(" [] [],
parameters: JsConstructorParameterList [
TsPropertyParameter {
modifiers: TsPropertyParameterModifierList [
TsReadonlyModifier {
modifier_token: [email protected] "readonly" [Skipped("@"), Skipped("foo"), Whitespace(" ")] [Whitespace(" ")],
},
],
formal_parameter: JsFormalParameter {
binding: JsIdentifierBinding {
name_token: [email protected] "x" [] [],
},
question_mark_token: missing (optional),
type_annotation: TsTypeAnnotation {
colon_token: [email protected] ":" [] [Whitespace(" ")],
ty: TsNumberType {
number_token: [email protected] "number" [] [],
},
},
initializer: missing (optional),
},
},
],
r_paren_token: [email protected] ")" [] [Whitespace(" ")],
},
body: JsFunctionBody {
l_curly_token: [email protected] "{" [] [],
directives: JsDirectiveList [],
statements: JsStatementList [],
r_curly_token: [email protected] "}" [] [],
},
},
],
r_curly_token: [email protected] "}" [Newline("\n")] [],
},
],
eof_token: [email protected] "" [Newline("\n")] [],
}

0: [email protected]
0: (empty)
1: [email protected]
2: [email protected]
0: [email protected]
0: [email protected]
1: (empty)
2: [email protected] "class" [] [Whitespace(" ")]
3: [email protected]
0: [email protected] "C" [] [Whitespace(" ")]
4: (empty)
5: (empty)
6: (empty)
7: [email protected] "{" [] []
8: [email protected]
0: [email protected]
0: [email protected]
1: [email protected]
0: [email protected] "constructor" [Newline("\n"), Whitespace(" ")] []
2: [email protected]
0: [email protected] "(" [] []
1: [email protected]
0: [email protected]
0: [email protected]
0: [email protected]
0: [email protected] "readonly" [Skipped("@"), Skipped("foo"), Whitespace(" ")] [Whitespace(" ")]
1: [email protected]
0: [email protected]
0: [email protected] "x" [] []
1: (empty)
2: [email protected]
0: [email protected] ":" [] [Whitespace(" ")]
1: [email protected]
0: [email protected] "number" [] []
3: (empty)
2: [email protected] ")" [] [Whitespace(" ")]
3: [email protected]
0: [email protected] "{" [] []
1: [email protected]
2: [email protected]
3: [email protected] "}" [] []
9: [email protected] "}" [Newline("\n")] []
3: [email protected] "" [Newline("\n")] []
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class C {
constructor(@foo readonly x: number) {}
}

0 comments on commit b773a24

Please sign in to comment.