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 17, 2023
1 parent 309d186 commit 1f319e1
Show file tree
Hide file tree
Showing 210 changed files with 8,656 additions and 2,063 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.

84 changes: 84 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 Expand Up @@ -12100,6 +12159,31 @@ impl IntoFormat<JsFormatContext> for rome_js_syntax::AnyJsCallArgument {
)
}
}
impl AsFormat<JsFormatContext> for rome_js_syntax::AnyJsDecorator {
type Format<'a> = FormatRefWithRule<
'a,
rome_js_syntax::AnyJsDecorator,
crate::js::any::decorator::FormatAnyJsDecorator,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::js::any::decorator::FormatAnyJsDecorator::default(),
)
}
}
impl IntoFormat<JsFormatContext> for rome_js_syntax::AnyJsDecorator {
type Format = FormatOwnedWithRule<
rome_js_syntax::AnyJsDecorator,
crate::js::any::decorator::FormatAnyJsDecorator,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::js::any::decorator::FormatAnyJsDecorator::default(),
)
}
}
impl AsFormat<JsFormatContext> for rome_js_syntax::AnyTsName {
type Format<'a> =
FormatRefWithRule<'a, rome_js_syntax::AnyTsName, crate::ts::any::name::FormatAnyTsName>;
Expand Down
18 changes: 18 additions & 0 deletions crates/rome_js_formatter/src/js/any/decorator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file.

use crate::prelude::*;
use rome_js_syntax::AnyJsDecorator;
#[derive(Debug, Clone, Default)]
pub(crate) struct FormatAnyJsDecorator;
impl FormatRule<AnyJsDecorator> for FormatAnyJsDecorator {
type Context = JsFormatContext;
fn fmt(&self, node: &AnyJsDecorator, f: &mut JsFormatter) -> FormatResult<()> {
match node {
AnyJsDecorator::JsParenthesizedExpression(node) => node.format().fmt(f),
AnyJsDecorator::JsCallExpression(node) => node.format().fmt(f),
AnyJsDecorator::JsStaticMemberExpression(node) => node.format().fmt(f),
AnyJsDecorator::JsIdentifierExpression(node) => node.format().fmt(f),
AnyJsDecorator::JsBogusExpression(node) => node.format().fmt(f),
}
}
}
1 change: 1 addition & 0 deletions crates/rome_js_formatter/src/js/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub(crate) mod class_member_name;
pub(crate) mod constructor_parameter;
pub(crate) mod declaration;
pub(crate) mod declaration_clause;
pub(crate) mod decorator;
pub(crate) mod export_clause;
pub(crate) mod export_default_declaration;
pub(crate) mod export_named_specifier;
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
20 changes: 20 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,20 @@
use crate::prelude::*;
use rome_formatter::write;
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<()> {
if node.is_empty() {
return Ok(());
}

f.join_with(&soft_line_break_or_space())
.entries(node.iter().formatted())
.finish()?;

write!(f, [soft_line_break_or_space()])
}
}
Loading

0 comments on commit 1f319e1

Please sign in to comment.