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 27, 2023
1 parent fd86dac commit 716ba53
Show file tree
Hide file tree
Showing 33 changed files with 1,864 additions and 961 deletions.
34 changes: 0 additions & 34 deletions crates/rome_js_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6841,40 +6841,6 @@ impl IntoFormat<JsFormatContext> for rome_js_syntax::TsThisParameter {
)
}
}
impl FormatRule<rome_js_syntax::JsDecorator>
for crate::js::auxiliary::decorator::FormatJsDecorator
{
type Context = JsFormatContext;
#[inline(always)]
fn fmt(&self, node: &rome_js_syntax::JsDecorator, f: &mut JsFormatter) -> FormatResult<()> {
FormatNodeRule::<rome_js_syntax::JsDecorator>::fmt(self, node, f)
}
}
impl AsFormat<JsFormatContext> for rome_js_syntax::JsDecorator {
type Format<'a> = FormatRefWithRule<
'a,
rome_js_syntax::JsDecorator,
crate::js::auxiliary::decorator::FormatJsDecorator,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::js::auxiliary::decorator::FormatJsDecorator::default(),
)
}
}
impl IntoFormat<JsFormatContext> for rome_js_syntax::JsDecorator {
type Format = FormatOwnedWithRule<
rome_js_syntax::JsDecorator,
crate::js::auxiliary::decorator::FormatJsDecorator,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::js::auxiliary::decorator::FormatJsDecorator::default(),
)
}
}
impl FormatRule<rome_js_syntax::TsAnyType> for crate::ts::types::any_type::FormatTsAnyType {
type Context = JsFormatContext;
#[inline(always)]
Expand Down
12 changes: 5 additions & 7 deletions crates/rome_js_formatter/tests/quick_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ mod language {
// use this test check if your snippet prints as you wish, without using a snapshot
fn quick_test() {
let src = r#"
const bar =
(
@deco
class {
//
}
);
class A {
@dec()
// comment
accessor b;
}
"#;
let syntax = SourceType::tsx();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ class Something {
comments.js:4:20 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× return types can only be used in TypeScript files
2 │ @Annotateme()
3 │ // comment
> 4 │ static property: Array<string>;
│ ^^^^^^^^^^^^^^^
5 │ }
6 │
6 │
i remove this type annotation
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ export default @decorator class {}
-@decorator
+export @decorator
class Foo {}

-export default
-@decorator
-class {}
+export default (@decorator
+class {});
+export default @decorator
class {}
```

# Output
Expand All @@ -37,8 +36,8 @@ export default @decorator class {}
export @decorator
class Foo {}

export default (@decorator
class {});
export default @decorator
class {}
```


Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const bar =
@@ -7,18 +7,12 @@
@deco
export default class Baz {}

-const foo =
- (
- @deco
Expand All @@ -45,7 +45,7 @@ const bar =
+class {
+ //
+};

-const bar =
- (
- @deco
Expand Down Expand Up @@ -82,31 +82,4 @@ class {
};
```

# Errors
```
classes.js:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Decorators are not valid here
1 │ @deco class Foo {}
2 │
> 3 │ @deco export class Bar {}
│ ^^^^^
4 │
5 │ @deco export default class Baz {}
classes.js:5:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Decorators are not valid here
3 │ @deco export class Bar {}
4 │
> 5 │ @deco export default class Baz {}
│ ^^^^^
6 │
7 │ const foo = @deco class {
```


This file was deleted.

Loading

0 comments on commit 716ba53

Please sign in to comment.