Skip to content

Commit

Permalink
feat(rome_js_parser): EcmaScript @decorators rome#4252
Browse files Browse the repository at this point in the history
Implement basic decorator cases for classes
  • Loading branch information
denbezrukov committed Apr 8, 2023
1 parent f6ada3a commit 41265f0
Show file tree
Hide file tree
Showing 207 changed files with 6,795 additions and 2,469 deletions.
33 changes: 33 additions & 0 deletions crates/rome_js_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 51 additions & 3 deletions crates/rome_js_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions crates/rome_js_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6807,6 +6807,40 @@ 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 Expand Up @@ -9843,6 +9877,31 @@ impl IntoFormat<JsFormatContext> for rome_js_syntax::JsConstructorParameterList
)
}
}
impl AsFormat<JsFormatContext> for rome_js_syntax::JsDecoratorList {
type Format<'a> = FormatRefWithRule<
'a,
rome_js_syntax::JsDecoratorList,
crate::js::lists::decorator_list::FormatJsDecoratorList,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::js::lists::decorator_list::FormatJsDecoratorList::default(),
)
}
}
impl IntoFormat<JsFormatContext> for rome_js_syntax::JsDecoratorList {
type Format = FormatOwnedWithRule<
rome_js_syntax::JsDecoratorList,
crate::js::lists::decorator_list::FormatJsDecoratorList,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::js::lists::decorator_list::FormatJsDecoratorList::default(),
)
}
}
impl AsFormat<JsFormatContext> for rome_js_syntax::JsDirectiveList {
type Format<'a> = FormatRefWithRule<
'a,
Expand Down
10 changes: 10 additions & 0 deletions crates/rome_js_formatter/src/js/auxiliary/decorator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use crate::prelude::*;
use rome_js_syntax::JsDecorator;
use rome_rowan::AstNode;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatJsDecorator;
impl FormatNodeRule<JsDecorator> for FormatJsDecorator {
fn fmt_fields(&self, node: &JsDecorator, f: &mut JsFormatter) -> FormatResult<()> {
format_verbatim_node(node.syntax()).fmt(f)
}
}
1 change: 1 addition & 0 deletions crates/rome_js_formatter/src/js/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub(crate) mod accessor_modifier;
pub(crate) mod array_hole;
pub(crate) mod case_clause;
pub(crate) mod catch_clause;
pub(crate) mod decorator;
pub(crate) mod default_clause;
pub(crate) mod directive;
pub(crate) mod else_clause;
Expand Down
12 changes: 12 additions & 0 deletions crates/rome_js_formatter/src/js/lists/decorator_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::prelude::*;
use rome_js_syntax::JsDecoratorList;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatJsDecoratorList;
impl FormatRule<JsDecoratorList> for FormatJsDecoratorList {
type Context = JsFormatContext;
fn fmt(&self, node: &JsDecoratorList, f: &mut JsFormatter) -> FormatResult<()> {
f.join_with(&soft_line_break_or_space())
.entries(node.iter().formatted())
.finish()
}
}
1 change: 1 addition & 0 deletions crates/rome_js_formatter/src/js/lists/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub(crate) mod call_argument_list;
pub(crate) mod class_member_list;
pub(crate) mod constructor_modifier_list;
pub(crate) mod constructor_parameter_list;
pub(crate) mod decorator_list;
pub(crate) mod directive_list;
pub(crate) mod export_named_from_specifier_list;
pub(crate) mod export_named_specifier_list;
Expand Down
3 changes: 3 additions & 0 deletions crates/rome_js_formatter/src/utils/format_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl<'a> From<&'a AnyJsClass> for FormatClass<'a> {

impl Format<JsFormatContext> for FormatClass<'_> {
fn fmt(&self, f: &mut Formatter<JsFormatContext>) -> FormatResult<()> {
let decorators = self.class.decorators();
let abstract_token = self.class.abstract_token();
let id = self.class.id()?;
let extends = self.class.extends_clause();
Expand All @@ -52,6 +53,8 @@ impl Format<JsFormatContext> for FormatClass<'_> {

let group_mode = self.should_group(f.comments())?;

write!(f, [decorators.format()])?;

if let Some(abstract_token) = abstract_token {
write!(f, [abstract_token.format(), space()])?;
}
Expand Down
Loading

0 comments on commit 41265f0

Please sign in to comment.