From fa3e63fa4d034b8531c37ca21ea674a6346bc460 Mon Sep 17 00:00:00 2001 From: Denis Bezrukov <6227442+denbezrukov@users.noreply.github.com> Date: Mon, 8 May 2023 00:37:01 +0300 Subject: [PATCH] feat(rome_js_formatter): EcmaScript @decorators #4252 --- crates/rome_js_formatter/src/comments.rs | 24 -- .../src/js/expressions/class_expression.rs | 18 +- .../src/js/lists/decorator_list.rs | 87 ++++++- .../src/js/lists/method_modifier_list.rs | 6 +- .../src/js/lists/property_modifier_list.rs | 6 +- .../lists/method_signature_modifier_list.rs | 6 +- .../lists/property_signature_modifier_list.rs | 6 +- .../src/utils/assignment_like.rs | 2 + .../src/utils/format_modifiers.rs | 93 +++++++ crates/rome_js_formatter/src/utils/mod.rs | 1 + crates/rome_js_formatter/tests/quick_test.rs | 9 +- .../class_members_call_decorator.js | 92 +++++++ .../class_members_call_decorator.js.snap | 238 ++++++++++++++++++ .../module/decorators/class_members_mixed.js | 92 +++++++ .../decorators/class_members_mixed.js.snap | 236 +++++++++++++++++ .../module/decorators/class_members_simple.js | 92 +++++++ .../decorators/class_members_simple.js.snap | 226 +++++++++++++++++ .../js/module/decorators/class_simple.js | 48 ++++ .../js/module/decorators/class_simple.js.snap | 158 ++++++++++++ .../decorators/class_simple_call_decorator.js | 48 ++++ .../class_simple_call_decorator.js.snap | 158 ++++++++++++ .../js/module/decorators/export_default_1.js | 1 + .../decorators/export_default_1.js.snap | 34 +++ .../js/module/decorators/export_default_2.js | 1 + .../decorators/export_default_2.js.snap | 35 +++ .../js/module/decorators/export_default_3.js | 1 + .../decorators/export_default_3.js.snap | 35 +++ .../js/module/decorators/export_default_4.js | 1 + .../decorators/export_default_4.js.snap | 37 +++ .../specs/js/module/decorators/expression.js | 21 ++ .../js/module/decorators/expression.js.snap | 115 +++++++++ .../specs/js/module/decorators/multiline.js | 16 ++ .../js/module/decorators/multiline.js.snap | 58 +++++ .../js/babel-plugins/decorators.js.snap | 92 ------- .../decorator-auto-accessors/comments.js.snap | 41 --- .../js/decorators-export/after_export.js.snap | 43 ---- .../class-expression/arguments.js.snap | 44 ---- .../class-expression/class-expression.js.snap | 103 -------- .../member-expression.js.snap | 44 ---- .../class-expression/super-class.js.snap | 43 ---- .../prettier/js/decorators/classes.js.snap | 85 ------- .../js/decorators/member-expression.js.snap | 106 +++----- .../prettier/js/decorators/methods.js.snap | 64 ----- .../prettier/js/decorators/mixed.js.snap | 46 ---- .../specs/prettier/js/decorators/mobx.js.snap | 46 ++-- .../prettier/js/decorators/parens.js.snap | 38 --- .../decorators-ts/accessor-decorator.ts.snap | 75 ------ .../decorators-ts/method-decorator.ts.snap | 56 ----- .../typescript/decorators-ts/multiple.ts.snap | 40 --- .../decorators-ts/parameter-decorator.ts.snap | 73 ------ .../typescript/decorators-ts/typeorm.ts.snap | 47 ++-- .../typescript/decorators/accessor.ts.snap | 48 ---- .../typescript/decorators/comments.ts.snap | 41 --- .../decorators/decorators-comments.ts.snap | 41 ++- .../decorators/inline-decorators.ts.snap | 57 ++--- .../typescript/decorators/legacy.ts.snap | 61 ----- .../typescript/decorators/mobx.ts.snap | 131 ---------- .../4.ts.snap | 35 --- .../tests/specs/ts/decoartors.ts.snap | 17 +- .../specs/ts/decorators/class_members.ts | 92 +++++++ .../specs/ts/decorators/class_members.ts.snap | 226 +++++++++++++++++ 61 files changed, 2374 insertions(+), 1462 deletions(-) create mode 100644 crates/rome_js_formatter/src/utils/format_modifiers.rs create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple_call_decorator.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple_call_decorator.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_1.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_1.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_2.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_2.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_3.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_3.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_4.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_4.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/expression.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/expression.js.snap create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/multiline.js create mode 100644 crates/rome_js_formatter/tests/specs/js/module/decorators/multiline.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/decorators.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/comments.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorators-export/after_export.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/member-expression.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/super-class.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorators/methods.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorators/mixed.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/js/decorators/parens.js.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/accessor-decorator.ts.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/method-decorator.ts.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/multiple.ts.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/parameter-decorator.ts.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/accessor.ts.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/comments.ts.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/mobx.ts.snap delete mode 100644 crates/rome_js_formatter/tests/specs/prettier/typescript/type-arguments-bit-shift-left-like/4.ts.snap create mode 100644 crates/rome_js_formatter/tests/specs/ts/decorators/class_members.ts create mode 100644 crates/rome_js_formatter/tests/specs/ts/decorators/class_members.ts.snap diff --git a/crates/rome_js_formatter/src/comments.rs b/crates/rome_js_formatter/src/comments.rs index 8c796935d9a..c08535e2b81 100644 --- a/crates/rome_js_formatter/src/comments.rs +++ b/crates/rome_js_formatter/src/comments.rs @@ -166,7 +166,6 @@ impl CommentStyle for JsCommentStyle { .or_else(handle_try_comment) .or_else(handle_class_comment) .or_else(handle_method_comment) - .or_else(handle_property_comments) .or_else(handle_for_comment) .or_else(handle_root_comments) .or_else(handle_array_hole_comment) @@ -185,7 +184,6 @@ impl CommentStyle for JsCommentStyle { .or_else(handle_try_comment) .or_else(handle_class_comment) .or_else(handle_method_comment) - .or_else(handle_property_comments) .or_else(handle_for_comment) .or_else(handle_root_comments) .or_else(handle_parameter_comment) @@ -510,28 +508,6 @@ fn handle_method_comment(comment: DecoratedComment) -> CommentPlacem CommentPlacement::Default(comment) } -fn handle_property_comments(comment: DecoratedComment) -> CommentPlacement { - let enclosing = comment.enclosing_node(); - - let is_property = matches!( - enclosing.kind(), - JsSyntaxKind::JS_PROPERTY_OBJECT_MEMBER | JsSyntaxKind::JS_PROPERTY_CLASS_MEMBER - ); - - if !is_property { - return CommentPlacement::Default(comment); - } - - if let (Some(preceding), Some(following)) = (comment.preceding_node(), comment.following_node()) - { - if preceding.kind() == JsSyntaxKind::JS_DECORATOR { - return CommentPlacement::leading(following.clone(), comment); - } - } - - CommentPlacement::Default(comment) -} - /// Handle a all comments document. /// See `blank.js` fn handle_root_comments(comment: DecoratedComment) -> CommentPlacement { diff --git a/crates/rome_js_formatter/src/js/expressions/class_expression.rs b/crates/rome_js_formatter/src/js/expressions/class_expression.rs index 367b7b8e51b..da2de6fc22f 100644 --- a/crates/rome_js_formatter/src/js/expressions/class_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/class_expression.rs @@ -1,5 +1,6 @@ use crate::prelude::*; use crate::utils::format_class::FormatClass; +use rome_formatter::{format_args, write}; use crate::parentheses::{ is_callee, is_first_in_statement, FirstInStatementMode, NeedsParentheses, @@ -11,11 +12,24 @@ pub(crate) struct FormatJsClassExpression; impl FormatNodeRule for FormatJsClassExpression { fn fmt_fields(&self, node: &JsClassExpression, f: &mut JsFormatter) -> FormatResult<()> { - FormatClass::from(&node.clone().into()).fmt(f) + if node.decorators().len() > 0 { + write!( + f, + [ + indent(&format_args![ + soft_line_break_or_space(), + &FormatClass::from(&node.clone().into()), + ]), + soft_line_break_or_space() + ] + ) + } else { + FormatClass::from(&node.clone().into()).fmt(f) + } } fn needs_parentheses(&self, item: &JsClassExpression) -> bool { - item.needs_parentheses() + item.decorators().len() > 0 || item.needs_parentheses() } fn fmt_dangling_comments( diff --git a/crates/rome_js_formatter/src/js/lists/decorator_list.rs b/crates/rome_js_formatter/src/js/lists/decorator_list.rs index 38ceb472200..f5a47d67409 100644 --- a/crates/rome_js_formatter/src/js/lists/decorator_list.rs +++ b/crates/rome_js_formatter/src/js/lists/decorator_list.rs @@ -1,6 +1,10 @@ use crate::prelude::*; use rome_formatter::write; -use rome_js_syntax::JsDecoratorList; +use rome_js_syntax::JsSyntaxKind::JS_CLASS_EXPRESSION; +use rome_js_syntax::{ + AnyJsDeclarationClause, AnyJsExportClause, AnyJsExportDefaultDeclaration, JsDecoratorList, + JsExport, +}; #[derive(Debug, Clone, Default)] pub(crate) struct FormatJsDecoratorList; @@ -11,10 +15,83 @@ impl FormatRule for FormatJsDecoratorList { return Ok(()); } - f.join_with(&soft_line_break_or_space()) - .entries(node.iter().formatted()) - .finish()?; + // we need to rearrange decorators to be before export if we have decorators before class + if let Some(export) = node.parent::() { + let mut join = f.join_nodes_with_hardline(); - write!(f, [soft_line_break_or_space()]) + // write decorators before export first + for decorator in node { + join.entry(decorator.syntax(), &format_or_verbatim(decorator.format())); + } + + // try to find class decorators + let class_decorators = match export.export_clause()? { + AnyJsExportClause::AnyJsDeclarationClause( + AnyJsDeclarationClause::JsClassDeclaration(class), + ) => { + // @before export @after class Foo {} + Some(class.decorators()) + } + AnyJsExportClause::JsExportDefaultDeclarationClause(export_default_declaration) => { + match export_default_declaration.declaration()? { + AnyJsExportDefaultDeclaration::JsClassExportDefaultDeclaration(class) => { + // @before export default @after class Foo {} + Some(class.decorators()) + } + _ => None, + } + } + _ => None, + }; + + // write decorators after export + if let Some(class_decorators) = class_decorators { + for decorator in class_decorators { + join.entry(decorator.syntax(), &format_or_verbatim(decorator.format())); + } + } + + join.finish()?; + + write!(f, [hard_line_break()]) + } else if matches!( + node.syntax().parent().map(|parent| parent.kind()), + Some(JS_CLASS_EXPRESSION) + ) { + write!(f, [expand_parent()])?; + f.join_with(&soft_line_break_or_space()) + .entries(node.iter().formatted()) + .finish()?; + + write!(f, [soft_line_break_or_space()]) + } else { + // If the parent node is an export declaration and the decorator + // was written before the export, the export will be responsible + // for printing the decorators. + let export = node.syntax().grand_parent().and_then(|grand_parent| { + JsExport::cast_ref(&grand_parent) + .or_else(|| grand_parent.parent().and_then(JsExport::cast)) + }); + let is_export = export.is_some(); + + let has_decorators_before_export = + export.map_or(false, |export| export.decorators().len() > 0); + + if has_decorators_before_export { + return Ok(()); + } + + if is_export { + write!(f, [hard_line_break()])?; + } else { + write!(f, [expand_parent()])?; + } + + f.join_with(&soft_line_break_or_space()) + .entries(node.iter().formatted()) + .finish()?; + + write!(f, [soft_line_break_or_space()]) + } } } diff --git a/crates/rome_js_formatter/src/js/lists/method_modifier_list.rs b/crates/rome_js_formatter/src/js/lists/method_modifier_list.rs index 53b75c22511..9a857c70a98 100644 --- a/crates/rome_js_formatter/src/js/lists/method_modifier_list.rs +++ b/crates/rome_js_formatter/src/js/lists/method_modifier_list.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::utils::sort_modifiers_by_precedence; +use crate::utils::format_modifiers::FormatModifiers; use rome_js_syntax::JsMethodModifierList; #[derive(Debug, Clone, Default)] @@ -9,8 +9,6 @@ impl FormatRule for FormatJsMethodModifierList { type Context = JsFormatContext; fn fmt(&self, node: &JsMethodModifierList, f: &mut JsFormatter) -> FormatResult<()> { - f.join_with(&space()) - .entries(sort_modifiers_by_precedence(node).into_iter().formatted()) - .finish() + FormatModifiers::from(node.clone()).fmt(f) } } diff --git a/crates/rome_js_formatter/src/js/lists/property_modifier_list.rs b/crates/rome_js_formatter/src/js/lists/property_modifier_list.rs index c8a42ff40ba..05916be72cd 100644 --- a/crates/rome_js_formatter/src/js/lists/property_modifier_list.rs +++ b/crates/rome_js_formatter/src/js/lists/property_modifier_list.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::utils::sort_modifiers_by_precedence; +use crate::utils::format_modifiers::FormatModifiers; use rome_js_syntax::JsPropertyModifierList; #[derive(Debug, Clone, Default)] @@ -9,8 +9,6 @@ impl FormatRule for FormatJsPropertyModifierList { type Context = JsFormatContext; fn fmt(&self, node: &JsPropertyModifierList, f: &mut JsFormatter) -> FormatResult<()> { - f.join_with(&space()) - .entries(sort_modifiers_by_precedence(node).into_iter().formatted()) - .finish() + FormatModifiers::from(node.clone()).fmt(f) } } diff --git a/crates/rome_js_formatter/src/ts/lists/method_signature_modifier_list.rs b/crates/rome_js_formatter/src/ts/lists/method_signature_modifier_list.rs index 08a31508cbf..e3fe04c8027 100644 --- a/crates/rome_js_formatter/src/ts/lists/method_signature_modifier_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/method_signature_modifier_list.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::utils::sort_modifiers_by_precedence; +use crate::utils::format_modifiers::FormatModifiers; use rome_js_syntax::TsMethodSignatureModifierList; #[derive(Debug, Clone, Default)] @@ -9,8 +9,6 @@ impl FormatRule for FormatTsMethodSignatureModifi type Context = JsFormatContext; fn fmt(&self, node: &TsMethodSignatureModifierList, f: &mut JsFormatter) -> FormatResult<()> { - f.join_with(&space()) - .entries(sort_modifiers_by_precedence(node).into_iter().formatted()) - .finish() + FormatModifiers::from(node.clone()).fmt(f) } } diff --git a/crates/rome_js_formatter/src/ts/lists/property_signature_modifier_list.rs b/crates/rome_js_formatter/src/ts/lists/property_signature_modifier_list.rs index 8ff07d30096..f5c85c636fe 100644 --- a/crates/rome_js_formatter/src/ts/lists/property_signature_modifier_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/property_signature_modifier_list.rs @@ -1,5 +1,5 @@ use crate::prelude::*; -use crate::utils::sort_modifiers_by_precedence; +use crate::utils::format_modifiers::FormatModifiers; use rome_js_syntax::TsPropertySignatureModifierList; #[derive(Debug, Clone, Default)] @@ -9,8 +9,6 @@ impl FormatRule for FormatTsPropertySignatureMo type Context = JsFormatContext; fn fmt(&self, node: &TsPropertySignatureModifierList, f: &mut JsFormatter) -> FormatResult<()> { - f.join_with(&space()) - .entries(sort_modifiers_by_precedence(node).into_iter().formatted()) - .finish() + FormatModifiers::from(node.clone()).fmt(f) } } diff --git a/crates/rome_js_formatter/src/utils/assignment_like.rs b/crates/rome_js_formatter/src/utils/assignment_like.rs index 60d4fcfb6d1..793cbc8593e 100644 --- a/crates/rome_js_formatter/src/utils/assignment_like.rs +++ b/crates/rome_js_formatter/src/utils/assignment_like.rs @@ -941,6 +941,8 @@ pub(crate) fn should_break_after_operator( }) } + AnyJsExpression::JsClassExpression(class) => class.decorators().len() > 0, + _ => false, }; diff --git a/crates/rome_js_formatter/src/utils/format_modifiers.rs b/crates/rome_js_formatter/src/utils/format_modifiers.rs new file mode 100644 index 00000000000..d8a965875d3 --- /dev/null +++ b/crates/rome_js_formatter/src/utils/format_modifiers.rs @@ -0,0 +1,93 @@ +use crate::prelude::*; +use crate::utils::sort_modifiers_by_precedence; +use crate::{AsFormat, IntoFormat}; +use rome_formatter::{format_args, write}; +use rome_js_syntax::JsSyntaxKind::JS_DECORATOR; +use rome_js_syntax::{JsLanguage, Modifiers}; +use rome_rowan::{AstNode, AstNodeList, NodeOrToken}; + +pub(crate) struct FormatModifiers { + pub(crate) list: List, +} + +impl FormatModifiers { + pub(crate) fn from(list: List) -> Self { + Self { list } + } +} + +impl Format for FormatModifiers +where + Node: AstNode + AsFormat + IntoFormat, + List: AstNodeList, + Modifiers: for<'a> From<&'a Node>, +{ + fn fmt(&self, f: &mut Formatter) -> FormatResult<()> { + let modifiers = sort_modifiers_by_precedence(&self.list); + let should_expand = should_expand_decorators(&self.list); + + // need to use peek the iterator to check if the current node is a decorator and don't advance the iterator + let mut iter = modifiers.into_iter().peekable(); + let decorators = format_once(|f| { + let mut join = f.join_nodes_with_soft_line(); + + // join only decorators here + while let Some(node) = iter.peek() { + // check if the current node is a decorator + match node.syntax().kind() { + JS_DECORATOR => { + join.entry(node.syntax(), &node.format()); + // advance the iterator + iter.next(); + } + _ => { + // if we encounter a non-decorator we break out of the loop + break; + } + } + } + + join.finish() + }); + + write!( + f, + [group(&format_args![decorators, soft_line_break_or_space()]) + .should_expand(should_expand)] + )?; + + // join the rest of the modifiers + f.join_with(&space()).entries(iter.formatted()).finish() + } +} + +/// This function expands decorators enclosing a group if there is a newline between decorators or after the last decorator. +fn should_expand_decorators(list: &List) -> bool +where + Node: AstNode, + List: AstNodeList, +{ + // we need to skip the first node because we look for newlines between decorators or after the last decorator + for node in list.iter().skip(1) { + match node.syntax().kind() { + JS_DECORATOR => { + if node.syntax().has_leading_newline() { + return true; + } + } + _ => { + // if we encounter a non-decorator with a leading newline after a decorator and the next modifier + return node.syntax().has_leading_newline(); + } + } + } + + // if we encounter a non-decorator with a leading newline after a decorator and the next node or token + list.syntax_list() + .node() + .next_sibling_or_token() + .map_or(false, |node| match node { + NodeOrToken::Node(node) => node.has_leading_newline(), + NodeOrToken::Token(token) => token.has_leading_newline(), + }) +} diff --git a/crates/rome_js_formatter/src/utils/mod.rs b/crates/rome_js_formatter/src/utils/mod.rs index be6a0b2a51d..4d80e952c1b 100644 --- a/crates/rome_js_formatter/src/utils/mod.rs +++ b/crates/rome_js_formatter/src/utils/mod.rs @@ -5,6 +5,7 @@ mod conditional; pub mod string_utils; pub(crate) mod format_class; +pub(crate) mod format_modifiers; pub(crate) mod function_body; pub mod jsx; pub(crate) mod member_chain; diff --git a/crates/rome_js_formatter/tests/quick_test.rs b/crates/rome_js_formatter/tests/quick_test.rs index a7432e4f160..872a541ecca 100644 --- a/crates/rome_js_formatter/tests/quick_test.rs +++ b/crates/rome_js_formatter/tests/quick_test.rs @@ -13,12 +13,9 @@ mod language { // use this test check if your snippet prints as you wish, without using a snapshot fn quick_test() { let src = r#" -class Test2 { - @anotherDecorator() // leading comment - prop: string; -} - - +const foo = @deco class { + // +}; "#; let syntax = SourceType::tsx(); let tree = parse(src, syntax); diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js new file mode 100644 index 00000000000..1c86e375076 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js @@ -0,0 +1,92 @@ +class Foo { + // one decorator without a newline + @decorator.method(value) property; + @decorator.method(value) method() {} + @decorator.method(value) async method() {} + @decorator.method(value) *method() {} + @decorator.method(value) get getter() {} + @decorator.method(value) set setter(val) {} + + // two decorators without a newline + @decorator.method(value) @decorator.method(value) property; + @decorator.method(value) @decorator.method(value) method() {} + @decorator.method(value) @decorator.method(value) async method() {} + @decorator.method(value) @decorator.method(value) *method() {} + @decorator.method(value) @decorator.method(value) get getter() {} + @decorator.method(value) @decorator.method(value) set setter(val) {} + + // one decorator with a newline + @decorator.method(value) + property; + @decorator.method(value) + method() {} + @decorator.method(value) + async method() {} + @decorator.method(value) + *method() {} + @decorator.method(value) + get getter() {} + @decorator.method(value) + set setter(val) {} + + // two decorators without a newline + @decorator.method(value) + @decorator.method(value) property; + @decorator.method(value) + @decorator.method(value) method() {} + @decorator.method(value) + @decorator.method(value) async method() {} + @decorator.method(value) + @decorator.method(value) *method() {} + @decorator.method(value) + @decorator.method(value) get getter() {} + @decorator.method(value) + @decorator.method(value) set setter(val) {} +} + + +class Foo { + // one decorator without a newline + /*before*/ @decorator.method(value) /*after*/ property; + /*before*/ @decorator.method(value) /*after*/ method() {} + /*before*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator.method(value) /*after*/ *method() {} + /*before*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator.method(value) /*after*/ set setter(val) {} + + // two decorators without a newline + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ property; + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ method() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ *method() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ set setter(val) {} + + // one decorator with a newline + @decorator.method(value) /*before*/ + /*after*/ property; + @decorator.method(value) /*before*/ + /*after*/ method() {} + @decorator.method(value) /*before*/ + /*after*/ async method() {} + @decorator.method(value) /*before*/ + /*after*/ *method() {} + @decorator.method(value) /*before*/ + /*after*/ get getter() {} + @decorator.method(value) /*before*/ + /*after*/ set setter(val) {} + + // two decorators without a newline + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ property; + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ async method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ *method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ get getter() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ set setter(val) {} +} diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js.snap new file mode 100644 index 00000000000..262cbc79090 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_call_decorator.js.snap @@ -0,0 +1,238 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/class_members_call_decorator.js +--- + +# Input + +```js +class Foo { + // one decorator without a newline + @decorator.method(value) property; + @decorator.method(value) method() {} + @decorator.method(value) async method() {} + @decorator.method(value) *method() {} + @decorator.method(value) get getter() {} + @decorator.method(value) set setter(val) {} + + // two decorators without a newline + @decorator.method(value) @decorator.method(value) property; + @decorator.method(value) @decorator.method(value) method() {} + @decorator.method(value) @decorator.method(value) async method() {} + @decorator.method(value) @decorator.method(value) *method() {} + @decorator.method(value) @decorator.method(value) get getter() {} + @decorator.method(value) @decorator.method(value) set setter(val) {} + + // one decorator with a newline + @decorator.method(value) + property; + @decorator.method(value) + method() {} + @decorator.method(value) + async method() {} + @decorator.method(value) + *method() {} + @decorator.method(value) + get getter() {} + @decorator.method(value) + set setter(val) {} + + // two decorators without a newline + @decorator.method(value) + @decorator.method(value) property; + @decorator.method(value) + @decorator.method(value) method() {} + @decorator.method(value) + @decorator.method(value) async method() {} + @decorator.method(value) + @decorator.method(value) *method() {} + @decorator.method(value) + @decorator.method(value) get getter() {} + @decorator.method(value) + @decorator.method(value) set setter(val) {} +} + + +class Foo { + // one decorator without a newline + /*before*/ @decorator.method(value) /*after*/ property; + /*before*/ @decorator.method(value) /*after*/ method() {} + /*before*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator.method(value) /*after*/ *method() {} + /*before*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator.method(value) /*after*/ set setter(val) {} + + // two decorators without a newline + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ property; + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ method() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ *method() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ set setter(val) {} + + // one decorator with a newline + @decorator.method(value) /*before*/ + /*after*/ property; + @decorator.method(value) /*before*/ + /*after*/ method() {} + @decorator.method(value) /*before*/ + /*after*/ async method() {} + @decorator.method(value) /*before*/ + /*after*/ *method() {} + @decorator.method(value) /*before*/ + /*after*/ get getter() {} + @decorator.method(value) /*before*/ + /*after*/ set setter(val) {} + + // two decorators without a newline + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ property; + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ async method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ *method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ get getter() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ set setter(val) {} +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +class Foo { + // one decorator without a newline + @decorator.method(value) property; + @decorator.method(value) method() {} + @decorator.method(value) async method() {} + @decorator.method(value) *method() {} + @decorator.method(value) get getter() {} + @decorator.method(value) set setter(val) {} + + // two decorators without a newline + @decorator.method(value) @decorator.method(value) property; + @decorator.method(value) @decorator.method(value) method() {} + @decorator.method(value) @decorator.method(value) async method() {} + @decorator.method(value) @decorator.method(value) *method() {} + @decorator.method(value) @decorator.method(value) get getter() {} + @decorator.method(value) @decorator.method(value) set setter(val) {} + + // one decorator with a newline + @decorator.method(value) + property; + @decorator.method(value) + method() {} + @decorator.method(value) + async method() {} + @decorator.method(value) + *method() {} + @decorator.method(value) + get getter() {} + @decorator.method(value) + set setter(val) {} + + // two decorators without a newline + @decorator.method(value) + @decorator.method(value) + property; + @decorator.method(value) + @decorator.method(value) + method() {} + @decorator.method(value) + @decorator.method(value) + async method() {} + @decorator.method(value) + @decorator.method(value) + *method() {} + @decorator.method(value) + @decorator.method(value) + get getter() {} + @decorator.method(value) + @decorator.method(value) + set setter(val) {} +} + +class Foo { + // one decorator without a newline + /*before*/ @decorator.method(value) /*after*/ property; + /*before*/ @decorator.method(value) /*after*/ method() {} + /*before*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator.method(value) /*after*/ *method() {} + /*before*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator.method(value) /*after*/ set setter(val) {} + + // two decorators without a newline + /*before*/ @decorator.method(value) /*middle*/ + @decorator.method(value) /*after*/ + property; + /*before*/ @decorator.method(value) /*middle*/ + @decorator.method(value) /*after*/ + method() {} + /*before*/ @decorator.method(value) /*middle*/ + @decorator.method(value) /*after*/ + async method() {} + /*before*/ @decorator.method(value) /*middle*/ + @decorator.method(value) /*after*/ + *method() {} + /*before*/ @decorator.method(value) /*middle*/ + @decorator.method(value) /*after*/ + get getter() {} + /*before*/ @decorator.method(value) /*middle*/ + @decorator.method(value) /*after*/ + set setter(val) {} + + // one decorator with a newline + @decorator.method(value) /*before*/ + /*after*/ property; + @decorator.method(value) /*before*/ + /*after*/ method() {} + @decorator.method(value) /*before*/ + async /*after*/ method() {} + @decorator.method(value) /*before*/ + */*after*/ method() {} + @decorator.method(value) /*before*/ + get /*after*/ getter() {} + @decorator.method(value) /*before*/ + set /*after*/ setter(val) {} + + // two decorators without a newline + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ + property; + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ + method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ + async method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ + *method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ + get getter() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator.method(value) /*after*/ + set setter(val) {} +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js new file mode 100644 index 00000000000..20b81241f0b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js @@ -0,0 +1,92 @@ +class Foo { + // one decorator without a newline + @decorator.method(value) property; + @decorator.method(value) method() {} + @decorator.method(value) async method() {} + @decorator.method(value) *method() {} + @decorator.method(value) get getter() {} + @decorator.method(value) set setter(val) {} + + // two decorators without a newline + @decorator.method(value) @decorator property; + @decorator.method(value) @decorator method() {} + @decorator.method(value) @decorator async method() {} + @decorator @decorator.method(value) *method() {} + @decorator @decorator.method(value) get getter() {} + @decorator @decorator.method(value) set setter(val) {} + + // one decorator with a newline + @decorator.method(value) + property; + @decorator + method() {} + @decorator.method(value) + async method() {} + @decorator + *method() {} + @decorator.method(value) + get getter() {} + @decorator.method(value) + set setter(val) {} + + // two decorators without a newline + @decorator + @decorator.method(value) property; + @decorator.method(value) + @decorator method() {} + @decorator.method(value) + @decorator.method(value) async method() {} + @decorator.method(value) + @decorator *method() {} + @decorator.method(value) + @decorator.method(value) get getter() {} + @decorator + @decorator.method(value) set setter(val) {} +} + + +class Foo { + // one decorator without a newline + /*before*/ @decorator /*after*/ property; + /*before*/ @decorator.method(value) /*after*/ method() {} + /*before*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator /*after*/ *method() {} + /*before*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator /*after*/ set setter(val) {} + + // two decorators without a newline + /*before*/ @decorator /*middle*/ @decorator.method(value) /*after*/ property; + /*before*/ @decorator.method(value) /*middle*/ @decorator /*after*/ method() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator /*middle*/ @decorator.method(value) /*after*/ *method() {} + /*before*/ @decorator /*middle*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator /*after*/ set setter(val) {} + + // one decorator with a newline + @decorator.method(value) /*before*/ + /*after*/ property; + @decorator /*before*/ + /*after*/ method() {} + @decorator.method(value) /*before*/ + /*after*/ async method() {} + @decorator /*before*/ + /*after*/ *method() {} + @decorator.method(value) /*before*/ + /*after*/ get getter() {} + @decorator /*before*/ + /*after*/ set setter(val) {} + + // two decorators without a newline + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ property; + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ async method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ *method() {} + @decorator /*before*/ + /*middle*/ @decorator.method(value) /*after*/ get getter() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ set setter(val) {} +} diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js.snap new file mode 100644 index 00000000000..b2cc7ca6180 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_mixed.js.snap @@ -0,0 +1,236 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/class_members_mixed.js +--- + +# Input + +```js +class Foo { + // one decorator without a newline + @decorator.method(value) property; + @decorator.method(value) method() {} + @decorator.method(value) async method() {} + @decorator.method(value) *method() {} + @decorator.method(value) get getter() {} + @decorator.method(value) set setter(val) {} + + // two decorators without a newline + @decorator.method(value) @decorator property; + @decorator.method(value) @decorator method() {} + @decorator.method(value) @decorator async method() {} + @decorator @decorator.method(value) *method() {} + @decorator @decorator.method(value) get getter() {} + @decorator @decorator.method(value) set setter(val) {} + + // one decorator with a newline + @decorator.method(value) + property; + @decorator + method() {} + @decorator.method(value) + async method() {} + @decorator + *method() {} + @decorator.method(value) + get getter() {} + @decorator.method(value) + set setter(val) {} + + // two decorators without a newline + @decorator + @decorator.method(value) property; + @decorator.method(value) + @decorator method() {} + @decorator.method(value) + @decorator.method(value) async method() {} + @decorator.method(value) + @decorator *method() {} + @decorator.method(value) + @decorator.method(value) get getter() {} + @decorator + @decorator.method(value) set setter(val) {} +} + + +class Foo { + // one decorator without a newline + /*before*/ @decorator /*after*/ property; + /*before*/ @decorator.method(value) /*after*/ method() {} + /*before*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator /*after*/ *method() {} + /*before*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator /*after*/ set setter(val) {} + + // two decorators without a newline + /*before*/ @decorator /*middle*/ @decorator.method(value) /*after*/ property; + /*before*/ @decorator.method(value) /*middle*/ @decorator /*after*/ method() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator /*middle*/ @decorator.method(value) /*after*/ *method() {} + /*before*/ @decorator /*middle*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator.method(value) /*middle*/ @decorator /*after*/ set setter(val) {} + + // one decorator with a newline + @decorator.method(value) /*before*/ + /*after*/ property; + @decorator /*before*/ + /*after*/ method() {} + @decorator.method(value) /*before*/ + /*after*/ async method() {} + @decorator /*before*/ + /*after*/ *method() {} + @decorator.method(value) /*before*/ + /*after*/ get getter() {} + @decorator /*before*/ + /*after*/ set setter(val) {} + + // two decorators without a newline + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ property; + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ async method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ *method() {} + @decorator /*before*/ + /*middle*/ @decorator.method(value) /*after*/ get getter() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ set setter(val) {} +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +class Foo { + // one decorator without a newline + @decorator.method(value) property; + @decorator.method(value) method() {} + @decorator.method(value) async method() {} + @decorator.method(value) *method() {} + @decorator.method(value) get getter() {} + @decorator.method(value) set setter(val) {} + + // two decorators without a newline + @decorator.method(value) @decorator property; + @decorator.method(value) @decorator method() {} + @decorator.method(value) @decorator async method() {} + @decorator @decorator.method(value) *method() {} + @decorator @decorator.method(value) get getter() {} + @decorator @decorator.method(value) set setter(val) {} + + // one decorator with a newline + @decorator.method(value) + property; + @decorator + method() {} + @decorator.method(value) + async method() {} + @decorator + *method() {} + @decorator.method(value) + get getter() {} + @decorator.method(value) + set setter(val) {} + + // two decorators without a newline + @decorator + @decorator.method(value) + property; + @decorator.method(value) + @decorator + method() {} + @decorator.method(value) + @decorator.method(value) + async method() {} + @decorator.method(value) + @decorator + *method() {} + @decorator.method(value) + @decorator.method(value) + get getter() {} + @decorator + @decorator.method(value) + set setter(val) {} +} + +class Foo { + // one decorator without a newline + /*before*/ @decorator /*after*/ property; + /*before*/ @decorator.method(value) /*after*/ method() {} + /*before*/ @decorator.method(value) /*after*/ async method() {} + /*before*/ @decorator /*after*/ *method() {} + /*before*/ @decorator.method(value) /*after*/ get getter() {} + /*before*/ @decorator /*after*/ set setter(val) {} + + // two decorators without a newline + /*before*/ @decorator /*middle*/ @decorator.method(value) /*after*/ property; + /*before*/ @decorator.method(value) /*middle*/ + @decorator /*after*/ + method() {} + /*before*/ @decorator.method(value) /*middle*/ + @decorator.method(value) /*after*/ + async method() {} + /*before*/ @decorator /*middle*/ + @decorator.method(value) /*after*/ + *method() {} + /*before*/ @decorator /*middle*/ + @decorator.method(value) /*after*/ + get getter() {} + /*before*/ @decorator.method(value) /*middle*/ + @decorator /*after*/ + set setter(val) {} + + // one decorator with a newline + @decorator.method(value) /*before*/ + /*after*/ property; + @decorator /*before*/ + /*after*/ method() {} + @decorator.method(value) /*before*/ + async /*after*/ method() {} + @decorator /*before*/ + */*after*/ method() {} + @decorator.method(value) /*before*/ + get /*after*/ getter() {} + @decorator /*before*/ + set /*after*/ setter(val) {} + + // two decorators without a newline + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ + property; + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ + method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ + async method() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ + *method() {} + @decorator /*before*/ + /*middle*/ @decorator.method(value) /*after*/ + get getter() {} + @decorator.method(value) /*before*/ + /*middle*/ @decorator /*after*/ + set setter(val) {} +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js new file mode 100644 index 00000000000..37d623b0b0a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js @@ -0,0 +1,92 @@ +class Foo { + // one decorator without a newline + @dec property; + @dec method() {} + @dec async method() {} + @dec *method() {} + @dec get getter() {} + @dec set setter(val) {} + + // two decorators without a newline + @dec @dec property; + @dec @dec method() {} + @dec @dec async method() {} + @dec @dec *method() {} + @dec @dec get getter() {} + @dec @dec set setter(val) {} + + // one decorator with a newline + @dec + property; + @dec + method() {} + @dec + async method() {} + @dec + *method() {} + @dec + get getter() {} + @dec + set setter(val) {} + + // two decorators without a newline + @dec + @dec property; + @dec + @dec method() {} + @dec + @dec async method() {} + @dec + @dec *method() {} + @dec + @dec get getter() {} + @dec + @dec set setter(val) {} +} + + +class Foo { + // one decorator without a newline + /*before*/ @dec /*after*/ property; + /*before*/ @dec /*after*/ method() {} + /*before*/ @dec /*after*/ async method() {} + /*before*/ @dec /*after*/ *method() {} + /*before*/ @dec /*after*/ get getter() {} + /*before*/ @dec /*after*/ set setter(val) {} + + // two decorators without a newline + /*before*/ @dec /*middle*/ @dec /*after*/ property; + /*before*/ @dec /*middle*/ @dec /*after*/ method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ async method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ *method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ get getter() {} + /*before*/ @dec /*middle*/ @dec /*after*/ set setter(val) {} + + // one decorator with a newline + @dec /*before*/ + /*after*/ property; + @dec /*before*/ + /*after*/ method() {} + @dec /*before*/ + /*after*/ async method() {} + @dec /*before*/ + /*after*/ *method() {} + @dec /*before*/ + /*after*/ get getter() {} + @dec /*before*/ + /*after*/ set setter(val) {} + + // two decorators without a newline + @dec /*before*/ + /*middle*/ @dec /*after*/ property; + @dec /*before*/ + /*middle*/ @dec /*after*/ method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ async method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ *method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ get getter() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ set setter(val) {} +} diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js.snap new file mode 100644 index 00000000000..f3de3588936 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_members_simple.js.snap @@ -0,0 +1,226 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/class_members_simple.js +--- + +# Input + +```js +class Foo { + // one decorator without a newline + @dec property; + @dec method() {} + @dec async method() {} + @dec *method() {} + @dec get getter() {} + @dec set setter(val) {} + + // two decorators without a newline + @dec @dec property; + @dec @dec method() {} + @dec @dec async method() {} + @dec @dec *method() {} + @dec @dec get getter() {} + @dec @dec set setter(val) {} + + // one decorator with a newline + @dec + property; + @dec + method() {} + @dec + async method() {} + @dec + *method() {} + @dec + get getter() {} + @dec + set setter(val) {} + + // two decorators without a newline + @dec + @dec property; + @dec + @dec method() {} + @dec + @dec async method() {} + @dec + @dec *method() {} + @dec + @dec get getter() {} + @dec + @dec set setter(val) {} +} + + +class Foo { + // one decorator without a newline + /*before*/ @dec /*after*/ property; + /*before*/ @dec /*after*/ method() {} + /*before*/ @dec /*after*/ async method() {} + /*before*/ @dec /*after*/ *method() {} + /*before*/ @dec /*after*/ get getter() {} + /*before*/ @dec /*after*/ set setter(val) {} + + // two decorators without a newline + /*before*/ @dec /*middle*/ @dec /*after*/ property; + /*before*/ @dec /*middle*/ @dec /*after*/ method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ async method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ *method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ get getter() {} + /*before*/ @dec /*middle*/ @dec /*after*/ set setter(val) {} + + // one decorator with a newline + @dec /*before*/ + /*after*/ property; + @dec /*before*/ + /*after*/ method() {} + @dec /*before*/ + /*after*/ async method() {} + @dec /*before*/ + /*after*/ *method() {} + @dec /*before*/ + /*after*/ get getter() {} + @dec /*before*/ + /*after*/ set setter(val) {} + + // two decorators without a newline + @dec /*before*/ + /*middle*/ @dec /*after*/ property; + @dec /*before*/ + /*middle*/ @dec /*after*/ method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ async method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ *method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ get getter() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ set setter(val) {} +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +class Foo { + // one decorator without a newline + @dec property; + @dec method() {} + @dec async method() {} + @dec *method() {} + @dec get getter() {} + @dec set setter(val) {} + + // two decorators without a newline + @dec @dec property; + @dec @dec method() {} + @dec @dec async method() {} + @dec @dec *method() {} + @dec @dec get getter() {} + @dec @dec set setter(val) {} + + // one decorator with a newline + @dec + property; + @dec + method() {} + @dec + async method() {} + @dec + *method() {} + @dec + get getter() {} + @dec + set setter(val) {} + + // two decorators without a newline + @dec + @dec + property; + @dec + @dec + method() {} + @dec + @dec + async method() {} + @dec + @dec + *method() {} + @dec + @dec + get getter() {} + @dec + @dec + set setter(val) {} +} + +class Foo { + // one decorator without a newline + /*before*/ @dec /*after*/ property; + /*before*/ @dec /*after*/ method() {} + /*before*/ @dec /*after*/ async method() {} + /*before*/ @dec /*after*/ *method() {} + /*before*/ @dec /*after*/ get getter() {} + /*before*/ @dec /*after*/ set setter(val) {} + + // two decorators without a newline + /*before*/ @dec /*middle*/ @dec /*after*/ property; + /*before*/ @dec /*middle*/ @dec /*after*/ method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ async method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ *method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ get getter() {} + /*before*/ @dec /*middle*/ @dec /*after*/ set setter(val) {} + + // one decorator with a newline + @dec /*before*/ + /*after*/ property; + @dec /*before*/ + /*after*/ method() {} + @dec /*before*/ + async /*after*/ method() {} + @dec /*before*/ + */*after*/ method() {} + @dec /*before*/ + get /*after*/ getter() {} + @dec /*before*/ + set /*after*/ setter(val) {} + + // two decorators without a newline + @dec /*before*/ + /*middle*/ @dec /*after*/ + property; + @dec /*before*/ + /*middle*/ @dec /*after*/ + method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ + async method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ + *method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ + get getter() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ + set setter(val) {} +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple.js new file mode 100644 index 00000000000..0ef9d9a20fb --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple.js @@ -0,0 +1,48 @@ +@dec1 export class My {} +@dec1 +export class My {} +@dec1 @dec2 export class My {} +@dec1 +@dec2 export class My {} + +@dec1 @dec2 +export class My {} + +export @dec1 class My {} +export @dec1 +class My {} +export +@dec1 class My {} + +export @dec1 @dec2 class My {} +export @dec1 +@dec2 class My {} +export @dec1 +@dec2 class My {} +export +@dec1 @dec2 class My {} + +export +@dec1 +@dec2 class My {} + +export +@dec1 +@dec2 +class My {} + +@dec1 +export @dec2 class My {} + +@dec1 export @dec2 class My {} + +@dec1 export +@dec2 class My {} + +@dec1 +export +@dec2 class My {} + +@dec1 @dec2 export @dec3 @dec4 class My {} +export @dec1 @dec2 @dec3 @dec4 class My {} + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple.js.snap new file mode 100644 index 00000000000..35c795a6ebd --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple.js.snap @@ -0,0 +1,158 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/class_simple.js +--- + +# Input + +```js +@dec1 export class My {} +@dec1 +export class My {} +@dec1 @dec2 export class My {} +@dec1 +@dec2 export class My {} + +@dec1 @dec2 +export class My {} + +export @dec1 class My {} +export @dec1 +class My {} +export +@dec1 class My {} + +export @dec1 @dec2 class My {} +export @dec1 +@dec2 class My {} +export @dec1 +@dec2 class My {} +export +@dec1 @dec2 class My {} + +export +@dec1 +@dec2 class My {} + +export +@dec1 +@dec2 +class My {} + +@dec1 +export @dec2 class My {} + +@dec1 export @dec2 class My {} + +@dec1 export +@dec2 class My {} + +@dec1 +export +@dec2 class My {} + +@dec1 @dec2 export @dec3 @dec4 class My {} +export @dec1 @dec2 @dec3 @dec4 class My {} + + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +@dec1 +export class My {} +@dec1 +export class My {} +@dec1 +@dec2 +export class My {} +@dec1 +@dec2 +export class My {} + +@dec1 +@dec2 +export class My {} + +export +@dec1 +class My {} +export +@dec1 +class My {} +export +@dec1 +class My {} + +export +@dec1 +@dec2 +class My {} +export +@dec1 +@dec2 +class My {} +export +@dec1 +@dec2 +class My {} +export +@dec1 +@dec2 +class My {} + +export +@dec1 +@dec2 +class My {} + +export +@dec1 +@dec2 +class My {} + +@dec1 +@dec2 +export class My {} + +@dec1 +@dec2 +export class My {} + +@dec1 +@dec2 +export class My {} + +@dec1 +@dec2 +export class My {} + +@dec1 +@dec2 +@dec3 +@dec4 +export class My {} +export +@dec1 +@dec2 +@dec3 +@dec4 +class My {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple_call_decorator.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple_call_decorator.js new file mode 100644 index 00000000000..0b63f92d6a2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple_call_decorator.js @@ -0,0 +1,48 @@ +@decorator.method(value) export class Foo {} +@decorator.method(value) +export class Foo {} +@decorator.method(value) @decorator2.method(value) export class Foo {} +@decorator.method(value) +@decorator2.method(value) export class Foo {} + +@decorator.method(value) @decorator2.method(value) +export class Foo {} + +export @decorator.method(value) class Foo {} +export @decorator.method(value) +class Foo {} +export +@decorator.method(value) class Foo {} + +export @decorator.method(value) @decorator2.method(value) class Foo {} +export @decorator.method(value) +@decorator2.method(value) class Foo {} +export @decorator.method(value) +@decorator2.method(value) class Foo {} +export +@decorator.method(value) @decorator2.method(value) class Foo {} + +export +@decorator.method(value) +@decorator2.method(value) class Foo {} + +export +@decorator.method(value) +@decorator2.method(value) +class Foo {} + +@decorator.method(value) +export @decorator2.method(value) class Foo {} + +@decorator.method(value) export @decorator2.method(value) class Foo {} + +@decorator.method(value) export +@decorator2.method(value) class Foo {} + +@decorator.method(value) +export +@decorator2.method(value) class Foo {} + +@decorator.method(value) @decorator2.method(value) export @decorator3.method(value) @decorator4.method(value) class Foo {} +export @decorator.method(value) @decorator2.method(value) @decorator3.method(value) @decorator4.method(value) class Foo {} + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple_call_decorator.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple_call_decorator.js.snap new file mode 100644 index 00000000000..6719c7723a4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/class_simple_call_decorator.js.snap @@ -0,0 +1,158 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/class_simple_call_decorator.js +--- + +# Input + +```js +@decorator.method(value) export class Foo {} +@decorator.method(value) +export class Foo {} +@decorator.method(value) @decorator2.method(value) export class Foo {} +@decorator.method(value) +@decorator2.method(value) export class Foo {} + +@decorator.method(value) @decorator2.method(value) +export class Foo {} + +export @decorator.method(value) class Foo {} +export @decorator.method(value) +class Foo {} +export +@decorator.method(value) class Foo {} + +export @decorator.method(value) @decorator2.method(value) class Foo {} +export @decorator.method(value) +@decorator2.method(value) class Foo {} +export @decorator.method(value) +@decorator2.method(value) class Foo {} +export +@decorator.method(value) @decorator2.method(value) class Foo {} + +export +@decorator.method(value) +@decorator2.method(value) class Foo {} + +export +@decorator.method(value) +@decorator2.method(value) +class Foo {} + +@decorator.method(value) +export @decorator2.method(value) class Foo {} + +@decorator.method(value) export @decorator2.method(value) class Foo {} + +@decorator.method(value) export +@decorator2.method(value) class Foo {} + +@decorator.method(value) +export +@decorator2.method(value) class Foo {} + +@decorator.method(value) @decorator2.method(value) export @decorator3.method(value) @decorator4.method(value) class Foo {} +export @decorator.method(value) @decorator2.method(value) @decorator3.method(value) @decorator4.method(value) class Foo {} + + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +@decorator.method(value) +export class Foo {} +@decorator.method(value) +export class Foo {} +@decorator.method(value) +@decorator2.method(value) +export class Foo {} +@decorator.method(value) +@decorator2.method(value) +export class Foo {} + +@decorator.method(value) +@decorator2.method(value) +export class Foo {} + +export +@decorator.method(value) +class Foo {} +export +@decorator.method(value) +class Foo {} +export +@decorator.method(value) +class Foo {} + +export +@decorator.method(value) +@decorator2.method(value) +class Foo {} +export +@decorator.method(value) +@decorator2.method(value) +class Foo {} +export +@decorator.method(value) +@decorator2.method(value) +class Foo {} +export +@decorator.method(value) +@decorator2.method(value) +class Foo {} + +export +@decorator.method(value) +@decorator2.method(value) +class Foo {} + +export +@decorator.method(value) +@decorator2.method(value) +class Foo {} + +@decorator.method(value) +@decorator2.method(value) +export class Foo {} + +@decorator.method(value) +@decorator2.method(value) +export class Foo {} + +@decorator.method(value) +@decorator2.method(value) +export class Foo {} + +@decorator.method(value) +@decorator2.method(value) +export class Foo {} + +@decorator.method(value) +@decorator2.method(value) +@decorator3.method(value) +@decorator4.method(value) +export class Foo {} +export +@decorator.method(value) +@decorator2.method(value) +@decorator3.method(value) +@decorator4.method(value) +class Foo {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_1.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_1.js new file mode 100644 index 00000000000..fa13a163af4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_1.js @@ -0,0 +1 @@ +@dec export default class Foo {} diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_1.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_1.js.snap new file mode 100644 index 00000000000..ea2bb9ddb94 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_1.js.snap @@ -0,0 +1,34 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/export_default_1.js +--- + +# Input + +```js +@dec export default class Foo {} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +@dec +export default class Foo {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_2.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_2.js new file mode 100644 index 00000000000..1673ed1505b --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_2.js @@ -0,0 +1 @@ + export default @dec class Foo {} diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_2.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_2.js.snap new file mode 100644 index 00000000000..7845aa91a90 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_2.js.snap @@ -0,0 +1,35 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/export_default_2.js +--- + +# Input + +```js + export default @dec class Foo {} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +export default +@dec +class Foo {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_3.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_3.js new file mode 100644 index 00000000000..079f9d880a8 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_3.js @@ -0,0 +1 @@ +@dec1 export default @dec2 class Foo {} diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_3.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_3.js.snap new file mode 100644 index 00000000000..96710fb39c2 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_3.js.snap @@ -0,0 +1,35 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/export_default_3.js +--- + +# Input + +```js +@dec1 export default @dec2 class Foo {} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +@dec1 +@dec2 +export default class Foo {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_4.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_4.js new file mode 100644 index 00000000000..e59a24cb773 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_4.js @@ -0,0 +1 @@ +@dec1 @dec2 export default @dec3 @dec4 class Foo {} diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_4.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_4.js.snap new file mode 100644 index 00000000000..a5cbf12f83d --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/export_default_4.js.snap @@ -0,0 +1,37 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/export_default_4.js +--- + +# Input + +```js +@dec1 @dec2 export default @dec3 @dec4 class Foo {} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +@dec1 +@dec2 +@dec3 +@dec4 +export default class Foo {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/expression.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/expression.js new file mode 100644 index 00000000000..81d0bb4d2b0 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/expression.js @@ -0,0 +1,21 @@ +console.log(@deco class Foo {}) +console.log(@deco class {}) + +const a1 = (@deco class Foo {}); +const a2 = (@deco class {}); + +(@deco class Foo {}); +(@deco class {}); + +const b1 = [] +;(@deco class Foo {}) + +const b2 = [] +;(@deco class {}) + +(@deco class Foo {}).name; +(@deco class {}).name; + +class Foo extends (@deco class Foo {}){} + +class Foo extends (@deco class {}){} diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/expression.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/expression.js.snap new file mode 100644 index 00000000000..eeecbc7352a --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/expression.js.snap @@ -0,0 +1,115 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/expression.js +--- + +# Input + +```js +console.log(@deco class Foo {}) +console.log(@deco class {}) + +const a1 = (@deco class Foo {}); +const a2 = (@deco class {}); + +(@deco class Foo {}); +(@deco class {}); + +const b1 = [] +;(@deco class Foo {}) + +const b2 = [] +;(@deco class {}) + +(@deco class Foo {}).name; +(@deco class {}).name; + +class Foo extends (@deco class Foo {}){} + +class Foo extends (@deco class {}){} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +console.log( + ( + @deco + class Foo {} + ), +); +console.log( + ( + @deco + class {} + ), +); + +const a1 = + ( + @deco + class Foo {} + ); +const a2 = + ( + @deco + class {} + ); + +( + @deco + class Foo {} +); +( + @deco + class {} +); + +const b1 = []; +( + @deco + class Foo {} +); + +const b2 = []; +( + @deco + class {} +)( + ( + @deco + class Foo {} + ), +).name; +( + @deco + class {} +).name; + +class Foo extends ( + @deco + class Foo {} +) {} + +class Foo extends ( + @deco + class {} +) {} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/multiline.js b/crates/rome_js_formatter/tests/specs/js/module/decorators/multiline.js new file mode 100644 index 00000000000..31b1724a5ea --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/multiline.js @@ -0,0 +1,16 @@ +class Foo { + @deco([ + foo, + bar + ]) prop = value; + + @decorator([]) method() {} + + @decorator([ + ]) method() {} + + @decorator({}) method() {} + + @decorator({ + }) method() {} +} diff --git a/crates/rome_js_formatter/tests/specs/js/module/decorators/multiline.js.snap b/crates/rome_js_formatter/tests/specs/js/module/decorators/multiline.js.snap new file mode 100644 index 00000000000..9c65a432dea --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/js/module/decorators/multiline.js.snap @@ -0,0 +1,58 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: js/module/decorators/multiline.js +--- + +# Input + +```js +class Foo { + @deco([ + foo, + bar + ]) prop = value; + + @decorator([]) method() {} + + @decorator([ + ]) method() {} + + @decorator({}) method() {} + + @decorator({ + }) method() {} +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```js +class Foo { + @deco([foo, bar]) prop = value; + + @decorator([]) method() {} + + @decorator([]) method() {} + + @decorator({}) method() {} + + @decorator({}) method() {} +} +``` + + diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/decorators.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/decorators.js.snap deleted file mode 100644 index ab49cc76aac..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/babel-plugins/decorators.js.snap +++ /dev/null @@ -1,92 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/babel-plugins/decorators.js ---- - -# Input - -```js -// https://babeljs.io/docs/en/babel-plugin-proposal-decorators - -@annotation -class MyClass { } - -function annotation(target) { - target.annotated = true; -} - -@isTestable(true) -class MyClass { } - -function isTestable(value) { - return function decorator(target) { - target.isTestable = value; - } -} - -class C { - @enumerable(false) - method() { } -} - -function enumerable(value) { - return function (target, key, descriptor) { - descriptor.enumerable = value; - return descriptor; - } -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -17,8 +17,7 @@ - } - - class C { -- @enumerable(false) -- method() {} -+ @enumerable(false) method() {} - } - - function enumerable(value) { -``` - -# Output - -```js -// https://babeljs.io/docs/en/babel-plugin-proposal-decorators - -@annotation -class MyClass {} - -function annotation(target) { - target.annotated = true; -} - -@isTestable(true) -class MyClass {} - -function isTestable(value) { - return function decorator(target) { - target.isTestable = value; - }; -} - -class C { - @enumerable(false) method() {} -} - -function enumerable(value) { - return function (target, key, descriptor) { - descriptor.enumerable = value; - return descriptor; - }; -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/comments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/comments.js.snap deleted file mode 100644 index 25eb7ff0f60..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorator-auto-accessors/comments.js.snap +++ /dev/null @@ -1,41 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorator-auto-accessors/comments.js ---- - -# Input - -```js -class A { - @dec() - // comment - accessor b; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,5 +1,4 @@ - class A { -- @dec() -- // comment -+ @dec() // comment - accessor b; - } -``` - -# Output - -```js -class A { - @dec() // comment - accessor b; -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators-export/after_export.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators-export/after_export.js.snap deleted file mode 100644 index c21028ce0a5..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators-export/after_export.js.snap +++ /dev/null @@ -1,43 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators-export/after_export.js ---- - -# Input - -```js -export @decorator class Foo {} - -export default @decorator class {} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,7 +1,5 @@ --export --@decorator -+export @decorator - class Foo {} - --export default --@decorator -+export default @decorator - class {} -``` - -# Output - -```js -export @decorator -class Foo {} - -export default @decorator -class {} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.snap deleted file mode 100644 index 8c2b7d88ef5..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/arguments.js.snap +++ /dev/null @@ -1,44 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/class-expression/arguments.js ---- - -# Input - -```js -console.log(@deco class Foo {}) -console.log(@deco class {}) - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,12 +1,2 @@ --console.log( -- ( -- @deco -- class Foo {} -- ), --); --console.log( -- ( -- @deco -- class {} -- ), --); -+console.log(@deco class Foo {}); -+console.log(@deco class {}); -``` - -# Output - -```js -console.log(@deco class Foo {}); -console.log(@deco class {}); -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.snap deleted file mode 100644 index 0261d96a5e8..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/class-expression.js.snap +++ /dev/null @@ -1,103 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/class-expression/class-expression.js ---- - -# Input - -```js -const a1 = (@deco class Foo {}); -const a2 = (@deco class {}); - -(@deco class Foo {}); -(@deco class {}); - -const b1 = [] -;(@deco class Foo {}) - -const b2 = [] -;(@deco class {}) - -// This is not a `ClassExpression` but `ClassDeclaration` -@deco class Foo {} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,34 +1,18 @@ --const a1 = -- ( -- @deco -- class Foo {} -- ); --const a2 = -- ( -- @deco -- class {} -- ); -+const a1 = @deco class Foo {}; -+const a2 = @deco class {}; - --( -- @deco -- class Foo {} --); --( -- @deco -- class {} --); -+(@deco -+class Foo {}); -+(@deco -+class {}); - - const b1 = []; --( -- @deco -- class Foo {} --); -+(@deco -+class Foo {}); - - const b2 = []; --( -- @deco -- class {} --); -+(@deco -+class {}); - - // This is not a `ClassExpression` but `ClassDeclaration` - @deco -``` - -# Output - -```js -const a1 = @deco class Foo {}; -const a2 = @deco class {}; - -(@deco -class Foo {}); -(@deco -class {}); - -const b1 = []; -(@deco -class Foo {}); - -const b2 = []; -(@deco -class {}); - -// This is not a `ClassExpression` but `ClassDeclaration` -@deco -class Foo {} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/member-expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/member-expression.js.snap deleted file mode 100644 index 87883594442..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/member-expression.js.snap +++ /dev/null @@ -1,44 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/class-expression/member-expression.js ---- - -# Input - -```js -(@deco class Foo {}).name; -(@deco class {}).name; - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,8 +1,4 @@ --( -- @deco -- class Foo {} --).name; --( -- @deco -- class {} --).name; -+(@deco -+class Foo {}).name; -+(@deco -+class {}).name; -``` - -# Output - -```js -(@deco -class Foo {}).name; -(@deco -class {}).name; -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/super-class.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/super-class.js.snap deleted file mode 100644 index 836d1f81d0e..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/class-expression/super-class.js.snap +++ /dev/null @@ -1,43 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/class-expression/super-class.js ---- - -# Input - -```js -class Foo extends (@deco class Foo {}){} - -class Foo extends (@deco class {}){} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,9 +1,3 @@ --class Foo extends ( -- @deco -- class Foo {} --) {} -+class Foo extends @deco class Foo {} {} - --class Foo extends ( -- @deco -- class {} --) {} -+class Foo extends @deco class {} {} -``` - -# Output - -```js -class Foo extends @deco class Foo {} {} - -class Foo extends @deco class {} {} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap deleted file mode 100644 index 01266db2ad0..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/classes.js.snap +++ /dev/null @@ -1,85 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/classes.js ---- - -# Input - -```js -@deco class Foo {} - -@deco export class Bar {} - -@deco export default class Baz {} - -const foo = @deco class { - // -}; - -const bar = - @deco - class { - // - }; - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -7,18 +7,12 @@ - @deco - export default class Baz {} - --const foo = -- ( -- @deco -- class { -- // -- } -- ); -+const foo = @deco -+class { -+ // -+}; - --const bar = -- ( -- @deco -- class { -- // -- } -- ); -+const bar = @deco -+class { -+ // -+}; -``` - -# Output - -```js -@deco -class Foo {} - -@deco -export class Bar {} - -@deco -export default class Baz {} - -const foo = @deco -class { - // -}; - -const bar = @deco -class { - // -}; -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap index 772996685af..3d86037e90e 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/member-expression.js.snap @@ -65,76 +65,24 @@ info: js/decorators/member-expression.js ```diff --- Prettier +++ Rome -@@ -1,54 +1,42 @@ - [ - class { -- @(decorators[0]) -- method() {} -+ @(decorators[0]) method() {} - }, - class { - @decorators [0]; +@@ -12,7 +12,7 @@ method() {} }, class { -- @(decorators?.[0]) -- method() {} -+ @(decorators?.[0]) method() {} - }, - class { - @decorators.at(0) -- method() {} -+ @(decorators.at(0)) method() {} - }, - class { -- @(decorators?.at(0)) -- method() {} -+ @(decorators?.at(0)) method() {} -+ }, -+ class { -+ @(decorators.first) method() {} -+ }, -+ class { -+ @(decorators?.first) method() {} - }, - class { -- @decorators.first -- method() {} -+ @(decorators[first]) method() {} - }, - class { -- @(decorators?.first) -+ @decorators [first]; ++ @(decorators.at(0)) method() {} }, class { -- @(decorators[first]) -- method() {} -+ @(decorators["first"]) method() {} - }, -+ @(decorators[first]) - class { -- @decorators [first]; +@@ -20,7 +20,7 @@ method() {} }, -+ @(decorators[0]) class { -- @(decorators["first"]) +- @decorators.first ++ @(decorators.first) method() {} }, -- ( -- @(decorators[first]) -- class { -- method() {} -- } -- ), -- ( -- @(decorators[0]) -- class { -- method() {} -- } -- ), - ]; + class { ``` # Output @@ -142,45 +90,57 @@ info: js/decorators/member-expression.js ```js [ class { - @(decorators[0]) method() {} + @(decorators[0]) + method() {} }, class { @decorators [0]; method() {} }, class { - @(decorators?.[0]) method() {} - }, - class { - @(decorators.at(0)) method() {} - }, - class { - @(decorators?.at(0)) method() {} + @(decorators?.[0]) + method() {} }, class { - @(decorators.first) method() {} + @(decorators.at(0)) + method() {} }, class { - @(decorators?.first) method() {} + @(decorators?.at(0)) + method() {} }, class { - @(decorators[first]) method() {} + @(decorators.first) + method() {} }, class { - @decorators [first]; + @(decorators?.first) method() {} }, class { - @(decorators["first"]) method() {} + @(decorators[first]) + method() {} }, - @(decorators[first]) class { + @decorators [first]; method() {} }, - @(decorators[0]) class { + @(decorators["first"]) method() {} }, + ( + @(decorators[first]) + class { + method() {} + } + ), + ( + @(decorators[0]) + class { + method() {} + } + ), ]; ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/methods.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/methods.js.snap deleted file mode 100644 index a547c14df8a..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/methods.js.snap +++ /dev/null @@ -1,64 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/methods.js ---- - -# Input - -```js - -class Yo { - @foo("hello") - async plop() {} - - @anotherDecoratorWithALongName("and a very long string as a first argument") - async plip() {} - - @anotherDecoratorWithALongName("another very long string, but now inline") async plip() {} -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,10 +1,11 @@ - class Yo { -- @foo("hello") -- async plop() {} -+ @foo("hello") async plop() {} - -- @anotherDecoratorWithALongName("and a very long string as a first argument") -- async plip() {} -+ @anotherDecoratorWithALongName( -+ "and a very long string as a first argument", -+ ) async plip() {} - -- @anotherDecoratorWithALongName("another very long string, but now inline") -- async plip() {} -+ @anotherDecoratorWithALongName( -+ "another very long string, but now inline", -+ ) async plip() {} - } -``` - -# Output - -```js -class Yo { - @foo("hello") async plop() {} - - @anotherDecoratorWithALongName( - "and a very long string as a first argument", - ) async plip() {} - - @anotherDecoratorWithALongName( - "another very long string, but now inline", - ) async plip() {} -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mixed.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mixed.js.snap deleted file mode 100644 index 686f9673b3a..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mixed.js.snap +++ /dev/null @@ -1,46 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/mixed.js ---- - -# Input - -```js -// https://github.com/prettier/prettier/issues/6747 - -@foo -export default class MyComponent { - @task - *foo() { - } -} -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -2,6 +2,5 @@ - - @foo - export default class MyComponent { -- @task -- *foo() {} -+ @task *foo() {} - } -``` - -# Output - -```js -// https://github.com/prettier/prettier/issues/6747 - -@foo -export default class MyComponent { - @task *foo() {} -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap index 5d8d2458c12..54489131594 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/mobx.js.snap @@ -62,31 +62,7 @@ import {observable} from "mobx"; constructor(price) { this.price = price; -@@ -17,30 +17,19 @@ - this.price = price; - } - -- @computed -- get total() { -+ @computed get total() { - return this.price * this.amount; - } - -- @action.bound -- setPrice(price) { -+ @action.bound setPrice(price) { - this.price = price; - } - -- @computed -- @computed -- @computed -- @computed -- @computed -- @computed -- @computed -- get total() { -+ @computed @computed @computed @computed @computed @computed @computed get total() { +@@ -38,9 +38,7 @@ return this.price * this.amount; } @@ -122,15 +98,24 @@ class OrderLine { this.price = price; } - @computed get total() { + @computed + get total() { return this.price * this.amount; } - @action.bound setPrice(price) { + @action.bound + setPrice(price) { this.price = price; } - @computed @computed @computed @computed @computed @computed @computed get total() { + @computed + @computed + @computed + @computed + @computed + @computed + @computed + get total() { return this.price * this.amount; } @@ -198,9 +183,8 @@ mobx.js:35:35 parse ━━━━━━━━━━━━━━━━━━━━ # Lines exceeding max width of 80 characters ``` - 28: @computed @computed @computed @computed @computed @computed @computed get total() { - 32: @action handleDecrease = (event: React.ChangeEvent) => this.count--; - 34: @action handleSomething = (event: React.ChangeEvent) => doSomething(); + 41: @action handleDecrease = (event: React.ChangeEvent) => this.count--; + 43: @action handleSomething = (event: React.ChangeEvent) => doSomething(); ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/parens.js.snap b/crates/rome_js_formatter/tests/specs/prettier/js/decorators/parens.js.snap deleted file mode 100644 index 6d8f478c33b..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/js/decorators/parens.js.snap +++ /dev/null @@ -1,38 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: js/decorators/parens.js ---- - -# Input - -```js -class X { - @(computed().volatile()) - x -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,4 +1,3 @@ - class X { -- @(computed().volatile()) -- x; -+ @(computed().volatile()) x; - } -``` - -# Output - -```js -class X { - @(computed().volatile()) x; -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/accessor-decorator.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/accessor-decorator.ts.snap deleted file mode 100644 index 5aae442e051..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/accessor-decorator.ts.snap +++ /dev/null @@ -1,75 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/decorators-ts/accessor-decorator.ts ---- - -# Input - -```ts -class Point { - private _x: number; - private _y: number; - constructor(x: number, y: number) { - this._x = x; - this._y = y; - } - - @configurable(false) - get x() { - return this._x; - } - - @configurable(false) - get y() { - return this._y; - } -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -6,13 +6,11 @@ - this._y = y; - } - -- @configurable(false) -- get x() { -+ @configurable(false) get x() { - return this._x; - } - -- @configurable(false) -- get y() { -+ @configurable(false) get y() { - return this._y; - } - } -``` - -# Output - -```ts -class Point { - private _x: number; - private _y: number; - constructor(x: number, y: number) { - this._x = x; - this._y = y; - } - - @configurable(false) get x() { - return this._x; - } - - @configurable(false) get y() { - return this._y; - } -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/method-decorator.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/method-decorator.ts.snap deleted file mode 100644 index c6153379280..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/method-decorator.ts.snap +++ /dev/null @@ -1,56 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/decorators-ts/method-decorator.ts ---- - -# Input - -```ts -class Greeter { - greeting: string; - constructor(message: string) { - this.greeting = message; - } - - @enumerable(false) - greet() { - return "Hello, " + this.greeting; - } -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -4,8 +4,7 @@ - this.greeting = message; - } - -- @enumerable(false) -- greet() { -+ @enumerable(false) greet() { - return "Hello, " + this.greeting; - } - } -``` - -# Output - -```ts -class Greeter { - greeting: string; - constructor(message: string) { - this.greeting = message; - } - - @enumerable(false) greet() { - return "Hello, " + this.greeting; - } -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/multiple.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/multiple.ts.snap deleted file mode 100644 index 4a1fd584d24..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/multiple.ts.snap +++ /dev/null @@ -1,40 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/decorators-ts/multiple.ts ---- - -# Input - -```ts -class C { - @f() - @g() - method() {} -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,5 +1,3 @@ - class C { -- @f() -- @g() -- method() {} -+ @f() @g() method() {} - } -``` - -# Output - -```ts -class C { - @f() @g() method() {} -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/parameter-decorator.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/parameter-decorator.ts.snap deleted file mode 100644 index 59d4114f438..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/parameter-decorator.ts.snap +++ /dev/null @@ -1,73 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/decorators-ts/parameter-decorator.ts ---- - -# Input - -```ts -class Greeter { - greeting: string; - - constructor(message: string) { - this.greeting = message; - } - - @validate - greet(@required name: string) { - return "Hello " + name + ", " + this.greeting; - } - - @validate - destructured(@required { toString }: Object) { - return Function.prototype.toString.apply(toString); - } -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -5,13 +5,11 @@ - this.greeting = message; - } - -- @validate -- greet(@required name: string) { -+ @validate greet(@required name: string) { - return "Hello " + name + ", " + this.greeting; - } - -- @validate -- destructured(@required { toString }: Object) { -+ @validate destructured(@required { toString }: Object) { - return Function.prototype.toString.apply(toString); - } - } -``` - -# Output - -```ts -class Greeter { - greeting: string; - - constructor(message: string) { - this.greeting = message; - } - - @validate greet(@required name: string) { - return "Hello " + name + ", " + this.greeting; - } - - @validate destructured(@required { toString }: Object) { - return Function.prototype.toString.apply(toString); - } -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/typeorm.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/typeorm.ts.snap index 105671c1320..9e1b6246a5c 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/typeorm.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators-ts/typeorm.ts.snap @@ -37,35 +37,16 @@ export class Board { ```diff --- Prettier +++ Rome -@@ -1,20 +1,17 @@ - @Entity() - export class Board { -- @PrimaryGeneratedColumn() -- id: number; -+ @PrimaryGeneratedColumn() id: number; - -- @Column() -- slug: string; -+ @Column() slug: string; - -- @Column() -- name: string; -+ @Column() name: string; - -- @Column() -- theme: string; -+ @Column() theme: string; - -- @Column() -- description: string; -+ @Column() description: string; +@@ -15,6 +15,9 @@ + @Column() + description: string; - @OneToMany((type) => Topic, (topic) => topic.board) -- topics: Topic[]; + @OneToMany( + (type) => Topic, + (topic) => topic.board, -+ ) topics: Topic[]; ++ ) + topics: Topic[]; } ``` @@ -74,20 +55,26 @@ export class Board { ```ts @Entity() export class Board { - @PrimaryGeneratedColumn() id: number; + @PrimaryGeneratedColumn() + id: number; - @Column() slug: string; + @Column() + slug: string; - @Column() name: string; + @Column() + name: string; - @Column() theme: string; + @Column() + theme: string; - @Column() description: string; + @Column() + description: string; @OneToMany( (type) => Topic, (topic) => topic.board, - ) topics: Topic[]; + ) + topics: Topic[]; } ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/accessor.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/accessor.ts.snap deleted file mode 100644 index 97e2570950c..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/accessor.ts.snap +++ /dev/null @@ -1,48 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/decorators/accessor.ts ---- - -# Input - -```ts -class A { - @foo() - get a() {return 1} - @bar() - set a(v) {} -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,8 +1,6 @@ - class A { -- @foo() -- get a() { -+ @foo() get a() { - return 1; - } -- @bar() -- set a(v) {} -+ @bar() set a(v) {} - } -``` - -# Output - -```ts -class A { - @foo() get a() { - return 1; - } - @bar() set a(v) {} -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/comments.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/comments.ts.snap deleted file mode 100644 index d98bfceb7b1..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/comments.ts.snap +++ /dev/null @@ -1,41 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/decorators/comments.ts ---- - -# Input - -```ts -class Something { - @Annotateme() - // comment - static property: Array; -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,5 +1,4 @@ - class Something { -- @Annotateme() -- // comment -+ @Annotateme() // comment - static property: Array; - } -``` - -# Output - -```ts -class Something { - @Annotateme() // comment - static property: Array; -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap index 94be4c515b8..187ed4c52f5 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/decorators-comments.ts.snap @@ -51,44 +51,36 @@ class Something2 { ```diff --- Prettier +++ Rome -@@ -1,35 +1,30 @@ +@@ -1,7 +1,7 @@ class Foo1 { -- @foo + @foo - // comment - async method() {} -+ @foo async // comment ++ async // comment + method() {} } class Foo2 { -- @foo -- // comment -+ @foo // comment - private method() {} - } +@@ -12,14 +12,14 @@ class Foo3 { -- @foo + @foo - // comment - *method() {} -+ @foo *// comment ++ *// comment + method() {} } class Foo4 { -- @foo + @foo - // comment - async *method() {} -+ @foo async *// comment ++ async *// comment + method() {} } class Something { -- @foo() -- // comment -+ @foo() // comment - readonly property: Array; - } +@@ -30,6 +30,6 @@ class Something2 { @foo() @@ -103,27 +95,32 @@ class Something2 { ```ts class Foo1 { - @foo async // comment + @foo + async // comment method() {} } class Foo2 { - @foo // comment + @foo + // comment private method() {} } class Foo3 { - @foo *// comment + @foo + *// comment method() {} } class Foo4 { - @foo async *// comment + @foo + async *// comment method() {} } class Something { - @foo() // comment + @foo() + // comment readonly property: Array; } diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/inline-decorators.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/inline-decorators.ts.snap index 2adab07208a..6429f63b114 100644 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/inline-decorators.ts.snap +++ b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/inline-decorators.ts.snap @@ -64,32 +64,7 @@ class MyContainerComponent { ```diff --- Prettier +++ Rome -@@ -5,20 +5,13 @@ - class Class1 {} - - class Class2 { -- @d1 -- @d2(foo) -- @d3.bar -- @d4.baz() -- method1() {} -+ @d1 @d2(foo) @d3.bar @d4.baz() method1() {} - -- @d1 -- method2() {} -+ @d1 method2() {} - -- @d2(foo) -- method3() {} -+ @d2(foo) method3() {} - -- @d3.bar -- method4() {} -+ @d3.bar method4() {} - } - - class Class3 { -@@ -30,11 +23,10 @@ +@@ -30,11 +30,10 @@ constructor( @d1 private x: number, @d2(foo) private y: number, @@ -104,16 +79,6 @@ class MyContainerComponent { ) {} } -@@ -46,6 +38,7 @@ - } - - class MyContainerComponent { -- @ContentChildren(MyComponent) -- components: QueryListSomeBigName; -+ @ContentChildren( -+ MyComponent, -+ ) components: QueryListSomeBigName; - } ``` # Output @@ -126,13 +91,20 @@ class MyContainerComponent { class Class1 {} class Class2 { - @d1 @d2(foo) @d3.bar @d4.baz() method1() {} + @d1 + @d2(foo) + @d3.bar + @d4.baz() + method1() {} - @d1 method2() {} + @d1 + method2() {} - @d2(foo) method3() {} + @d2(foo) + method3() {} - @d3.bar method4() {} + @d3.bar + method4() {} } class Class3 { @@ -159,9 +131,8 @@ class Bar { } class MyContainerComponent { - @ContentChildren( - MyComponent, - ) components: QueryListSomeBigName; + @ContentChildren(MyComponent) + components: QueryListSomeBigName; } ``` diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.snap deleted file mode 100644 index 6640a1206d7..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/legacy.ts.snap +++ /dev/null @@ -1,61 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/decorators/legacy.ts ---- - -# Input - -```ts -[ - @decorator() class {}, - @decorator() class A {}, -]; - -class A { - @decorator() accessor #field; -} - -class B { - @decorator() #field () {} -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,13 +1,4 @@ --[ -- ( -- @decorator() -- class {} -- ), -- ( -- @decorator() -- class A {} -- ), --]; -+[@decorator() class {}, @decorator() class A {}]; - - class A { - @decorator() accessor #field; -``` - -# Output - -```ts -[@decorator() class {}, @decorator() class A {}]; - -class A { - @decorator() accessor #field; -} - -class B { - @decorator() #field() {} -} -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/mobx.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/mobx.ts.snap deleted file mode 100644 index 708d5fecaee..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/decorators/mobx.ts.snap +++ /dev/null @@ -1,131 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/decorators/mobx.ts ---- - -# Input - -```ts -import {observable} from "mobx"; - -@observer class OrderLine { - @observable price:number = 0; - @observable amount:number = 1; - - constructor(price) { - this.price = price; - } - - @computed get total() { - return this.price * this.amount; - } - - @action.bound setPrice(price) { - this.price = price; - } - - @computed - get total2() { - return this.price * this.amount; - } - - @action.bound - setPrice(price) { - this.price = price; - } - - @computed @computed @computed @computed @computed @computed @computed get total3() { - return this.price * this.amount; - } - - @action handleDecrease = (event: React.ChangeEvent) => this.count--; - - @action handleSomething = (event: React.ChangeEvent) => doSomething(); -} - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -17,24 +17,15 @@ - this.price = price; - } - -- @computed -- get total2() { -+ @computed get total2() { - return this.price * this.amount; - } - -- @action.bound -- setPrice(price) { -+ @action.bound setPrice(price) { - this.price = price; - } - -- @computed -- @computed -- @computed -- @computed -- @computed -- @computed -- @computed -- get total3() { -+ @computed @computed @computed @computed @computed @computed @computed get total3() { - return this.price * this.amount; - } - -``` - -# Output - -```ts -import { observable } from "mobx"; - -@observer -class OrderLine { - @observable price: number = 0; - @observable amount: number = 1; - - constructor(price) { - this.price = price; - } - - @computed get total() { - return this.price * this.amount; - } - - @action.bound setPrice(price) { - this.price = price; - } - - @computed get total2() { - return this.price * this.amount; - } - - @action.bound setPrice(price) { - this.price = price; - } - - @computed @computed @computed @computed @computed @computed @computed get total3() { - return this.price * this.amount; - } - - @action handleDecrease = (event: React.ChangeEvent) => - this.count--; - - @action handleSomething = (event: React.ChangeEvent) => - doSomething(); -} -``` - -# Lines exceeding max width of 80 characters -``` - 28: @computed @computed @computed @computed @computed @computed @computed get total3() { -``` - - diff --git a/crates/rome_js_formatter/tests/specs/prettier/typescript/type-arguments-bit-shift-left-like/4.ts.snap b/crates/rome_js_formatter/tests/specs/prettier/typescript/type-arguments-bit-shift-left-like/4.ts.snap deleted file mode 100644 index 12571816f53..00000000000 --- a/crates/rome_js_formatter/tests/specs/prettier/typescript/type-arguments-bit-shift-left-like/4.ts.snap +++ /dev/null @@ -1,35 +0,0 @@ ---- -source: crates/rome_formatter_test/src/snapshot_builder.rs -info: typescript/type-arguments-bit-shift-left-like/4.ts ---- - -# Input - -```ts -(@f<(v: T) => void>() class {}); - -``` - - -# Prettier differences - -```diff ---- Prettier -+++ Rome -@@ -1,4 +1,2 @@ --( -- @f<(v: T) => void>() -- class {} --); -+(@f<(v: T) => void>() -+class {}); -``` - -# Output - -```ts -(@f<(v: T) => void>() -class {}); -``` - - diff --git a/crates/rome_js_formatter/tests/specs/ts/decoartors.ts.snap b/crates/rome_js_formatter/tests/specs/ts/decoartors.ts.snap index 6db5ce451da..08f7b6d0212 100644 --- a/crates/rome_js_formatter/tests/specs/ts/decoartors.ts.snap +++ b/crates/rome_js_formatter/tests/specs/ts/decoartors.ts.snap @@ -74,7 +74,8 @@ Semicolons: Always ```ts @sealed class Test { - @readonly prop: string; + @readonly + prop: string; constructor( @param test, @@ -104,7 +105,9 @@ class Test2 { */ @test /* trailing multiline comment - for decorator */ @anotherDecorator() // leading comment + for decorator */ + @anotherDecorator() + // leading comment prop: string; } ``` @@ -113,9 +116,9 @@ class Test2 { ## Unimplemented nodes/tokens -"\t\t@par" => 61..67 -"\t\t@readon" => 76..85 -"\t\t@aVeryLongDecoratorNameLetsSeeWhatHappensWith" => 103..150 -"@param" => 174..180 -"@param" => 218..224 +"\t\t@par" => 62..68 +"\t\t@readon" => 77..86 +"\t\t@aVeryLongDecoratorNameLetsSeeWhatHappensWith" => 104..151 +"@param" => 175..181 +"@param" => 219..225 diff --git a/crates/rome_js_formatter/tests/specs/ts/decorators/class_members.ts b/crates/rome_js_formatter/tests/specs/ts/decorators/class_members.ts new file mode 100644 index 00000000000..4f17f2e14d9 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/ts/decorators/class_members.ts @@ -0,0 +1,92 @@ +class Foo { + // one decorator without a newline + @dec public property; + @dec public method() {} + @dec public async method() {} + @dec public *method() {} + @dec public get getter() {} + @dec public set setter(val) {} + + // two decorators without a newline + @dec @dec public property; + @dec @dec public method() {} + @dec @dec public async method() {} + @dec @dec public *method() {} + @dec @dec public get getter() {} + @dec @dec public set setter(val) {} + + // one decorator with a newline + @dec + public property; + @dec + public method() {} + @dec + public async method() {} + @dec + public *method() {} + @dec + public get getter() {} + @dec + public set setter(val) {} + + // two decorators without a newline + @dec + @dec public property; + @dec + @dec public method() {} + @dec + @dec public async method() {} + @dec + @dec public *method() {} + @dec + @dec public get getter() {} + @dec + @dec public set setter(val) {} +} + + +class Foo { + // one decorator without a newline + /*before*/ @dec /*after*/ public property; + /*before*/ @dec /*after*/ public method() {} + /*before*/ @dec /*after*/ public async method() {} + /*before*/ @dec /*after*/ public *method() {} + /*before*/ @dec /*after*/ public get getter() {} + /*before*/ @dec /*after*/ public set setter(val) {} + + // two decorators without a newline + /*before*/ @dec /*middle*/ @dec /*after*/ public property; + /*before*/ @dec /*middle*/ @dec /*after*/ public method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public async method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public *method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public get getter() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public set setter(val) {} + + // one decorator with a newline + @dec /*before*/ + /*after*/ public property; + @dec /*before*/ + /*after*/ public method() {} + @dec /*before*/ + /*after*/ public async method() {} + @dec /*before*/ + /*after*/ public *method() {} + @dec /*before*/ + /*after*/ public get getter() {} + @dec /*before*/ + /*after*/ public set setter(val) {} + + // two decorators without a newline + @dec /*before*/ + /*middle*/ @dec /*after*/ public property; + @dec /*before*/ + /*middle*/ @dec /*after*/ public method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ public async method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ public *method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ public get getter() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ public set setter(val) {} +} diff --git a/crates/rome_js_formatter/tests/specs/ts/decorators/class_members.ts.snap b/crates/rome_js_formatter/tests/specs/ts/decorators/class_members.ts.snap new file mode 100644 index 00000000000..109b8b876c4 --- /dev/null +++ b/crates/rome_js_formatter/tests/specs/ts/decorators/class_members.ts.snap @@ -0,0 +1,226 @@ +--- +source: crates/rome_formatter_test/src/snapshot_builder.rs +info: ts/decorators/class_members.ts +--- + +# Input + +```ts +class Foo { + // one decorator without a newline + @dec public property; + @dec public method() {} + @dec public async method() {} + @dec public *method() {} + @dec public get getter() {} + @dec public set setter(val) {} + + // two decorators without a newline + @dec @dec public property; + @dec @dec public method() {} + @dec @dec public async method() {} + @dec @dec public *method() {} + @dec @dec public get getter() {} + @dec @dec public set setter(val) {} + + // one decorator with a newline + @dec + public property; + @dec + public method() {} + @dec + public async method() {} + @dec + public *method() {} + @dec + public get getter() {} + @dec + public set setter(val) {} + + // two decorators without a newline + @dec + @dec public property; + @dec + @dec public method() {} + @dec + @dec public async method() {} + @dec + @dec public *method() {} + @dec + @dec public get getter() {} + @dec + @dec public set setter(val) {} +} + + +class Foo { + // one decorator without a newline + /*before*/ @dec /*after*/ public property; + /*before*/ @dec /*after*/ public method() {} + /*before*/ @dec /*after*/ public async method() {} + /*before*/ @dec /*after*/ public *method() {} + /*before*/ @dec /*after*/ public get getter() {} + /*before*/ @dec /*after*/ public set setter(val) {} + + // two decorators without a newline + /*before*/ @dec /*middle*/ @dec /*after*/ public property; + /*before*/ @dec /*middle*/ @dec /*after*/ public method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public async method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public *method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public get getter() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public set setter(val) {} + + // one decorator with a newline + @dec /*before*/ + /*after*/ public property; + @dec /*before*/ + /*after*/ public method() {} + @dec /*before*/ + /*after*/ public async method() {} + @dec /*before*/ + /*after*/ public *method() {} + @dec /*before*/ + /*after*/ public get getter() {} + @dec /*before*/ + /*after*/ public set setter(val) {} + + // two decorators without a newline + @dec /*before*/ + /*middle*/ @dec /*after*/ public property; + @dec /*before*/ + /*middle*/ @dec /*after*/ public method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ public async method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ public *method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ public get getter() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ public set setter(val) {} +} + +``` + + +============================= + +# Outputs + +## Output 1 + +----- +Indent style: Tab +Line width: 80 +Quote style: Double Quotes +Quote properties: As needed +Trailing comma: All +Semicolons: Always +----- + +```ts +class Foo { + // one decorator without a newline + @dec public property; + @dec public method() {} + @dec public async method() {} + @dec public *method() {} + @dec public get getter() {} + @dec public set setter(val) {} + + // two decorators without a newline + @dec @dec public property; + @dec @dec public method() {} + @dec @dec public async method() {} + @dec @dec public *method() {} + @dec @dec public get getter() {} + @dec @dec public set setter(val) {} + + // one decorator with a newline + @dec + public property; + @dec + public method() {} + @dec + public async method() {} + @dec + public *method() {} + @dec + public get getter() {} + @dec + public set setter(val) {} + + // two decorators without a newline + @dec + @dec + public property; + @dec + @dec + public method() {} + @dec + @dec + public async method() {} + @dec + @dec + public *method() {} + @dec + @dec + public get getter() {} + @dec + @dec + public set setter(val) {} +} + +class Foo { + // one decorator without a newline + /*before*/ @dec /*after*/ public property; + /*before*/ @dec /*after*/ public method() {} + /*before*/ @dec /*after*/ public async method() {} + /*before*/ @dec /*after*/ public *method() {} + /*before*/ @dec /*after*/ public get getter() {} + /*before*/ @dec /*after*/ public set setter(val) {} + + // two decorators without a newline + /*before*/ @dec /*middle*/ @dec /*after*/ public property; + /*before*/ @dec /*middle*/ @dec /*after*/ public method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public async method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public *method() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public get getter() {} + /*before*/ @dec /*middle*/ @dec /*after*/ public set setter(val) {} + + // one decorator with a newline + @dec /*before*/ + /*after*/ public property; + @dec /*before*/ + /*after*/ public method() {} + @dec /*before*/ + /*after*/ public async method() {} + @dec /*before*/ + /*after*/ public *method() {} + @dec /*before*/ + /*after*/ public get getter() {} + @dec /*before*/ + /*after*/ public set setter(val) {} + + // two decorators without a newline + @dec /*before*/ + /*middle*/ @dec /*after*/ + public property; + @dec /*before*/ + /*middle*/ @dec /*after*/ + public method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ + public async method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ + public *method() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ + public get getter() {} + @dec /*before*/ + /*middle*/ @dec /*after*/ + public set setter(val) {} +} +``` + +