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 May 8, 2023
1 parent fa3e63f commit 21dbb08
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pub(crate) struct FormatJsClassExpression;

impl FormatNodeRule<JsClassExpression> for FormatJsClassExpression {
fn fmt_fields(&self, node: &JsClassExpression, f: &mut JsFormatter) -> FormatResult<()> {
if node.decorators().len() > 0 {
if node.decorators().is_empty() {
FormatClass::from(&node.clone().into()).fmt(f)
} else {
write!(
f,
[
Expand All @@ -23,13 +25,11 @@ impl FormatNodeRule<JsClassExpression> for FormatJsClassExpression {
soft_line_break_or_space()
]
)
} else {
FormatClass::from(&node.clone().into()).fmt(f)
}
}

fn needs_parentheses(&self, item: &JsClassExpression) -> bool {
item.decorators().len() > 0 || item.needs_parentheses()
!item.decorators().is_empty() || item.needs_parentheses()
}

fn fmt_dangling_comments(
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_formatter/src/js/lists/decorator_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl FormatRule<JsDecoratorList> for FormatJsDecoratorList {
let is_export = export.is_some();

let has_decorators_before_export =
export.map_or(false, |export| export.decorators().len() > 0);
export.map_or(false, |export| !export.decorators().is_empty());

if has_decorators_before_export {
return Ok(());
Expand Down
2 changes: 1 addition & 1 deletion crates/rome_js_formatter/src/utils/assignment_like.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ pub(crate) fn should_break_after_operator(
})
}

AnyJsExpression::JsClassExpression(class) => class.decorators().len() > 0,
AnyJsExpression::JsClassExpression(class) => !class.decorators().is_empty(),

_ => false,
};
Expand Down

0 comments on commit 21dbb08

Please sign in to comment.