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 7e7766c commit e29f085
Show file tree
Hide file tree
Showing 14 changed files with 599 additions and 727 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ impl FormatRule<AnyTsMethodSignatureModifier> for FormatAnyTsMethodSignatureModi
fn fmt(&self, node: &AnyTsMethodSignatureModifier, f: &mut JsFormatter) -> FormatResult<()> {
match node {
AnyTsMethodSignatureModifier::TsAccessibilityModifier(node) => node.format().fmt(f),
AnyTsMethodSignatureModifier::JsDecorator(node) => node.format().fmt(f),
AnyTsMethodSignatureModifier::JsStaticModifier(node) => node.format().fmt(f),
AnyTsMethodSignatureModifier::TsOverrideModifier(node) => node.format().fmt(f),
AnyTsMethodSignatureModifier::TsAbstractModifier(node) => node.format().fmt(f),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ impl FormatRule<AnyTsPropertySignatureModifier> for FormatAnyTsPropertySignature
AnyTsPropertySignatureModifier::TsDeclareModifier(node) => node.format().fmt(f),
AnyTsPropertySignatureModifier::TsAccessibilityModifier(node) => node.format().fmt(f),
AnyTsPropertySignatureModifier::JsStaticModifier(node) => node.format().fmt(f),
AnyTsPropertySignatureModifier::JsDecorator(node) => node.format().fmt(f),
AnyTsPropertySignatureModifier::JsAccessorModifier(node) => node.format().fmt(f),
AnyTsPropertySignatureModifier::TsReadonlyModifier(node) => node.format().fmt(f),
AnyTsPropertySignatureModifier::TsOverrideModifier(node) => node.format().fmt(f),
Expand Down
31 changes: 17 additions & 14 deletions crates/rome_js_parser/src/syntax/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2141,12 +2141,26 @@ impl ClassMemberModifiers {
| JS_GETTER_CLASS_MEMBER
| JS_SETTER_CLASS_MEMBER
| TS_METHOD_SIGNATURE_CLASS_MEMBER
| TS_GETTER_SIGNATURE_CLASS_MEMBER
| TS_SETTER_SIGNATURE_CLASS_MEMBER
| TS_PROPERTY_SIGNATURE_CLASS_MEMBER
| TS_INITIALIZED_PROPERTY_SIGNATURE_CLASS_MEMBER
)
{
// test ts decorator_parameters_constructor
// class Foo {
// constructor(@dec a: string) {}
// test ts decorator_class_member_in_ts
// abstract class Qux {
// @dec declare static foo: string;
// }
// class Bar {
// @dec readonly foo = '123';
// }
// declare class Foo {
// @dec method();
// }
// declare class Baz {
// @dec method();
// @dec get foo();
// @dec set foo(a);
// }

// test_err ts decorator_class_member
Expand All @@ -2163,17 +2177,6 @@ impl ClassMemberModifiers {
// constructor(a: String)
// constructor(a?: String) {}
// }
// declare class Baz {
// @dec method();
// @dec get foo();
// @dec set foo(a);
// }
// abstract class Qux {
// @dec declare static foo: string;
// }
// class Bar {
// @dec declare foo = '123';
// }
return Some(decorators_not_allowed(p, modifier.as_text_range()));
} else if member_kind == TS_INDEX_SIGNATURE_CLASS_MEMBER
&& !matches!(modifier.kind, ModifierKind::Static | ModifierKind::Readonly)
Expand Down
3 changes: 2 additions & 1 deletion crates/rome_js_parser/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ fn diagnostics_print_correctly() {
pub fn quick_test() {
let code = r#"
class Foo {
@decorator declare a;
@decorator declare a: number;
@decorator declare [b]: number;
}
"#;
let root = parse(code, SourceType::ts());
Expand Down
Loading

0 comments on commit e29f085

Please sign in to comment.