diff --git a/Cargo.lock b/Cargo.lock index 88b96231f2ad..932f29f08a12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1297,6 +1297,7 @@ dependencies = [ "rome_core", "rome_diagnostics", "rome_flags", + "rome_formatter", "rome_fs", "rome_js_formatter", "rome_js_parser", @@ -1365,6 +1366,7 @@ dependencies = [ name = "rome_formatter" version = "0.1.0" dependencies = [ + "cfg-if", "rome_rowan", "tracing", ] @@ -1392,7 +1394,6 @@ dependencies = [ name = "rome_js_formatter" version = "0.0.0" dependencies = [ - "cfg-if", "countme", "ctor", "iai", @@ -1472,6 +1473,7 @@ dependencies = [ "rome_console", "rome_diagnostics", "rome_flags", + "rome_formatter", "rome_fs", "rome_js_formatter", "rome_js_parser", @@ -1502,6 +1504,7 @@ dependencies = [ "rome_analyze", "rome_console", "rome_diagnostics", + "rome_formatter", "rome_js_formatter", "rome_js_parser", "serde_json", @@ -2357,6 +2360,7 @@ dependencies = [ "regex", "rome_analyze", "rome_diagnostics", + "rome_formatter", "rome_js_formatter", "rome_js_parser", "rome_js_syntax", diff --git a/crates/rome_cli/Cargo.toml b/crates/rome_cli/Cargo.toml index 319f64d0f94f..861cd4c18bf0 100644 --- a/crates/rome_cli/Cargo.toml +++ b/crates/rome_cli/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] rome_js_formatter = { path = "../rome_js_formatter" } +rome_formatter = { path = "../rome_formatter" } rome_js_parser = { path = "../rome_js_parser" } rome_diagnostics = { path = "../rome_diagnostics" } rome_core = { path = "../rome_core" } diff --git a/crates/rome_cli/src/commands/format.rs b/crates/rome_cli/src/commands/format.rs index 83f1a3e8ab03..cd95974b6124 100644 --- a/crates/rome_cli/src/commands/format.rs +++ b/crates/rome_cli/src/commands/format.rs @@ -21,9 +21,9 @@ use rome_diagnostics::{ file::{FileId, Files, SimpleFile}, Diagnostic, DiagnosticHeader, Severity, }; +use rome_formatter::{FormatOptions, IndentStyle}; use rome_fs::{AtomicInterner, FileSystem, PathInterner, RomePath}; use rome_fs::{TraversalContext, TraversalScope}; -use rome_js_formatter::{FormatOptions, IndentStyle}; use rome_js_parser::{parse, SourceType}; use crate::{CliSession, Termination}; diff --git a/crates/rome_formatter/Cargo.toml b/crates/rome_formatter/Cargo.toml index ab117cacf7c4..b62b00741d2a 100644 --- a/crates/rome_formatter/Cargo.toml +++ b/crates/rome_formatter/Cargo.toml @@ -7,4 +7,5 @@ edition = "2021" [dependencies] rome_rowan = { path = "../rome_rowan" } -tracing = { version = "0.1.31", default-features = false, features = ["std"] } \ No newline at end of file +tracing = { version = "0.1.31", default-features = false, features = ["std"] } +cfg-if = "1.0.0" diff --git a/crates/rome_formatter/src/builders.rs b/crates/rome_formatter/src/builders.rs index bf47e2c8eb83..ee65ebe4ccae 100644 --- a/crates/rome_formatter/src/builders.rs +++ b/crates/rome_formatter/src/builders.rs @@ -1,5 +1,4 @@ -use crate::format_element::List; -use crate::{empty_element, FormatElement}; +use crate::prelude::*; #[derive(Default)] pub struct ConcatBuilder { diff --git a/crates/rome_formatter/src/format_elements.rs b/crates/rome_formatter/src/format_elements.rs deleted file mode 100644 index 2da46dc5499c..000000000000 --- a/crates/rome_formatter/src/format_elements.rs +++ /dev/null @@ -1,73 +0,0 @@ -/// The macro `format_tokens` is a convenience macro to -/// use when writing a list of tokens that should be at the same level -/// without particular rule. -/// -/// # Examples -/// -/// Let's suppose you need to create tokens for the string `"foo": "bar"`, -/// you would write: -/// -/// ```rust -/// use rome_formatter::{format_elements, space_token, token}; -/// let element = format_elements![token("foo:"), space_token(), token("bar")]; -/// ``` -/// -/// The macro can be also nested, although the macro needs to be decorated with the token you need. -/// For example, let's try to format following string: -/// -/// ```no_rust -/// foo: { bar: lorem } -/// ``` -/// You would write it like the following: -/// -/// ```rust -/// use rome_formatter::{format_elements, space_token, token, FormatOptions, Formatted}; -/// let element = format_elements![ -/// token("foo:"), -/// space_token(), -/// token("{"), -/// space_token(), -/// token("bar:"), -/// space_token(), -/// token("lorem"), -/// space_token(), -/// token("}") -/// ]; -/// assert_eq!( -/// r#"foo: { bar: lorem }"#, -/// Formatted::new(element, FormatOptions::default()) -/// .print() -/// .as_code() -/// ); -/// ``` -/// Or you can also create single element: -/// ``` -/// use rome_formatter::{format_elements, token, FormatOptions, Formatted}; -/// let element = format_elements![token("single")]; -/// assert_eq!( -/// r#"single"#, -/// Formatted::new(element, FormatOptions::default()) -/// .print() -/// .as_code() -/// ); -/// ``` -#[macro_export] -macro_rules! format_elements { - - // called for things like format_tokens!["hey"] - ($element:expr) => { - { - use $crate::FormatElement; - FormatElement::from($element) - } - }; - - ( $( $element:expr ),+ $(,)?) => {{ - use $crate::{FormatElement, concat_elements}; - concat_elements([ - $( - FormatElement::from($element) - ),+ - ]) - }}; -} diff --git a/crates/rome_formatter/src/format_extensions.rs b/crates/rome_formatter/src/format_extensions.rs new file mode 100644 index 000000000000..b3e34e9869c9 --- /dev/null +++ b/crates/rome_formatter/src/format_extensions.rs @@ -0,0 +1,356 @@ +use crate::prelude::*; +use std::cell::RefCell; + +use crate::IntoFormatElement; +use rome_rowan::SyntaxResult; + +/// Utility trait used to simplify the formatting of optional objects that are formattable. +/// +/// In order to take advantage of all the functions, you only need to implement the [FormatOptionalTokenAndNode::with_or] +/// function. +pub trait FormatOptional { + /// This function tries to format an optional object. If the object is [None] + /// an [empty token](crate::FormatElement::Empty) is created. If exists, the utility + /// formats the object and passes it to the closure. + /// + /// ## Examples + /// + /// ``` + /// use rome_formatter::prelude::*; + /// use rome_rowan::TextSize; + /// + /// struct MyFormat; + /// + /// impl Format for MyFormat { + /// fn format(&self, formatter: &Formatter) -> FormatResult { + /// Ok(token("MyToken")) + /// } + /// } + /// + /// let formatter = Formatter::default(); + /// + /// let none_token: Option = None; + /// // Returns `empty_element()` for a `None` value + /// let none_result = none_token.with_or_empty(|token| token); + /// assert_eq!(Ok(empty_element()), formatted![&formatter, [none_result]]); + /// + /// let some_token = Some(MyFormat); + /// let some_result = some_token.with_or_empty(|token| { + /// formatted![&formatter, [space_token(), token]] + /// }); + /// assert_eq!(formatted![&formatter, [space_token(), token("MyToken")]], formatted![&formatter, [some_result]]); + fn with_or_empty( + &self, + with: With, + ) -> FormatWithOr FormatElement, WithResult, FormatElement> + where + With: Fn(FormatElement) -> WithResult, + WithResult: IntoFormatElement, + { + self.with_or(with, empty_element) + } + + /// This function tries to format an optional formattable object as is. If the object is [None], + /// it calls the passed closure, which has to return a [crate::FormatElement] + /// + /// ## Examples + /// + /// ``` + /// use rome_formatter::prelude::*; + /// use rome_rowan::TextSize; + /// + /// struct MyFormat; + /// + /// impl Format for MyFormat { + /// fn format(&self, formatter: &Formatter) -> FormatResult { + /// Ok(token("MyToken")) + /// } + /// } + /// + /// let formatter = Formatter::default(); + /// let none_token: Option = None; + /// let result = none_token.or_format(|| token(" other result")); + /// + /// assert_eq!(Ok(token(" other result")), formatted![&formatter, [result]]); + fn or_format( + &self, + op: Or, + ) -> FormatWithOr FormatElement, Or, FormatElement, OrResult> + where + Or: Fn() -> OrResult, + OrResult: IntoFormatElement, + Self: Sized, + { + self.with_or(|token| token, op) + } + + /// If the object isn't [None], it will call the first closure which will accept formatted element. + /// + /// If the object is [None], the second closure will be called. + /// + /// Both closures have to return a [crate::FormatElement]. This function will make sure to wrap them into [Ok]. + /// + /// ## Examples + /// + /// ``` + /// use rome_formatter::prelude::*; + /// use rome_rowan::TextSize; + /// + /// struct MyFormat; + /// + /// impl Format for MyFormat { + /// fn format(&self, formatter: &Formatter) -> FormatResult { + /// Ok(token("MyToken")) + /// } + /// } + /// + /// let formatter = Formatter::default(); + /// let none_token: Option = None; + /// + /// // It returns the `or` result if called on `None` + /// let none_result = none_token.with_or(|token| token, || { + /// token("empty") + /// }); + /// assert_eq!(Ok(token("empty")), formatted![&formatter, [none_result]]); + /// + /// // Returns the result of the first callback when called with `Some(value)` + /// let some_result = Some(MyFormat).with_or(|token| { + /// formatted![&formatter, [space_token(), token]] + /// }, || empty_element()); + /// + /// assert_eq!(formatted![&formatter, [space_token(), token("MyToken")]], formatted![&formatter, [some_result]]); + fn with_or( + &self, + with: With, + op: Or, + ) -> FormatWithOr + where + With: Fn(FormatElement) -> WithResult, + WithResult: IntoFormatElement, + Or: Fn() -> OrResult, + OrResult: IntoFormatElement; +} + +/// Utility trait for formatting a formattable object with some additional content. +pub trait FormatWith { + /// Allows to chain a formattable object with another [elements](FormatElement) + /// + /// The function will decorate the result with [Ok] + /// + /// The formatted element is passed to the closure, which then can appended to additional elements. + /// This method is useful in case, for example, a token has to be chained with a space. + /// + /// ## Examples + /// + /// ``` + /// use rome_formatter::prelude::*; + /// use rome_rowan::TextSize; + /// + /// struct MyFormat; + /// + /// impl Format for MyFormat { + /// fn format(&self, formatter: &Formatter) -> FormatResult { + /// Ok(token("MyToken")) + /// } + /// } + /// + /// let formatter = Formatter::default(); + /// + /// let result = MyFormat.with(|string_literal| { + /// formatted![&formatter, [string_literal, space_token(), token("+")]] + /// }); + /// + /// assert_eq!(formatted![&formatter, [token("MyToken"), space_token(), token("+")]], formatted![&formatter, [result]]) + fn with(&self, with: With) -> FormatItemWith + where + With: Fn(FormatElement) -> WithResult, + WithResult: IntoFormatElement; +} + +pub struct FormatItemWith<'a, With, WithResult> +where + With: Fn(FormatElement) -> WithResult, + WithResult: IntoFormatElement, +{ + with: With, + inner: &'a dyn Format, +} + +impl<'a, With, WithResult> Format for FormatItemWith<'a, With, WithResult> +where + With: Fn(FormatElement) -> WithResult, + WithResult: IntoFormatElement, +{ + fn format(&self, formatter: &Formatter) -> FormatResult { + let element = self.inner.format(formatter)?; + + (self.with)(element).into_format_element(formatter) + } +} + +impl FormatWith for F { + fn with(&self, with: With) -> FormatItemWith + where + With: Fn(FormatElement) -> WithResult, + WithResult: IntoFormatElement, + { + FormatItemWith { with, inner: self } + } +} + +impl FormatOptional for SyntaxResult> { + fn with_or( + &self, + with: With, + op: Or, + ) -> FormatWithOr + where + With: Fn(FormatElement) -> WithResult, + WithResult: IntoFormatElement, + Or: Fn() -> OrResult, + OrResult: IntoFormatElement, + { + match self { + Err(_) => FormatWithOr::With { inner: self, with }, + Ok(Some(value)) => FormatWithOr::With { inner: value, with }, + Ok(None) => FormatWithOr::Or(op), + } + } +} + +impl FormatOptional for Option { + fn with_or( + &self, + with: With, + op: Or, + ) -> FormatWithOr + where + With: Fn(FormatElement) -> WithResult, + WithResult: IntoFormatElement, + Or: Fn() -> OrResult, + OrResult: IntoFormatElement, + { + match self { + None => FormatWithOr::Or(op), + Some(value) => FormatWithOr::With { inner: value, with }, + } + } +} + +pub enum FormatWithOr<'a, With, Or, WithResult, OrResult> +where + With: Fn(FormatElement) -> WithResult, + Or: Fn() -> OrResult, + WithResult: IntoFormatElement, + OrResult: IntoFormatElement, +{ + With { inner: &'a dyn Format, with: With }, + Or(Or), +} + +impl<'a, With, Or, WithResult, OrResult> Format for FormatWithOr<'a, With, Or, WithResult, OrResult> +where + With: Fn(FormatElement) -> WithResult, + Or: Fn() -> OrResult, + WithResult: IntoFormatElement, + OrResult: IntoFormatElement, +{ + #[inline] + fn format(&self, formatter: &Formatter) -> FormatResult { + match self { + FormatWithOr::Or(op) => op().into_format_element(formatter), + FormatWithOr::With { inner, with } => { + with(inner.format(formatter)?).into_format_element(formatter) + } + } + } +} + +/// Utility trait that allows memorizing the output of a [Format]. +/// Useful to avoid re-formatting the same object twice. +pub trait MemoizeFormat { + /// Returns a formattable object that memoizes the result of `Format` by cloning. + /// Mainly useful if the same sub-tree can appear twice in the formatted output because it's + /// used inside of `if_group_breaks` or `if_group_fits_single_line`. + /// + /// ``` + /// use std::cell::Cell; + /// use rome_formatter::FormatOptions; + /// use rome_formatter::prelude::*; + /// use rome_rowan::TextSize; + /// + /// struct MyFormat { + /// value: Cell + /// } + /// + /// impl MyFormat { + /// pub fn new() -> Self { + /// Self { value: Cell::new(1) } + /// } + /// } + /// + /// impl Format for MyFormat {fn format(&self, formatter: &Formatter) -> FormatResult { + /// let value = self.value.get(); + /// self.value.set(value + 1); + /// + /// Ok(FormatElement::from(Token::new_dynamic(format!("Formatted {value} times."), TextSize::from(0)))) + /// } + /// } + /// + /// let formatter = Formatter::new(FormatOptions::default()); + /// let normal = MyFormat::new(); + /// + /// // Calls `format` for everytime the object gets formatted + /// assert_eq!( + /// Ok(format_elements![token("Formatted 1 times."), token("Formatted 2 times.")]), + /// formatted![&formatter, [&normal, &normal]] + /// ); + /// + /// // Memoized memoizes the result and calls `format` only once. + /// let memoized = normal.memoized(); + /// assert_eq!( + /// Ok(format_elements![token("Formatted 3 times."), token("Formatted 3 times.")]), + /// formatted![&formatter, [&memoized, &memoized]] + /// ); + /// ``` + /// + fn memoized(self) -> Memoized + where + Self: Sized + Format, + { + Memoized::new(self) + } +} + +impl MemoizeFormat for F where F: Format {} + +/// Memoizes the output of its inner [Format] to avoid re-formatting a potential expensive object. +pub struct Memoized { + inner: F, + memory: RefCell>>, +} + +impl Memoized { + fn new(inner: F) -> Self { + Self { + inner, + memory: RefCell::new(None), + } + } +} + +impl Format for Memoized +where + F: Format, +{ + fn format(&self, formatter: &Formatter) -> FormatResult { + if let Some(memory) = self.memory.borrow().as_ref() { + return memory.clone(); + } + + let formatted = self.inner.format(formatter); + *self.memory.borrow_mut() = Some(formatted.clone()); + + formatted + } +} diff --git a/crates/rome_formatter/src/formatter.rs b/crates/rome_formatter/src/formatter.rs new file mode 100644 index 000000000000..14e42f0e4472 --- /dev/null +++ b/crates/rome_formatter/src/formatter.rs @@ -0,0 +1,112 @@ +use crate::prelude::*; +#[cfg(debug_assertions)] +use crate::printed_tokens::PrintedTokens; +use crate::FormatOptions; +use rome_rowan::{Language, SyntaxNode, SyntaxToken}; +#[cfg(debug_assertions)] +use std::cell::RefCell; + +/// Handles the formatting of a CST and stores the options how the CST should be formatted (user preferences). +/// The formatter is passed to the [Format] implementation of every node in the CST so that they +/// can use it to format their children. +#[derive(Debug, Default)] +pub struct Formatter { + options: FormatOptions, + // This is using a RefCell as it only exists in debug mode, + // the Formatter is still completely immutable in release builds + #[cfg(debug_assertions)] + pub printed_tokens: RefCell, +} + +impl Formatter { + /// Creates a new context that uses the given formatter options + pub fn new(options: FormatOptions) -> Self { + Self { + options, + #[cfg(debug_assertions)] + printed_tokens: RefCell::default(), + } + } + + /// Returns the [FormatOptions] specifying how to format the current CST + pub fn options(&self) -> &FormatOptions { + &self.options + } + + /// Tracks the given token as formatted + #[inline] + pub fn track_token(&self, #[allow(unused_variables)] token: &SyntaxToken) { + cfg_if::cfg_if! { + if #[cfg(debug_assertions)] { + self.printed_tokens.borrow_mut().track_token(token); + } + } + } + + #[inline] + pub fn assert_formatted_all_tokens( + &self, + #[allow(unused_variables)] root: &SyntaxNode, + ) { + cfg_if::cfg_if! { + if #[cfg(debug_assertions)] { + let printed_tokens = self.printed_tokens.borrow(); + printed_tokens.assert_all_tracked(root); + } + } + } + + /// Formats all items of the iterator and returns the formatted result + /// + /// Returns the [Err] of the first item that failed to format. + #[inline] + pub fn format_all( + &self, + nodes: impl IntoIterator, + ) -> FormatResult> { + let mut result = Vec::new(); + + for node in nodes { + match node.format(self) { + Ok(formatted) => { + result.push(formatted); + } + Err(err) => return Err(err), + } + } + + Ok(result.into_iter()) + } +} + +impl Formatter { + /// Take a snapshot of the state of the formatter + #[inline] + pub fn snapshot(&self) -> FormatterSnapshot { + FormatterSnapshot { + #[cfg(debug_assertions)] + printed_tokens: self.printed_tokens.borrow().clone(), + } + } + + #[inline] + /// Restore the state of the formatter to a previous snapshot + pub fn restore(&self, #[allow(unused)] snapshot: FormatterSnapshot) { + cfg_if::cfg_if! { + if #[cfg(debug_assertions)] { + *self.printed_tokens.borrow_mut() = snapshot.printed_tokens; + } + } + } +} + +/// Snapshot of the formatter state used to handle backtracking if +/// errors are encountered in the formatting process and the formatter +/// has to fallback to printing raw tokens +/// +/// In practice this only saves the set of printed tokens in debug +/// mode and compiled to nothing in release mode +pub struct FormatterSnapshot { + #[cfg(debug_assertions)] + printed_tokens: PrintedTokens, +} diff --git a/crates/rome_formatter/src/intersperse.rs b/crates/rome_formatter/src/intersperse.rs index 2ad68d6a7f94..b327f5648aa6 100644 --- a/crates/rome_formatter/src/intersperse.rs +++ b/crates/rome_formatter/src/intersperse.rs @@ -2,7 +2,7 @@ use std::{fmt::Debug, iter::Peekable}; -use crate::FormatElement; +use crate::prelude::*; /// An iterator adapter that places a separator between all elements. #[derive(Debug, Clone)] diff --git a/crates/rome_formatter/src/lib.rs b/crates/rome_formatter/src/lib.rs index 22d7a384a7e4..568ff11313e6 100644 --- a/crates/rome_formatter/src/lib.rs +++ b/crates/rome_formatter/src/lib.rs @@ -1,12 +1,38 @@ +//! Infrastructure for code formatting +//! +//! This module defines [FormatElement], an IR to format code documents and provides a mean to print +//! such a document to a string. Objects that know how to format themselves implement the [Format] trait. +//! +//! ## Formatting Traits +//! +//! * [Format]: Implemented by objects that can be formatted. +//! * [IntoFormatElement]: The arguments passed to the `formatted[formatter, arg1, arg2]` must implement the. +//! [IntoFormatElement] trait. Its main difference to the [Format] trait is that it consumes self rather than borrowing it. +//! This module provides [IntoFormatElement] implementations for every object implementing [Format] and [FormatElement]. +//! * [FormatRule]: Rule that knows how to format an object of another type. Necessary in the situation where +//! it's necessary to implement [Format] on an object from another crate. This module defines the +//! [FormatRefWithRule] and [FormatOwnedWithRule] structs to pass an item with its corresponding rule. +//! * [FormatWithRule] implemented by objects that know how to format another type. Useful for implementing +//! some reusable formatting logic inside of this module if the type itself doesn't implement [Format] +//! +//! ## Formatting Macros +//! +//! This trait defines two macros to construct the IR. +//! * [format_elements]: Allows concatenating multiple [FormatElement]s +//! * [formatted]: Concatenates a sequence of [FormatElement]s and/or objects implementing [Format]. + mod builders; pub mod format_element; -pub mod format_elements; +mod format_extensions; +pub mod formatter; pub mod intersperse; +pub mod macros; pub mod prelude; #[cfg(debug_assertions)] pub mod printed_tokens; pub mod printer; +use crate::formatter::Formatter; use crate::printer::Printer; pub use builders::ConcatBuilder; pub use format_element::{ @@ -17,9 +43,12 @@ pub use format_element::{ soft_block_indent, soft_line_break, soft_line_break_or_space, soft_line_indent_or_space, space_token, token, FormatElement, Token, Verbatim, LINE_TERMINATORS, }; -use rome_rowan::{SyntaxError, TextRange, TextSize}; +use rome_rowan::{ + Language, SyntaxError, SyntaxNode, SyntaxResult, TextRange, TextSize, TokenAtOffset, +}; use std::error::Error; -use std::fmt::{self, Display, Formatter}; +use std::fmt; +use std::marker::PhantomData; use std::num::ParseIntError; use std::str::FromStr; @@ -54,7 +83,7 @@ impl FromStr for IndentStyle { } } -impl Display for IndentStyle { +impl fmt::Display for IndentStyle { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { IndentStyle::Tab => write!(f, "Tab"), @@ -94,8 +123,8 @@ pub enum ParseLineWidthError { TryFromIntError(LineWidthFromIntError), } -impl Display for ParseLineWidthError { - fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { +impl fmt::Display for ParseLineWidthError { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{self:?}") } } @@ -157,7 +186,7 @@ impl FromStr for QuoteStyle { } } -impl Display for QuoteStyle { +impl fmt::Display for QuoteStyle { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { QuoteStyle::Double => write!(f, "Double Quotes"), @@ -195,7 +224,7 @@ impl FormatOptions { } } -impl Display for FormatOptions { +impl fmt::Display for FormatOptions { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "Indent style: {}", self.indent_style)?; writeln!(f, "Line width: {}", self.line_width.value())?; @@ -327,7 +356,7 @@ pub enum FormatError { CapabilityDisabled, } -impl Display for FormatError { +impl fmt::Display for FormatError { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { match self { FormatError::MissingRequiredChild => fmt.write_str("missing required child"), @@ -352,3 +381,491 @@ impl From<&SyntaxError> for FormatError { } } } + +/// Formatting trait for types that can create a formatted representation. The `rome_formatter` equivalent +/// to [std::fmt::Display]. +/// +/// ## Example +/// Implementing `Format` for a custom struct +/// +/// ``` +/// use rome_formatter::{format, FormatOptions}; +/// use rome_formatter::prelude::*; +/// use rome_rowan::TextSize; +/// +/// struct Paragraph(String); +/// +/// impl Format for Paragraph {fn format(&self, formatter: &Formatter) -> FormatResult { +/// formatted![ +/// formatter, +/// [ +/// hard_line_break(), +/// FormatElement::from(Token::new_dynamic(self.0.clone(), TextSize::from(0))), +/// hard_line_break(), +/// ] +/// ] +/// } +/// } +/// +/// let paragraph = Paragraph(String::from("test")); +/// let printed = format(FormatOptions::default(), ¶graph).unwrap().print(); +/// +/// assert_eq!("test\n", printed.as_code()) +/// ``` +pub trait Format { + fn format(&self, formatter: &Formatter) -> FormatResult; +} + +impl Format for &T +where + T: ?Sized + Format, +{ + fn format(&self, formatter: &Formatter) -> FormatResult { + Format::format(&**self, formatter) + } +} + +impl Format for &mut T +where + T: ?Sized + Format, +{ + fn format(&self, formatter: &Formatter) -> FormatResult { + Format::format(&**self, formatter) + } +} + +impl Format for Option +where + T: Format, +{ + fn format(&self, formatter: &Formatter) -> FormatResult { + match self { + Some(value) => value.format(formatter), + None => Ok(empty_element()), + } + } +} + +impl Format for SyntaxResult +where + T: Format, +{ + fn format(&self, formatter: &Formatter) -> FormatResult { + match self { + Ok(value) => value.format(formatter), + Err(err) => Err(err.into()), + } + } +} + +/// Implemented by traits that can be converted to a `FormatElement`. +/// +/// This is similar to [Format] but with the difference that it consumes `self`, allowing it to also +/// be implemented on [FormatElement].format_elements.rs +pub trait IntoFormatElement { + fn into_format_element(self, formatter: &Formatter) -> FormatResult; +} + +impl IntoFormatElement for FormatElement { + #[inline] + fn into_format_element(self, _: &Formatter) -> FormatResult { + Ok(self) + } +} + +impl IntoFormatElement for FormatResult { + #[inline] + fn into_format_element(self, _: &Formatter) -> FormatResult { + self + } +} + +impl IntoFormatElement for T +where + T: Format, +{ + #[inline] + fn into_format_element(self, formatter: &Formatter) -> FormatResult { + self.format(formatter) + } +} + +/// Rule that knows how to format an object of type [T]. +/// +/// Implementing [Format] on the object itself is preferred over implementing [FormatRule] but +/// this isn't possible inside of a dependent crate for external type. +/// +/// For example, the `rome_js_formatter` crate isn't able to implement [Format] on `JsIfStatement` +/// because both the [Format] trait and `JsIfStatement` are external types (Rust's orphan rule). +/// +/// That's why the `rome_js_formatter` crate must define a new-type that implements the formatting +/// of `JsIfStatement`. +pub trait FormatRule { + fn format(item: &T, formatter: &Formatter) -> FormatResult; +} + +/// Trait for an object that formats an object with a specified rule. +/// +/// Gives access to the underlying item. +/// +/// Useful in situation where a type itself doesn't implement [Format] (e.g. because of Rust's orphan rule) +/// but you want to implement some common formatting logic. +/// +/// ## Examples +/// +/// This can be useful if you want to format a `SyntaxNode` inside rome_formatter.. `SyntaxNode` doesn't implement [Format] +/// itself but the language agnostic crate implements `AsFormat` and `IntoFormat` for it and the returned [Format] +/// implement [FormatWithRule]. +/// +/// ``` +/// use rome_formatter::prelude::*; +/// use rome_formatter::{FormatOptions, FormatWithRule}; +/// use rome_rowan::{Language, SyntaxNode}; +/// fn format_node>>(node: F) -> FormatResult { +/// let formatter = Formatter::new(FormatOptions::default()); +/// +/// let formatted = node.format(&formatter); +/// let _syntax = node.item(); +/// +/// // Do something with syntax +/// formatted +/// } +/// ``` +pub trait FormatWithRule: Format { + type Item; + + /// Returns the associated item + fn item(&self) -> &Self::Item; +} + +/// Formats the referenced `item` with the specified rule. +pub struct FormatRefWithRule<'a, T, R> +where + R: FormatRule, +{ + item: &'a T, + rule: PhantomData, +} + +impl<'a, T, R> FormatRefWithRule<'a, T, R> +where + R: FormatRule, +{ + pub fn new(item: &'a T) -> Self { + Self { + item, + rule: PhantomData, + } + } +} + +impl FormatWithRule for FormatRefWithRule<'_, T, R> +where + R: FormatRule, +{ + type Item = T; + + fn item(&self) -> &Self::Item { + self.item + } +} + +impl Format for FormatRefWithRule<'_, T, R> +where + R: FormatRule, +{ + #[inline] + fn format(&self, formatter: &Formatter) -> FormatResult { + R::format(self.item, formatter) + } +} + +/// Formats the `item` with the specified rule. +pub struct FormatOwnedWithRule +where + R: FormatRule, +{ + item: T, + rule: PhantomData, +} + +impl FormatOwnedWithRule +where + R: FormatRule, +{ + pub fn new(item: T) -> Self { + Self { + item, + rule: PhantomData, + } + } + + pub fn with_item(mut self, item: T) -> Self { + self.item = item; + self + } + + pub fn into_item(self) -> T { + self.item + } +} + +impl Format for FormatOwnedWithRule +where + R: FormatRule, +{ + #[inline] + fn format(&self, formatter: &Formatter) -> FormatResult { + R::format(&self.item, formatter) + } +} + +impl FormatWithRule for FormatOwnedWithRule +where + R: FormatRule, +{ + type Item = T; + + fn item(&self) -> &Self::Item { + &self.item + } +} + +/// Formats any value that implements [Format]. +/// +/// Please note that [format_node] is preferred to format a [JsSyntaxNode] +pub fn format(options: FormatOptions, root: &dyn Format) -> FormatResult { + tracing::trace_span!("format").in_scope(move || { + let formatter = Formatter::new(options); + let element = root.format(&formatter)?; + Ok(Formatted::new(element, options)) + }) +} + +/// Formats a syntax node file based on its features. +/// +/// It returns a [Formatted] result, which the user can use to override a file. +pub fn format_node>>( + options: FormatOptions, + root: &N, +) -> FormatResult { + tracing::trace_span!("format_node").in_scope(move || { + let formatter = Formatter::new(options); + let element = formatted![&formatter, [root]]?; + + formatter.assert_formatted_all_tokens(root.item()); + + Ok(Formatted::new(element, options)) + }) +} + +/// Formats a range within a file, supported by Rome +/// +/// This runs a simple heuristic to determine the initial indentation +/// level of the node based on the provided [FormatOptions], which +/// must match currently the current initial of the file. Additionally, +/// because the reformatting happens only locally the resulting code +/// will be indented with the same level as the original selection, +/// even if it's a mismatch from the rest of the block the selection is in +/// +/// It returns a [Formatted] result with a range corresponding to the +/// range of the input that was effectively overwritten by the formatter +pub fn format_range>>( + options: FormatOptions, + root: &SyntaxNode, + range: TextRange, +) -> FormatResult { + // Find the tokens corresponding to the start and end of the range + let start_token = root.token_at_offset(range.start()); + let end_token = root.token_at_offset(range.end()); + + // If these tokens were not found this means either: + // 1. The input [SyntaxNode] was empty + // 2. The input node was not the root [SyntaxNode] of the file + // In the first case we can return an empty result immediately, + // otherwise default to the first and last tokens in the root node + let start_token = match start_token { + // If the start of the range lies between two tokens, + // start at the rightmost one + TokenAtOffset::Between(_, token) => token, + TokenAtOffset::Single(token) => token, + TokenAtOffset::None => match root.first_token() { + Some(token) => token, + // root node is empty + None => return Ok(Printed::new_empty()), + }, + }; + let end_token = match end_token { + // If the end of the range lies between two tokens, + // end at the leftmost one + TokenAtOffset::Between(token, _) => token, + TokenAtOffset::Single(token) => token, + TokenAtOffset::None => match root.last_token() { + Some(token) => token, + // root node is empty + None => return Ok(Printed::new_empty()), + }, + }; + + // Find the lowest common ancestor node for the start and end token + // by building the path to the root node from both tokens and + // iterating along the two paths at once to find the first divergence + #[allow(clippy::needless_collect)] + let start_to_root: Vec<_> = start_token.ancestors().collect(); + #[allow(clippy::needless_collect)] + let end_to_root: Vec<_> = end_token.ancestors().collect(); + + let common_root = start_to_root + .into_iter() + .rev() + .zip(end_to_root.into_iter().rev()) + .map_while(|(lhs, rhs)| if lhs == rhs { Some(lhs) } else { None }) + .last(); + + // Logically this should always return at least the root node, + // fallback to said node just in case + let common_root = common_root.as_ref().unwrap_or(root); + + // Perform the actual formatting of the root node with + // an appropriate indentation level + let formatted = format_sub_tree(options, &FormatRefWithRule::<_, R>::new(common_root))?; + + // This finds the closest marker to the beginning of the source + // starting before or at said starting point, and the closest + // marker to the end of the source range starting after or at + // said ending point respectively + let mut range_start = None; + let mut range_end = None; + + let sourcemap = Vec::from(formatted.sourcemap()); + for marker in &sourcemap { + if let Some(start_dist) = marker.source.checked_sub(range.start()) { + range_start = match range_start { + Some((prev_marker, prev_dist)) => { + if start_dist < prev_dist { + Some((marker, start_dist)) + } else { + Some((prev_marker, prev_dist)) + } + } + None => Some((marker, start_dist)), + } + } + + if let Some(end_dist) = range.end().checked_sub(marker.source) { + range_end = match range_end { + Some((prev_marker, prev_dist)) => { + if end_dist < prev_dist { + Some((marker, end_dist)) + } else { + Some((prev_marker, prev_dist)) + } + } + None => Some((marker, end_dist)), + } + } + } + + // If no start or end were found, this means that the edge of the formatting + // range was near the edge of the input, and no marker were emitted before + // the start (or after the end) of the formatting range: in this case + // the start/end marker default to the start/end of the input + let (start_source, start_dest) = match range_start { + Some((start_marker, _)) => (start_marker.source, start_marker.dest), + None => (common_root.text_range().start(), TextSize::from(0)), + }; + let (end_source, end_dest) = match range_end { + Some((end_marker, _)) => (end_marker.source, end_marker.dest), + None => ( + common_root.text_range().end(), + TextSize::try_from(formatted.as_code().len()).expect("code length out of bounds"), + ), + }; + + let input_range = TextRange::new(start_source, end_source); + let output_range = TextRange::new(start_dest, end_dest); + let sourcemap = Vec::from(formatted.sourcemap()); + let verbatim_ranges = Vec::from(formatted.verbatim_ranges()); + let code = &formatted.into_code()[output_range]; + Ok(Printed::new( + code.into(), + Some(input_range), + sourcemap, + verbatim_ranges, + )) +} + +/// Formats a single node within a file, supported by Rome. +/// +/// This runs a simple heuristic to determine the initial indentation +/// level of the node based on the provided [FormatOptions], which +/// must match currently the current initial of the file. Additionally, +/// because the reformatting happens only locally the resulting code +/// will be indented with the same level as the original selection, +/// even if it's a mismatch from the rest of the block the selection is in +/// +/// It returns a [Formatted] result +pub fn format_sub_tree>>( + options: FormatOptions, + root: &N, +) -> FormatResult { + let syntax = root.item(); + // Determine the initial indentation level for the printer by inspecting the trivia pieces + // of each token from the first token of the common root towards the start of the file + let mut tokens = std::iter::successors(syntax.first_token(), |token| token.prev_token()); + + // From the iterator of tokens, build an iterator of trivia pieces (once again the iterator is + // reversed, starting from the last trailing trivia towards the first leading trivia). + // The first token is handled specially as we only wan to consider its leading trivia pieces + let first_token = tokens.next(); + let first_token_trivias = first_token + .into_iter() + .flat_map(|token| token.leading_trivia().pieces().rev()); + + let next_tokens_trivias = tokens.flat_map(|token| { + token + .trailing_trivia() + .pieces() + .rev() + .chain(token.leading_trivia().pieces().rev()) + }); + + let trivias = first_token_trivias + .chain(next_tokens_trivias) + .filter(|piece| { + // We're only interested in newline and whitespace trivias, skip over comments + let is_newline = piece.is_newline(); + let is_whitespace = piece.is_whitespace(); + is_newline || is_whitespace + }); + + // Finally run the iterator until a newline trivia is found, and get the last whitespace trivia before it + let last_whitespace = trivias.map_while(|piece| piece.as_whitespace()).last(); + let initial_indent = match last_whitespace { + Some(trivia) => { + // This logic is based on the formatting options passed in + // the be user (or the editor) as we do not have any kind + // of indentation type detection yet. Unfortunately this + // may not actually match the current content of the file + let length = trivia.text().len() as u16; + match options.indent_style { + IndentStyle::Tab => length, + IndentStyle::Space(width) => length / u16::from(width), + } + } + // No whitespace was found between the start of the range + // and the start of the file + None => 0, + }; + + let formatted = format_node(options, root)?; + let printed = formatted.print_with_indent(initial_indent); + let sourcemap = Vec::from(printed.sourcemap()); + let verbatim_ranges = Vec::from(printed.verbatim_ranges()); + Ok(Printed::new( + printed.into_code(), + Some(syntax.text_range()), + sourcemap, + verbatim_ranges, + )) +} diff --git a/crates/rome_js_formatter/src/macros.rs b/crates/rome_formatter/src/macros.rs similarity index 51% rename from crates/rome_js_formatter/src/macros.rs rename to crates/rome_formatter/src/macros.rs index c6437d9e8f2b..b97082b40146 100644 --- a/crates/rome_js_formatter/src/macros.rs +++ b/crates/rome_formatter/src/macros.rs @@ -1,7 +1,77 @@ -use crate::{Formatter, IntoFormatElement}; -use rome_formatter::{ConcatBuilder, FormatElement, FormatError, FormatResult}; +use crate::prelude::*; +use crate::{ConcatBuilder, IntoFormatElement}; -/// The macro `format` is a convenience macro to chain a list of [FormatElement] or objects +/// The macro `format_elements` is a convenience macro to +/// use when writing a list of tokens that should be at the same level +/// without particular rule. +/// +/// # Examples +/// +/// Let's suppose you need to create tokens for the string `"foo": "bar"`, +/// you would write: +/// +/// ```rust +/// use rome_formatter::prelude::*; +/// +/// let element = format_elements![token("foo:"), space_token(), token("bar")]; +/// ``` +/// +/// The macro can be also nested, although the macro needs to be decorated with the token you need. +/// For example, let's try to format following string: +/// +/// ```no_rust +/// foo: { bar: lorem } +/// ``` +/// You would write it like the following: +/// +/// ```rust +/// use rome_formatter::{FormatOptions, Formatted}; +/// use rome_formatter::prelude::*; +/// +/// let element = format_elements![ +/// token("foo:"), +/// space_token(), +/// token("{"), +/// space_token(), +/// token("bar:"), +/// space_token(), +/// token("lorem"), +/// space_token(), +/// token("}") +/// ]; +/// assert_eq!(r#"foo: { bar: lorem }"#, Formatted::new(element, FormatOptions::default()).print().as_code()); +/// ``` +/// Or you can also create single element: +/// ``` +/// use rome_formatter::{Formatted, FormatOptions}; +/// use rome_formatter::prelude::*; +/// +/// use rome_formatter::prelude::*; +/// let element = format_elements![token("single")]; +/// assert_eq!(r#"single"#, Formatted::new(element, FormatOptions::default()).print().as_code()); +/// ``` +#[macro_export] +macro_rules! format_elements { + + // called for things like format_tokens!["hey"] + ($element:expr) => { + { + use $crate::FormatElement; + FormatElement::from($element) + } + }; + + ( $( $element:expr ),+ $(,)?) => {{ + use $crate::{FormatElement, concat_elements}; + concat_elements([ + $( + FormatElement::from($element) + ),+ + ]) + }}; +} + +/// The macro `formatted` is a convenience macro to chain a list of [FormatElement] or objects /// that implement [IntoFormatElement] (which is implemented by all object implementing [Format]). /// /// # Examples @@ -10,8 +80,8 @@ use rome_formatter::{ConcatBuilder, FormatElement, FormatError, FormatResult}; /// you would write: /// /// ```rust -/// use rome_formatter::{concat_elements, format_elements, FormatElement, FormatOptions, FormatResult, space_token, token}; -/// use rome_js_formatter::{Format, formatted, Formatter}; +/// use rome_formatter::FormatOptions; +/// use rome_formatter::prelude::*; /// /// struct TestFormat; /// @@ -24,49 +94,51 @@ use rome_formatter::{ConcatBuilder, FormatElement, FormatError, FormatResult}; /// let formatter = Formatter::new(FormatOptions::default()); /// /// let formatted = formatted![ -/// &formatter, +/// &formatter, +/// [ /// token("a"), /// space_token(), /// token("simple"), /// space_token(), /// TestFormat /// ] -/// .unwrap(); -/// -/// assert_eq!( -/// formatted, -/// concat_elements([ -/// token("a"), -/// space_token(), -/// token("simple"), -/// space_token(), -/// token("test") -/// ]) +/// ] +/// .unwrap(); +/// +/// assert_eq!( +/// formatted, +/// concat_elements([ +/// token("a"), +/// space_token(), +/// token("simple"), +/// space_token(), +/// token("test") +/// ]) /// ); /// ``` /// /// Or you can also create single element: /// ``` -/// use rome_formatter::{FormatOptions, token}; -/// use rome_js_formatter::{formatted, Formatter}; +/// use rome_formatter::prelude::*; +/// use rome_formatter::FormatOptions; /// /// let formatter = Formatter::new(FormatOptions::default()); /// -/// let formatted = formatted![&formatter, token("test")].unwrap(); +/// let formatted = formatted![&formatter, [token("test")]].unwrap(); /// /// assert_eq!(formatted, token("test")); /// ``` #[macro_export] macro_rules! formatted { - // called for things like formatted![formatter, token("test")] - ($formatter:expr, $element:expr) => { + // called for things like formatted![formatter, [token("test")]] + ($formatter:expr, [$element:expr]) => { { $crate::IntoFormatElement::into_format_element($element, $formatter) } }; - ($formatter:expr, $($element:expr),+ $(,)?) => {{ + ($formatter:expr, [$($element:expr),+ $(,)?]) => {{ use $crate::macros::FormatBuilder; const SIZE: usize = $crate::__count_elements!($($element),*); @@ -127,10 +199,8 @@ impl FormatBuilder { #[cfg(test)] mod tests { - use crate::{Format, Formatter}; - use rome_formatter::{ - concat_elements, space_token, token, FormatElement, FormatOptions, FormatResult, - }; + use crate::prelude::*; + use crate::FormatOptions; struct TestFormat; @@ -144,7 +214,7 @@ mod tests { fn test_single_element() { let formatter = Formatter::new(FormatOptions::default()); - let formatted = formatted![&formatter, TestFormat].unwrap(); + let formatted = formatted![&formatter, [TestFormat]].unwrap(); assert_eq!(formatted, token("test")); } @@ -155,11 +225,13 @@ mod tests { let formatted = formatted![ &formatter, - token("a"), - space_token(), - token("simple"), - space_token(), - TestFormat + [ + token("a"), + space_token(), + token("simple"), + space_token(), + TestFormat + ] ] .unwrap(); diff --git a/crates/rome_formatter/src/prelude.rs b/crates/rome_formatter/src/prelude.rs index 568711cfaf38..d392f192274f 100644 --- a/crates/rome_formatter/src/prelude.rs +++ b/crates/rome_formatter/src/prelude.rs @@ -1,3 +1,8 @@ pub use crate::format_element::*; -pub use crate::format_elements; -pub use crate::FormatResult; +pub use crate::format_extensions::{FormatOptional as _, FormatWith as _, MemoizeFormat}; +pub use crate::formatter::Formatter; + +pub use crate::{ + format_elements, formatted, Format, Format as _, FormatError, FormatResult, FormatRule, + FormatWithRule as _, IntoFormatElement as _, +}; diff --git a/crates/rome_js_formatter/Cargo.toml b/crates/rome_js_formatter/Cargo.toml index 3aba15ae9c9e..44229b0e3f5b 100644 --- a/crates/rome_js_formatter/Cargo.toml +++ b/crates/rome_js_formatter/Cargo.toml @@ -9,7 +9,6 @@ edition = "2021" rome_js_syntax = { path = "../rome_js_syntax" } rome_formatter = { path = "../rome_formatter" } rome_rowan = { path = "../rome_rowan" } -cfg-if = "1.0.0" tracing = { version = "0.1.31", default-features = false, features = ["std"] } [dev-dependencies] diff --git a/crates/rome_js_formatter/README.md b/crates/rome_js_formatter/README.md index 92321be58a8c..869b40502443 100644 --- a/crates/rome_js_formatter/README.md +++ b/crates/rome_js_formatter/README.md @@ -39,7 +39,7 @@ impl FormatNode for Buzz { ```rust fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let l_paren_yes = &self.l_paren_token()?.format(formatter)?; // yes + let l_paren_yes = &self.l_paren_token()?.format(); // yes let l_paren_no = toke("("); // no } ``` diff --git a/crates/rome_js_formatter/docs/implement_the_formatter.md b/crates/rome_js_formatter/docs/implement_the_formatter.md index 582b6e292c6b..4d0f42476864 100644 --- a/crates/rome_js_formatter/docs/implement_the_formatter.md +++ b/crates/rome_js_formatter/docs/implement_the_formatter.md @@ -31,31 +31,31 @@ This will automatically build and open a browser tab to the documentation. 1. Use the `*Fields` struct to extract all the tokens/nodes ```rust - impl FormatNode for JsExportDefaultExpressionClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { + impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsExportDefaultExpressionClause, formatter: &Formatter) -> FormatResult { let JsExportDefaultExpressionClauseFields { default_token, expression, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); } } ``` 2. When using `.as_fields()` with the destructuring, don't use the `..` feature. Prefer extracting all fields and ignore them using the `_` ```rust - impl FormatNode for JsExportDefaultExpressionClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { + impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsExportDefaultExpressionClause, formatter: &Formatter) -> FormatResult { let JsExportDefaultExpressionClauseFields { default_token, expression: _, semicolon_token - } = self.as_fields(); + } = node.as_fields(); } } ``` The reason why we want to promote this pattern is because we want to make explicit when a token/node is excluded; -3. Use the APIs provided by `format_element.rs` and `formatter` and `format_traits.rs`. +3. Use the APIs provided by `format_element.rs` and `formatter` and `format_extensions.rs`. 1. `formatter_element.rs` exposes a series of utilities to craft the formatter IR; please refer to their internal documentation to understand what the utilities are for; 2. `formatter` exposes a set of functions to help to format some recurring patterns; please refer to their internal @@ -63,21 +63,21 @@ This will automatically build and open a browser tab to the documentation. 3. `format_traits.rs`: with these traits, we give the ability to nodes and tokens to implements certain methods that are exposed based on its type. If you have a good IDE support, this feature will help you. For example: ```rust - impl FormatNode for JsExportDefaultExpressionClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { + impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsExportDefaultExpressionClause, formatter: &Formatter) -> FormatResult { let JsExportDefaultExpressionClauseFields { default_token, expression, // it's a mandatory node semicolon_token, // this is not a mandatory node - } = self.as_fields(); - let element = expression.format(formatter)?; - let element = expression.format_with(formatter, |element| { - format_element![element , space_token()] + } = node.as_fields(); + let element = expression.format(); + let element = expression.format().with(|element| { + formatted![formatter, element , space_token()] })?; - let semicolon = semicolon_token.format_or(formatter, || space_token())?; - let semicolon = semicolon_token.format_or_empty(formatter)?; - let semicolon = semicolon_token.format_with_or_empty(formatter, |semicolon_element| { - format_element![semicolon_element, space_token()] + let semicolon = semicolon_token.format().format_or(|| space_token())?; + let semicolon = semicolon_token.format(); + let semicolon = semicolon_token.format().with_or_empty(formatter, |semicolon_element| { + formatted![formatter, semicolon_element, space_token()] })?; } } diff --git a/crates/rome_js_formatter/src/check_reformat.rs b/crates/rome_js_formatter/src/check_reformat.rs index 66bc28cc0c0d..65c2b56fee87 100644 --- a/crates/rome_js_formatter/src/check_reformat.rs +++ b/crates/rome_js_formatter/src/check_reformat.rs @@ -1,5 +1,6 @@ -use crate::{format_node, FormatOptions}; +use crate::format_node; use rome_diagnostics::{file::SimpleFiles, termcolor, Emitter}; +use rome_formatter::FormatOptions; use rome_js_parser::{parse, SourceType}; use rome_js_syntax::JsSyntaxNode; diff --git a/crates/rome_js_formatter/src/cst.rs b/crates/rome_js_formatter/src/cst.rs index 2c3e464c7286..00410a3825a7 100644 --- a/crates/rome_js_formatter/src/cst.rs +++ b/crates/rome_js_formatter/src/cst.rs @@ -1,9 +1,29 @@ -use crate::{Format, FormatElement, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; +use rome_formatter::{FormatOwnedWithRule, FormatRefWithRule}; + +use crate::{AsFormat, IntoFormat}; use rome_js_syntax::{map_syntax_node, JsSyntaxNode}; -impl Format for JsSyntaxNode { - fn format(&self, formatter: &Formatter) -> FormatResult { - map_syntax_node!(self.clone(), node => node.format(formatter)) +pub struct FormatJsSyntaxNode; + +impl rome_formatter::FormatRule for FormatJsSyntaxNode { + fn format(node: &JsSyntaxNode, formatter: &Formatter) -> FormatResult { + map_syntax_node!(node.clone(), node => formatted![formatter, [node.format()]]) + } +} + +impl<'a> AsFormat<'a> for JsSyntaxNode { + type Format = FormatRefWithRule<'a, JsSyntaxNode, FormatJsSyntaxNode>; + + fn format(&'a self) -> Self::Format { + FormatRefWithRule::new(self) + } +} + +impl IntoFormat for JsSyntaxNode { + type Format = FormatOwnedWithRule; + + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new(self) } } diff --git a/crates/rome_js_formatter/src/format_extensions.rs b/crates/rome_js_formatter/src/format_extensions.rs deleted file mode 100644 index 0f1ec01b1d27..000000000000 --- a/crates/rome_js_formatter/src/format_extensions.rs +++ /dev/null @@ -1,286 +0,0 @@ -use crate::Format; -use crate::{empty_element, FormatElement, Formatter}; -use rome_formatter::FormatResult; - -use rome_rowan::SyntaxResult; - -/// Utility trait used to simplify the formatting of optional objects that are formattable. -/// -/// In order to take advantage of all the functions, you only need to implement the [FormatOptionalTokenAndNode::with_or] -/// function. -pub trait FormatOptional { - /// This function tries to format an optional object. If the object is [None] - /// an [empty token](crate::FormatElement::Empty) is created. If exists, the utility - /// formats the object and passes it to the closure. - /// - /// ## Examples - /// - /// ``` - /// use rome_js_factory::JsSyntaxTreeBuilder; - /// use rome_js_formatter::{Formatter, empty_element, space_token, format_elements, token, formatted}; - /// use rome_js_syntax::{JsSyntaxToken}; - /// use rome_js_formatter::prelude::*; - /// use rome_js_syntax::JsSyntaxKind; - /// - /// let formatter = Formatter::default(); - /// let empty_token: Option = None; - /// - /// let mut builder = JsSyntaxTreeBuilder::new(); - /// - /// builder.start_node(JsSyntaxKind::JS_STRING_LITERAL_EXPRESSION); - /// builder.token(JsSyntaxKind::JS_STRING_LITERAL, "'abc'"); - /// builder.finish_node(); - /// let node = builder.finish(); - /// let syntax_token = node.first_token(); - /// - /// // we wrap the token in [Ok] so we can simulate SyntaxResult. - /// let empty_result = empty_token.with_or_empty(|token| token); - /// let with_result = syntax_token.with_or_empty(|token| { - /// formatted![&formatter, space_token(), token] - /// }); - /// - /// assert_eq!(Ok(empty_element()), formatted![&formatter, empty_result]); - /// assert_eq!(formatted![&formatter, space_token(), token("'abc'")], formatted![&formatter, with_result]); - fn with_or_empty( - &self, - with: With, - ) -> FormatWithOr FormatElement, WithResult, FormatElement> - where - With: Fn(FormatElement) -> WithResult, - WithResult: IntoFormatResult, - { - self.with_or(with, empty_element) - } - - /// This function tries to format an optional formattable object as is. If the object is [None], - /// it calls the passed closure, which has to return a [crate::FormatElement] - /// - /// ## Examples - /// - /// ``` - /// use rome_js_formatter::{formatted, Formatter, token}; - /// use rome_js_syntax::{JsSyntaxToken}; - /// use rome_js_formatter::prelude::*; - /// - /// let formatter = Formatter::default(); - /// let empty_token: Option = None; - /// - /// let result = empty_token.or_format(|| token(" other result")); - /// - /// assert_eq!(Ok(token(" other result")), formatted![&formatter, result]); - fn or_format( - &self, - op: Or, - ) -> FormatWithOr FormatElement, Or, FormatElement, OrResult> - where - Or: Fn() -> OrResult, - OrResult: IntoFormatResult, - Self: Sized, - { - self.with_or(|token| token, op) - } - - /// If the object isn't [None], it will call the first closure which will accept formatted element. - /// - /// If the object is [None], the second closure will be called. - /// - /// Both closures have to return a [crate::FormatElement]. This function will make sure to wrap them into [Ok]. - /// - /// ## Examples - /// - /// ``` - /// use rome_js_factory::JsSyntaxTreeBuilder; - /// use rome_js_formatter::{Formatter, empty_element, space_token, format_elements, token, formatted}; - /// use rome_js_syntax::{JsSyntaxToken}; - /// use rome_js_formatter::prelude::*; - /// use rome_js_syntax::JsSyntaxKind; - /// - /// let formatter = Formatter::default(); - /// let empty_token: Option = None; - /// - /// let mut builder = JsSyntaxTreeBuilder::new(); - /// - /// builder.start_node(JsSyntaxKind::JS_STRING_LITERAL_EXPRESSION); - /// builder.token(JsSyntaxKind::JS_STRING_LITERAL, "'abc'"); - /// builder.finish_node(); - /// let node = builder.finish(); - /// let syntax_token = node.first_token(); - /// - /// // we wrap the token in [Ok] so we can simulate SyntaxResult. - /// let empty_result = empty_token.with_or(|token| token, || { - /// token("empty") - /// }); - /// let with_result = syntax_token.with_or(|token| { - /// formatted![&formatter, space_token(), token] - /// }, || empty_element()); - /// - /// assert_eq!(Ok(token("empty")), formatted![&formatter, empty_result]); - /// assert_eq!(formatted![&formatter, space_token(), token("'abc'")], formatted![&formatter, with_result]); - fn with_or( - &self, - with: With, - op: Or, - ) -> FormatWithOr - where - With: Fn(FormatElement) -> WithResult, - WithResult: IntoFormatResult, - Or: Fn() -> OrResult, - OrResult: IntoFormatResult; -} - -/// Utility trait for formatting a formattable object with some additional content. -pub trait FormatWith { - /// Allows to chain a formattable object with another [elements](FormatElement) - /// - /// The function will decorate the result with [Ok] - /// - /// The formatted element is passed to the closure, which then can appended to additional elements. - /// This method is useful in case, for example, a token has to be chained with a space. - /// - /// ## Examples - /// - /// ``` - /// use rome_js_factory::JsSyntaxTreeBuilder; - /// use rome_js_formatter::{Formatter, token, format_elements, space_token, formatted}; - /// use rome_js_syntax::{JsSyntaxNode, JsSyntaxKind}; - /// use rome_js_formatter::prelude::*; - /// - /// let mut builder = JsSyntaxTreeBuilder::new(); - /// builder.start_node(JsSyntaxKind::JS_STRING_LITERAL_EXPRESSION); - /// builder.token(JsSyntaxKind::JS_STRING_LITERAL, "'abc'"); - /// builder.finish_node(); - /// let node = builder.finish(); - /// let syntax_token = node.first_token().unwrap(); - /// let formatter = Formatter::default(); - /// - /// // Wrap the token in [Ok] so we can simulate SyntaxResult. - /// let result = Ok(syntax_token); - /// let result = result.with(|string_literal| { - /// formatted![&formatter, string_literal, space_token(), token("+")] - /// }); - /// - /// assert_eq!(formatted![&formatter, token("'abc'"), space_token(), token("+")], formatted![&formatter, result]) - fn with(&self, with: With) -> FormatItemWith - where - With: Fn(FormatElement) -> WithResult, - WithResult: IntoFormatResult; -} - -pub struct FormatItemWith<'a, With, WithResult> -where - With: Fn(FormatElement) -> WithResult, - WithResult: IntoFormatResult, -{ - with: With, - inner: &'a dyn Format, -} - -impl<'a, With, WithResult> Format for FormatItemWith<'a, With, WithResult> -where - With: Fn(FormatElement) -> WithResult, - WithResult: IntoFormatResult, -{ - fn format(&self, formatter: &Formatter) -> FormatResult { - let element = self.inner.format(formatter)?; - - (self.with)(element).into_format_result() - } -} - -/// Utility trait to convert [crate::FormatElement] to [FormatResult] -pub trait IntoFormatResult { - /// Consumes a [crate::FormatElement] to return a [FormatResult::FormatElement] - /// - /// This function in important when working with closures and the rest of the traits - /// that belong to this module. - fn into_format_result(self) -> FormatResult; -} - -impl IntoFormatResult for FormatElement { - fn into_format_result(self) -> FormatResult { - Ok(self) - } -} - -impl IntoFormatResult for FormatResult { - fn into_format_result(self) -> FormatResult { - self - } -} - -impl FormatWith for F { - fn with(&self, with: With) -> FormatItemWith - where - With: Fn(FormatElement) -> WithResult, - WithResult: IntoFormatResult, - { - FormatItemWith { with, inner: self } - } -} - -impl FormatOptional for SyntaxResult> { - fn with_or( - &self, - with: With, - op: Or, - ) -> FormatWithOr - where - With: Fn(FormatElement) -> WithResult, - WithResult: IntoFormatResult, - Or: Fn() -> OrResult, - OrResult: IntoFormatResult, - { - match self { - Err(_) => FormatWithOr::With { inner: self, with }, - Ok(Some(value)) => FormatWithOr::With { inner: value, with }, - Ok(None) => FormatWithOr::Or(op), - } - } -} - -impl FormatOptional for Option { - fn with_or( - &self, - with: With, - op: Or, - ) -> FormatWithOr - where - With: Fn(FormatElement) -> WithResult, - WithResult: IntoFormatResult, - Or: Fn() -> OrResult, - OrResult: IntoFormatResult, - { - match self { - None => FormatWithOr::Or(op), - Some(value) => FormatWithOr::With { inner: value, with }, - } - } -} - -pub enum FormatWithOr<'a, With, Or, WithResult, OrResult> -where - With: Fn(FormatElement) -> WithResult, - Or: Fn() -> OrResult, - WithResult: IntoFormatResult, - OrResult: IntoFormatResult, -{ - With { inner: &'a dyn Format, with: With }, - Or(Or), -} - -impl<'a, With, Or, WithResult, OrResult> Format for FormatWithOr<'a, With, Or, WithResult, OrResult> -where - With: Fn(FormatElement) -> WithResult, - Or: Fn() -> OrResult, - WithResult: IntoFormatResult, - OrResult: IntoFormatResult, -{ - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - FormatWithOr::Or(op) => op().into_format_result(), - FormatWithOr::With { inner, with } => { - with(inner.format(formatter)?).into_format_result() - } - } - } -} diff --git a/crates/rome_js_formatter/src/formatter.rs b/crates/rome_js_formatter/src/formatter.rs index 59dd21624cd9..1964b478521f 100644 --- a/crates/rome_js_formatter/src/formatter.rs +++ b/crates/rome_js_formatter/src/formatter.rs @@ -1,32 +1,12 @@ -use crate::{ - block_indent, concat_elements, empty_element, empty_line, format_elements, formatted, - group_elements, hard_line_break, if_group_breaks, if_group_fits_on_single_line, indent, - join_elements_hard_line, line_suffix, soft_block_indent, soft_line_break_or_space, space_token, - Format, FormatElement, FormatOptions, TextRange, Token, Verbatim, -}; -#[cfg(debug_assertions)] -use rome_formatter::printed_tokens::PrintedTokens; +use crate::prelude::*; + use rome_formatter::{normalize_newlines, FormatResult, LINE_TERMINATORS}; use rome_js_syntax::{JsLanguage, JsSyntaxNode, JsSyntaxToken}; -use rome_rowan::{ - AstNode, AstNodeList, AstSeparatedList, Language, SyntaxNode, SyntaxToken, SyntaxTriviaPiece, -}; -#[cfg(debug_assertions)] -use std::cell::RefCell; -use std::iter::once; +use crate::AsFormat; +use rome_rowan::{AstNode, AstNodeList, AstSeparatedList, Language, SyntaxTriviaPiece, TextRange}; -/// Handles the formatting of a CST and stores the options how the CST should be formatted (user preferences). -/// The formatter is passed to the [Format] implementation of every node in the CST so that they -/// can use it to format their children. -#[derive(Debug, Default)] -pub struct Formatter { - options: FormatOptions, - // This is using a RefCell as it only exists in debug mode, - // the Formatter is still completely immutable in release builds - #[cfg(debug_assertions)] - pub(super) printed_tokens: RefCell, -} +use std::iter::once; #[derive(Debug)] pub enum TrailingSeparator { @@ -50,66 +30,6 @@ impl Default for TrailingSeparator { } } -impl Formatter { - /// Creates a new context that uses the given formatter options - pub fn new(options: FormatOptions) -> Self { - Self { - options, - #[cfg(debug_assertions)] - printed_tokens: RefCell::default(), - } - } - - /// Returns the [FormatOptions] specifying how to format the current CST - #[inline] - pub fn options(&self) -> &FormatOptions { - &self.options - } - - /// Tracks the given token as formatted - - pub fn track_token(&self, #[allow(unused_variables)] token: &SyntaxToken) { - cfg_if::cfg_if! { - if #[cfg(debug_assertions)] { - self.printed_tokens.borrow_mut().track_token(token); - } - } - } - - pub fn assert_formatted_all_tokens( - &self, - #[allow(unused_variables)] root: &SyntaxNode, - ) { - cfg_if::cfg_if! { - if #[cfg(debug_assertions)] { - let printed_tokens = self.printed_tokens.borrow(); - printed_tokens.assert_all_tracked(root); - } - } - } - - /// Formats all items of the iterator and returns the formatted result - /// - /// Returns the [Err] of the first item that failed to format. - pub fn format_all( - &self, - nodes: impl IntoIterator, - ) -> FormatResult> { - let mut result = Vec::new(); - - for node in nodes { - match node.format(self) { - Ok(formatted) => { - result.push(formatted); - } - Err(err) => return Err(err), - } - } - - Ok(result.into_iter()) - } -} - /// Determines if the whitespace separating comment trivias /// from their associated tokens should be printed or trimmed #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -118,37 +38,6 @@ pub(super) enum TriviaPrintMode { Trim, } -/// Snapshot of the formatter state used to handle backtracking if -/// errors are encountered in the formatting process and the formatter -/// has to fallback to printing raw tokens -/// -/// In practice this only saves the set of printed tokens in debug -/// mode and compiled to nothing in release mode -pub struct FormatterSnapshot { - #[cfg(debug_assertions)] - printed_tokens: PrintedTokens, -} - -impl Formatter { - /// Take a snapshot of the state of the formatter - pub fn snapshot(&self) -> FormatterSnapshot { - FormatterSnapshot { - #[cfg(debug_assertions)] - printed_tokens: self.printed_tokens.borrow().clone(), - } - } - - #[cfg(debug_assertions)] - /// Restore the state of the formatter to a previous snapshot - pub fn restore(&self, snapshot: FormatterSnapshot) { - *self.printed_tokens.borrow_mut() = snapshot.printed_tokens; - } - - #[cfg(not(debug_assertions))] - /// Restore the state of the formatter to a previous snapshot - pub fn restore(&self, _: FormatterSnapshot) {} -} - /// "Formats" a node according to its original formatting in the source text. Being able to format /// a node "as is" is useful if a node contains syntax errors. Formatting a node with syntax errors /// has the risk that Rome misinterprets the structure of the code and formatting it could @@ -211,12 +100,14 @@ impl Format for FormatSuppressedNode<'_> { fn format(&self, formatter: &Formatter) -> FormatResult { formatted![ formatter, - // Insert a force a line break to ensure the suppression comment is on its own line - // and correctly registers as a leading trivia on the opening token of this node - hard_line_break(), - FormatElement::Verbatim(Verbatim::new_suppressed(format_verbatim_node_or_token( - self.node, formatter - ))), + [ + // Insert a force a line break to ensure the suppression comment is on its own line + // and correctly registers as a leading trivia on the opening token of this node + hard_line_break(), + FormatElement::Verbatim(Verbatim::new_suppressed(format_verbatim_node_or_token( + self.node, formatter + ))), + ] ] } } @@ -618,7 +509,7 @@ pub(crate) trait JsFormatter { trailing_separator: TrailingSeparator, ) -> FormatResult> where - T: AstNode + Format, + for<'a> T: AstNode + AsFormat<'a>, L: AstSeparatedList, F: Fn() -> FormatElement, { @@ -627,7 +518,7 @@ pub(crate) trait JsFormatter { let formatter = self.as_formatter(); for (index, element) in list.elements().enumerate() { - let node = element.node()?.format(formatter)?; + let node = formatted![formatter, [element.node()?.format()]]?; // Reuse the existing trailing separator or create it if it wasn't in the // input source. Only print the last trailing token if the outer group breaks @@ -639,12 +530,12 @@ pub(crate) trait JsFormatter { // but still print its associated trivias unconditionally self.format_replaced(separator, if_group_breaks(Token::from(separator))) } else if trailing_separator.is_mandatory() { - separator.format(formatter)? + formatted![formatter, [separator.format()]]? } else { empty_element() } } else { - separator.format(formatter)? + formatted![formatter, [separator.format()]]? } } else if index == last_index { if trailing_separator.is_allowed() { @@ -658,7 +549,7 @@ pub(crate) trait JsFormatter { separator_factory() }; - result.push(formatted![formatter, node, separator]?); + result.push(formatted![formatter, [node, separator]]?); } Ok(result.into_iter()) @@ -671,17 +562,17 @@ pub(crate) trait JsFormatter { /// end up separated by hard lines or empty lines. /// /// If the formatter fails to format an element, said element gets printed verbatim. - fn format_list + Format>( - &self, - list: List, - ) -> FormatElement + fn format_list(&self, list: &List) -> FormatElement where List: AstNodeList, + for<'a> Node: AstNode + AsFormat<'a>, { let formatter = self.as_formatter(); let formatted_list = list.iter().map(|module_item| { let snapshot = formatter.snapshot(); - let elem = match module_item.format(formatter) { + let format = module_item.format(); + + let elem = match formatted![formatter, [format]] { Ok(result) => result, Err(_) => { formatter.restore(snapshot); @@ -727,8 +618,7 @@ fn format_delimited( let open_token_trailing_trivia = if !open_token_trailing_trivia.is_empty() { formatted![ formatter, - open_token_trailing_trivia, - soft_line_break_or_space() + [open_token_trailing_trivia, soft_line_break_or_space()] ]? } else { empty_element() @@ -736,8 +626,7 @@ fn format_delimited( let close_token_leading_trivia = if !close_token_leading_trivia.is_empty() { formatted![ formatter, - soft_line_break_or_space(), - close_token_leading_trivia + [soft_line_break_or_space(), close_token_leading_trivia] ]? } else { empty_element() @@ -746,15 +635,19 @@ fn format_delimited( let formatted_content = match content { DelimitedContent::BlockIndent(content) => block_indent(formatted![ formatter, - open_token_trailing_trivia, - content, - close_token_leading_trivia + [ + open_token_trailing_trivia, + content, + close_token_leading_trivia + ] ]?), DelimitedContent::SoftBlockIndent(content) => soft_block_indent(formatted![ formatter, - open_token_trailing_trivia, - content, - close_token_leading_trivia + [ + open_token_trailing_trivia, + content, + close_token_leading_trivia + ] ]?), DelimitedContent::SoftBlockSpaces(content) => { if open_token_trailing_trivia.is_empty() @@ -765,14 +658,18 @@ fn format_delimited( } else { formatted![ formatter, - indent(formatted![ - formatter, + [ + indent(formatted![ + formatter, + [ + soft_line_break_or_space(), + open_token_trailing_trivia, + content, + close_token_leading_trivia, + ] + ]?), soft_line_break_or_space(), - open_token_trailing_trivia, - content, - close_token_leading_trivia, - ]?), - soft_line_break_or_space(), + ] ]? } } @@ -780,12 +677,14 @@ fn format_delimited( formatted![ formatter, - format_leading_trivia(open_token, TriviaPrintMode::Full), - group_elements(format_elements![ - Token::from(open_token), - formatted_content, - Token::from(close_token), - ]), - format_trailing_trivia(close_token), + [ + format_leading_trivia(open_token, TriviaPrintMode::Full), + group_elements(format_elements![ + Token::from(open_token), + formatted_content, + Token::from(close_token), + ]), + format_trailing_trivia(close_token), + ] ] } diff --git a/crates/rome_js_formatter/src/generated.rs b/crates/rome_js_formatter/src/generated.rs index 5c4ac58e8324..ebba0090034c 100644 --- a/crates/rome_js_formatter/src/generated.rs +++ b/crates/rome_js_formatter/src/generated.rs @@ -1,1418 +1,5431 @@ //! Generated file, do not edit by hand, see `xtask/codegen` -use crate::prelude::*; -impl Format for rome_js_syntax::JsScript { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsModule { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExpressionSnipped { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsDirective { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsBlockStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsBreakStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsClassDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsContinueStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsDebuggerStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsDoWhileStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsEmptyStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExpressionStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsForInStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsForOfStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsForStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsIfStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsLabeledStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsReturnStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsSwitchStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsThrowStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsTryFinallyStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsTryStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsVariableStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsWhileStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsWithStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsFunctionDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsEnumDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeAliasDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsInterfaceDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsDeclareFunctionDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsDeclareStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsModuleDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsExternalModuleDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsGlobalDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsImportEqualsDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsElseClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsVariableDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsForVariableDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsVariableDeclarator { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsCaseClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsDefaultClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsCatchClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsFinallyClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsCatchDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeAnnotation { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::ImportMeta { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsArrayExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsArrowFunctionExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsAssignmentExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsAwaitExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsBinaryExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsCallExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsClassExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsComputedMemberExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsConditionalExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsFunctionExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsIdentifierExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsImportCallExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsInExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsInstanceofExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsLogicalExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsNewExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsObjectExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsParenthesizedExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsPostUpdateExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsPreUpdateExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsSequenceExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsStaticMemberExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsSuperExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsThisExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnaryExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsYieldExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::NewTarget { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsTemplate { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeAssertionExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsAsExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsNonNullAssertionExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxTagExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeArguments { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsTemplateChunkElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsTemplateElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsCallArguments { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsYieldArgument { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeParameters { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsParameters { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsReturnTypeAnnotation { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsFunctionBody { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsSpread { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsArrayHole { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsReferenceIdentifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsPrivateName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsLiteralMemberName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsComputedMemberName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsPropertyObjectMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsMethodObjectMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsGetterObjectMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsSetterObjectMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsShorthandPropertyObjectMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExtendsClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsImplementsClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsClassExportDefaultDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsPrivateClassMemberName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsConstructorClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsStaticInitializationBlockClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsPropertyClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsMethodClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsGetterClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsSetterClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsConstructorSignatureClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsPropertySignatureClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsMethodSignatureClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsGetterSignatureClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsSetterSignatureClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsIndexSignatureClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsEmptyClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsStaticModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsDeclareModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsReadonlyModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsAbstractModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsOverrideModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsAccessibilityModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsConstructorParameters { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsRestParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsPropertyParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsInitializerClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsOptionalPropertyAnnotation { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsDefinitePropertyAnnotation { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsIndexSignatureParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsIdentifierAssignment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsStaticMemberAssignment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsComputedMemberAssignment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsParenthesizedAssignment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsNonNullAssertionAssignment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsAsAssignment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeAssertionAssignment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsAssignmentWithDefault { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsArrayAssignmentPattern { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsObjectAssignmentPattern { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsArrayAssignmentPatternRestElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsObjectAssignmentPatternShorthandProperty { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsObjectAssignmentPatternProperty { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsObjectAssignmentPatternRest { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsIdentifierBinding { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsBindingPatternWithDefault { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsArrayBindingPattern { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsObjectBindingPattern { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsArrayBindingPatternRestElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsObjectBindingPatternProperty { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsObjectBindingPatternRest { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsObjectBindingPatternShorthandProperty { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsStringLiteralExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsNumberLiteralExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsBigIntLiteralExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsBooleanLiteralExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsNullLiteralExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsRegexLiteralExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsVariableDeclarationClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsDefiniteVariableAnnotation { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExport { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsImport { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsImportBareClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsImportNamedClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsImportDefaultClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsImportNamespaceClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsModuleSource { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsImportAssertion { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsDefaultImportSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsNamedImportSpecifiers { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsNamespaceImportSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsShorthandNamedImportSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsNamedImportSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsLiteralExportName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsImportAssertionEntry { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExportDefaultDeclarationClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExportDefaultExpressionClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExportNamedClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExportFromClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExportNamedFromClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsExportAsNamespaceClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsExportAssignmentClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsExportDeclareClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsFunctionExportDefaultDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExportNamedShorthandSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExportNamedSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExportAsClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsExportNamedFromSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsFormalParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsThisParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsAnyType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsUnknownType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsNumberType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsBooleanType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsBigintType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsStringType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsSymbolType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsVoidType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsUndefinedType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsNeverType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsParenthesizedType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsReferenceType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsArrayType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTupleType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeofType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsImportType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeOperatorType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsIndexedAccessType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsMappedType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsObjectType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsNonPrimitiveType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsThisType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsNumberLiteralType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsBigIntLiteralType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsStringLiteralType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsNullLiteralType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsBooleanLiteralType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTemplateLiteralType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsInferType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsIntersectionType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsUnionType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsFunctionType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsConstructorType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsConditionalType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsIdentifierBinding { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsEnumMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsExternalModuleReference { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsModuleBlock { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsQualifiedModuleName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsEmptyExternalModuleDeclarationBody { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeParameterName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsPredicateReturnType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsAssertsReturnType { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsAssertsCondition { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTypeConstraintClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsDefaultTypeClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsExtendsClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsNameWithTypeArguments { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsCallSignatureTypeMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsPropertySignatureTypeMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsConstructSignatureTypeMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsMethodSignatureTypeMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsGetterSignatureTypeMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsSetterSignatureTypeMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsIndexSignatureTypeMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsMappedTypeReadonlyModifierClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsMappedTypeAsClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsMappedTypeOptionalModifierClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsImportTypeQualifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsNamedTupleTypeElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsRestTupleTypeElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsOptionalTupleTypeElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTemplateChunkElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsTemplateElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::TsQualifiedName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxSelfClosingElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxFragment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxOpeningElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxClosingElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxOpeningFragment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxClosingFragment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxReferenceIdentifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxNamespaceName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxMemberName { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxAttribute { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxSpreadAttribute { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxAttributeInitializerClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxString { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxExpressionAttributeValue { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxText { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxExpressionChild { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsxSpreadChild { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnknown { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnknownStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnknownExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnknownMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnknownBinding { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnknownAssignment { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnknownParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnknownImportAssertionEntry { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } -} -impl Format for rome_js_syntax::JsUnknownNamedImportSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) - } +use crate::{AsFormat, FormatNodeRule, IntoFormat}; +use rome_formatter::{FormatOwnedWithRule, FormatRefWithRule}; +impl<'a> AsFormat<'a> for rome_js_syntax::JsScript { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsScript, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsScript { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsModule { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsModule, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsModule { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExpressionSnipped { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExpressionSnipped, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExpressionSnipped { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExpressionSnipped, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsDirective { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsDirective, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsDirective { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsDirective, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsBlockStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsBlockStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsBlockStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsBlockStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsBreakStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsBreakStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsBreakStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsBreakStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsClassDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsClassDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsClassDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsClassDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsContinueStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsContinueStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsContinueStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsContinueStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsDebuggerStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsDebuggerStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsDebuggerStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsDebuggerStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsDoWhileStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsDoWhileStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsDoWhileStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsDoWhileStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsEmptyStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsEmptyStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsEmptyStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsEmptyStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExpressionStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExpressionStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExpressionStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExpressionStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsForInStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsForInStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsForInStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsForInStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsForOfStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsForOfStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsForOfStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsForOfStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsForStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsForStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsForStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsForStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsIfStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsIfStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsIfStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsIfStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsLabeledStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsLabeledStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsLabeledStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsLabeledStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsReturnStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsReturnStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsReturnStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsReturnStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsSwitchStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsSwitchStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsSwitchStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsSwitchStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsThrowStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsThrowStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsThrowStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsThrowStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsTryFinallyStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsTryFinallyStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsTryFinallyStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsTryFinallyStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsTryStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsTryStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsTryStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsTryStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsVariableStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsVariableStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsVariableStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsVariableStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsWhileStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsWhileStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsWhileStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsWhileStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsWithStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsWithStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsWithStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsWithStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsFunctionDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsFunctionDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsFunctionDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsFunctionDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsEnumDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsEnumDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsEnumDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsEnumDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeAliasDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeAliasDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeAliasDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeAliasDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsInterfaceDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsInterfaceDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsInterfaceDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsInterfaceDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsDeclareFunctionDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsDeclareFunctionDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsDeclareFunctionDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsDeclareFunctionDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsDeclareStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsDeclareStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsDeclareStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsDeclareStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsModuleDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsModuleDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsModuleDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsModuleDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsExternalModuleDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsExternalModuleDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsExternalModuleDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsExternalModuleDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsGlobalDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsGlobalDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsGlobalDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsGlobalDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsImportEqualsDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsImportEqualsDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsImportEqualsDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsImportEqualsDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsElseClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsElseClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsElseClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsElseClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsVariableDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsVariableDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsVariableDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsVariableDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsForVariableDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsForVariableDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsForVariableDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsForVariableDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsVariableDeclarator { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsVariableDeclarator, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsVariableDeclarator { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsVariableDeclarator, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsCaseClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsCaseClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsCaseClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsCaseClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsDefaultClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsDefaultClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsDefaultClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsDefaultClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsCatchClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsCatchClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsCatchClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsCatchClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsFinallyClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsFinallyClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsFinallyClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsFinallyClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsCatchDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsCatchDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsCatchDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsCatchDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeAnnotation { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeAnnotation, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeAnnotation { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeAnnotation, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::ImportMeta { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::ImportMeta, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::ImportMeta { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrayExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsArrayExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrayExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsArrayExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrowFunctionExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsArrowFunctionExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrowFunctionExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsArrowFunctionExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsAssignmentExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAssignmentExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAssignmentExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAssignmentExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsAwaitExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAwaitExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAwaitExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAwaitExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsBinaryExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsBinaryExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsBinaryExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsBinaryExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsCallExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsCallExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsCallExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsCallExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsClassExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsClassExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsClassExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsClassExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsComputedMemberExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsComputedMemberExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsComputedMemberExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsComputedMemberExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsConditionalExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsConditionalExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsConditionalExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsConditionalExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsFunctionExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsFunctionExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsFunctionExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsFunctionExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsIdentifierExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsIdentifierExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsIdentifierExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsIdentifierExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsImportCallExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsImportCallExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsImportCallExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsImportCallExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsInExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsInExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsInExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsInExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsInstanceofExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsInstanceofExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsInstanceofExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsInstanceofExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsLogicalExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsLogicalExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsLogicalExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsLogicalExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsNewExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsNewExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsNewExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsNewExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsParenthesizedExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsParenthesizedExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsParenthesizedExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsParenthesizedExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsPostUpdateExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsPostUpdateExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsPostUpdateExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsPostUpdateExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsPreUpdateExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsPreUpdateExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsPreUpdateExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsPreUpdateExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsSequenceExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsSequenceExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsSequenceExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsSequenceExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsStaticMemberExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsStaticMemberExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsStaticMemberExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsStaticMemberExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsSuperExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsSuperExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsSuperExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsSuperExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsThisExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsThisExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsThisExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsThisExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnaryExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsUnaryExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnaryExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsUnaryExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsYieldExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsYieldExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsYieldExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsYieldExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::NewTarget { + type Format = + FormatRefWithRule<'a, rome_js_syntax::NewTarget, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::NewTarget { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsTemplate { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsTemplate, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsTemplate { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeAssertionExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeAssertionExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeAssertionExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeAssertionExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsAsExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAsExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAsExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAsExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsNonNullAssertionExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsNonNullAssertionExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsNonNullAssertionExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsNonNullAssertionExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxTagExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxTagExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxTagExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxTagExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeArguments { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeArguments, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeArguments { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeArguments, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsTemplateChunkElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsTemplateChunkElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsTemplateChunkElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsTemplateChunkElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsTemplateElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsTemplateElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsTemplateElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsTemplateElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsCallArguments { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsCallArguments, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsCallArguments { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsCallArguments, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsYieldArgument { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsYieldArgument, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsYieldArgument { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsYieldArgument, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeParameters { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeParameters, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeParameters { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeParameters, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsParameters { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsParameters, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsParameters { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsParameters, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsReturnTypeAnnotation { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsReturnTypeAnnotation, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsReturnTypeAnnotation { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsReturnTypeAnnotation, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsFunctionBody { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsFunctionBody, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsFunctionBody { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsFunctionBody, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsSpread { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsSpread, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsSpread { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrayHole { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsArrayHole, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrayHole { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsArrayHole, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsReferenceIdentifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsReferenceIdentifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsReferenceIdentifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsReferenceIdentifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsPrivateName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsPrivateName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsPrivateName { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsPrivateName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsLiteralMemberName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsLiteralMemberName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsLiteralMemberName { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsLiteralMemberName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsComputedMemberName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsComputedMemberName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsComputedMemberName { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsComputedMemberName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsPropertyObjectMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsPropertyObjectMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsPropertyObjectMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsPropertyObjectMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsMethodObjectMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsMethodObjectMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsMethodObjectMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsMethodObjectMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsGetterObjectMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsGetterObjectMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsGetterObjectMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsGetterObjectMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsSetterObjectMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsSetterObjectMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsSetterObjectMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsSetterObjectMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsShorthandPropertyObjectMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsShorthandPropertyObjectMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsShorthandPropertyObjectMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsShorthandPropertyObjectMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExtendsClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExtendsClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExtendsClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExtendsClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsImplementsClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsImplementsClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsImplementsClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsImplementsClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsClassExportDefaultDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsClassExportDefaultDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsClassExportDefaultDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsClassExportDefaultDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsPrivateClassMemberName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsPrivateClassMemberName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsPrivateClassMemberName { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsPrivateClassMemberName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsConstructorClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsConstructorClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsConstructorClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsConstructorClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsStaticInitializationBlockClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsStaticInitializationBlockClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsStaticInitializationBlockClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsStaticInitializationBlockClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsPropertyClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsPropertyClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsPropertyClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsPropertyClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsMethodClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsMethodClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsMethodClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsMethodClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsGetterClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsGetterClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsGetterClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsGetterClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsSetterClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsSetterClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsSetterClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsSetterClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsConstructorSignatureClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsConstructorSignatureClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsConstructorSignatureClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsConstructorSignatureClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsPropertySignatureClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsPropertySignatureClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsPropertySignatureClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsPropertySignatureClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsMethodSignatureClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsMethodSignatureClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsMethodSignatureClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsMethodSignatureClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsGetterSignatureClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsGetterSignatureClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsGetterSignatureClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsGetterSignatureClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsSetterSignatureClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsSetterSignatureClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsSetterSignatureClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsSetterSignatureClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsIndexSignatureClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsIndexSignatureClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsIndexSignatureClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsIndexSignatureClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsEmptyClassMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsEmptyClassMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsEmptyClassMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsEmptyClassMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsStaticModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsStaticModifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsStaticModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsStaticModifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsDeclareModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsDeclareModifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsDeclareModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsDeclareModifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsReadonlyModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsReadonlyModifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsReadonlyModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsReadonlyModifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsAbstractModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAbstractModifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAbstractModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAbstractModifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsOverrideModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsOverrideModifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsOverrideModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsOverrideModifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsAccessibilityModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAccessibilityModifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAccessibilityModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAccessibilityModifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsConstructorParameters { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsConstructorParameters, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsConstructorParameters { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsConstructorParameters, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsRestParameter { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsRestParameter, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsRestParameter { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsRestParameter, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsPropertyParameter { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsPropertyParameter, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsPropertyParameter { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsPropertyParameter, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsInitializerClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsInitializerClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsInitializerClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsInitializerClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsOptionalPropertyAnnotation { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsOptionalPropertyAnnotation, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsOptionalPropertyAnnotation { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsOptionalPropertyAnnotation, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsDefinitePropertyAnnotation { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsDefinitePropertyAnnotation, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsDefinitePropertyAnnotation { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsDefinitePropertyAnnotation, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsIndexSignatureParameter { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsIndexSignatureParameter, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsIndexSignatureParameter { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsIndexSignatureParameter, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsIdentifierAssignment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsIdentifierAssignment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsIdentifierAssignment { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsIdentifierAssignment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsStaticMemberAssignment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsStaticMemberAssignment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsStaticMemberAssignment { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsStaticMemberAssignment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsComputedMemberAssignment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsComputedMemberAssignment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsComputedMemberAssignment { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsComputedMemberAssignment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsParenthesizedAssignment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsParenthesizedAssignment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsParenthesizedAssignment { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsParenthesizedAssignment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsNonNullAssertionAssignment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsNonNullAssertionAssignment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsNonNullAssertionAssignment { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsNonNullAssertionAssignment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsAsAssignment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAsAssignment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAsAssignment { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAsAssignment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeAssertionAssignment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeAssertionAssignment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeAssertionAssignment { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeAssertionAssignment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsAssignmentWithDefault { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAssignmentWithDefault, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAssignmentWithDefault { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAssignmentWithDefault, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrayAssignmentPattern { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsArrayAssignmentPattern, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrayAssignmentPattern { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsArrayAssignmentPattern, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectAssignmentPattern { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectAssignmentPattern, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectAssignmentPattern { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectAssignmentPattern, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrayAssignmentPatternRestElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsArrayAssignmentPatternRestElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrayAssignmentPatternRestElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsArrayAssignmentPatternRestElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectAssignmentPatternShorthandProperty { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectAssignmentPatternShorthandProperty, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectAssignmentPatternShorthandProperty { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectAssignmentPatternShorthandProperty, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectAssignmentPatternProperty { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectAssignmentPatternProperty, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectAssignmentPatternProperty { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectAssignmentPatternProperty, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectAssignmentPatternRest { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectAssignmentPatternRest, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectAssignmentPatternRest { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectAssignmentPatternRest, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsIdentifierBinding { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsIdentifierBinding, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsIdentifierBinding { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsIdentifierBinding, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsBindingPatternWithDefault { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsBindingPatternWithDefault, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsBindingPatternWithDefault { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsBindingPatternWithDefault, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrayBindingPattern { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsArrayBindingPattern, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrayBindingPattern { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsArrayBindingPattern, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectBindingPattern { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectBindingPattern, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectBindingPattern { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectBindingPattern, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrayBindingPatternRestElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsArrayBindingPatternRestElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrayBindingPatternRestElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsArrayBindingPatternRestElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectBindingPatternProperty { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectBindingPatternProperty, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectBindingPatternProperty { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectBindingPatternProperty, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectBindingPatternRest { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectBindingPatternRest, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectBindingPatternRest { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectBindingPatternRest, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectBindingPatternShorthandProperty { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectBindingPatternShorthandProperty, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectBindingPatternShorthandProperty { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectBindingPatternShorthandProperty, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsStringLiteralExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsStringLiteralExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsStringLiteralExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsStringLiteralExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsNumberLiteralExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsNumberLiteralExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsNumberLiteralExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsNumberLiteralExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsBigIntLiteralExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsBigIntLiteralExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsBigIntLiteralExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsBigIntLiteralExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsBooleanLiteralExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsBooleanLiteralExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsBooleanLiteralExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsBooleanLiteralExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsNullLiteralExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsNullLiteralExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsNullLiteralExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsNullLiteralExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsRegexLiteralExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsRegexLiteralExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsRegexLiteralExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsRegexLiteralExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsVariableDeclarationClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsVariableDeclarationClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsVariableDeclarationClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsVariableDeclarationClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsDefiniteVariableAnnotation { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsDefiniteVariableAnnotation, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsDefiniteVariableAnnotation { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsDefiniteVariableAnnotation, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExport { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsExport, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExport { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsImport { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsImport, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsImport { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsImportBareClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsImportBareClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsImportBareClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsImportBareClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsImportNamedClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsImportNamedClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsImportNamedClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsImportNamedClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsImportDefaultClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsImportDefaultClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsImportDefaultClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsImportDefaultClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsImportNamespaceClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsImportNamespaceClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsImportNamespaceClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsImportNamespaceClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsModuleSource { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsModuleSource, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsModuleSource { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsModuleSource, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsImportAssertion { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsImportAssertion, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsImportAssertion { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsImportAssertion, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsDefaultImportSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsDefaultImportSpecifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsDefaultImportSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsDefaultImportSpecifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsNamedImportSpecifiers { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsNamedImportSpecifiers, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsNamedImportSpecifiers { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsNamedImportSpecifiers, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsNamespaceImportSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsNamespaceImportSpecifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsNamespaceImportSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsNamespaceImportSpecifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsShorthandNamedImportSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsShorthandNamedImportSpecifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsShorthandNamedImportSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsShorthandNamedImportSpecifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsNamedImportSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsNamedImportSpecifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsNamedImportSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsNamedImportSpecifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsLiteralExportName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsLiteralExportName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsLiteralExportName { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsLiteralExportName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsImportAssertionEntry { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsImportAssertionEntry, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsImportAssertionEntry { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsImportAssertionEntry, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportDefaultDeclarationClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportDefaultDeclarationClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportDefaultDeclarationClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportDefaultDeclarationClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportDefaultExpressionClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportDefaultExpressionClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportDefaultExpressionClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportDefaultExpressionClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportNamedClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportNamedClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportNamedClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportNamedClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportFromClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportFromClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportFromClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportFromClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportNamedFromClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportNamedFromClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportNamedFromClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportNamedFromClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsExportAsNamespaceClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsExportAsNamespaceClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsExportAsNamespaceClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsExportAsNamespaceClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsExportAssignmentClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsExportAssignmentClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsExportAssignmentClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsExportAssignmentClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsExportDeclareClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsExportDeclareClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsExportDeclareClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsExportDeclareClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsFunctionExportDefaultDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsFunctionExportDefaultDeclaration, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsFunctionExportDefaultDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsFunctionExportDefaultDeclaration, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportNamedShorthandSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportNamedShorthandSpecifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportNamedShorthandSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportNamedShorthandSpecifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportNamedSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportNamedSpecifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportNamedSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportNamedSpecifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportAsClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportAsClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportAsClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportAsClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportNamedFromSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportNamedFromSpecifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportNamedFromSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportNamedFromSpecifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsName { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsName, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsName { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsFormalParameter { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsFormalParameter, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsFormalParameter { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsFormalParameter, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsThisParameter { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsThisParameter, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsThisParameter { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsThisParameter, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyType { + type Format = + FormatRefWithRule<'a, rome_js_syntax::TsAnyType, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyType { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsUnknownType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsUnknownType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsUnknownType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsUnknownType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsNumberType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsNumberType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsNumberType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsNumberType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsBooleanType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsBooleanType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsBooleanType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsBooleanType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsBigintType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsBigintType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsBigintType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsBigintType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsStringType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsStringType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsStringType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsStringType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsSymbolType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsSymbolType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsSymbolType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsSymbolType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsVoidType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsVoidType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsVoidType { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsUndefinedType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsUndefinedType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsUndefinedType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsUndefinedType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsNeverType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsNeverType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsNeverType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsNeverType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsParenthesizedType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsParenthesizedType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsParenthesizedType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsParenthesizedType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsReferenceType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsReferenceType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsReferenceType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsReferenceType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsArrayType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsArrayType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsArrayType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsArrayType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTupleType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTupleType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTupleType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTupleType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeofType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeofType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeofType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeofType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsImportType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsImportType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsImportType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsImportType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeOperatorType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeOperatorType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeOperatorType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeOperatorType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsIndexedAccessType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsIndexedAccessType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsIndexedAccessType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsIndexedAccessType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsMappedType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsMappedType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsMappedType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsMappedType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsObjectType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsObjectType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsObjectType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsObjectType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsNonPrimitiveType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsNonPrimitiveType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsNonPrimitiveType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsNonPrimitiveType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsThisType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsThisType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsThisType { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsNumberLiteralType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsNumberLiteralType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsNumberLiteralType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsNumberLiteralType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsBigIntLiteralType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsBigIntLiteralType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsBigIntLiteralType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsBigIntLiteralType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsStringLiteralType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsStringLiteralType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsStringLiteralType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsStringLiteralType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsNullLiteralType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsNullLiteralType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsNullLiteralType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsNullLiteralType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsBooleanLiteralType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsBooleanLiteralType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsBooleanLiteralType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsBooleanLiteralType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTemplateLiteralType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTemplateLiteralType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTemplateLiteralType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTemplateLiteralType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsInferType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsInferType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsInferType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsInferType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsIntersectionType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsIntersectionType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsIntersectionType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsIntersectionType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsUnionType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsUnionType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsUnionType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsUnionType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsFunctionType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsFunctionType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsFunctionType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsFunctionType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsConstructorType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsConstructorType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsConstructorType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsConstructorType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsConditionalType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsConditionalType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsConditionalType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsConditionalType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsIdentifierBinding { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsIdentifierBinding, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsIdentifierBinding { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsIdentifierBinding, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsEnumMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsEnumMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsEnumMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsEnumMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsExternalModuleReference { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsExternalModuleReference, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsExternalModuleReference { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsExternalModuleReference, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsModuleBlock { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsModuleBlock, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsModuleBlock { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsModuleBlock, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsQualifiedModuleName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsQualifiedModuleName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsQualifiedModuleName { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsQualifiedModuleName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsEmptyExternalModuleDeclarationBody { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsEmptyExternalModuleDeclarationBody, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsEmptyExternalModuleDeclarationBody { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsEmptyExternalModuleDeclarationBody, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeParameterName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeParameterName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeParameterName { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeParameterName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsPredicateReturnType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsPredicateReturnType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsPredicateReturnType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsPredicateReturnType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsAssertsReturnType { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAssertsReturnType, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAssertsReturnType { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAssertsReturnType, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsAssertsCondition { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAssertsCondition, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAssertsCondition { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAssertsCondition, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeParameter { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeParameter, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeParameter { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeParameter, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeConstraintClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTypeConstraintClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeConstraintClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTypeConstraintClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsDefaultTypeClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsDefaultTypeClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsDefaultTypeClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsDefaultTypeClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsExtendsClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsExtendsClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsExtendsClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsExtendsClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsNameWithTypeArguments { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsNameWithTypeArguments, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsNameWithTypeArguments { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsNameWithTypeArguments, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsCallSignatureTypeMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsCallSignatureTypeMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsCallSignatureTypeMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsCallSignatureTypeMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsPropertySignatureTypeMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsPropertySignatureTypeMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsPropertySignatureTypeMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsPropertySignatureTypeMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsConstructSignatureTypeMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsConstructSignatureTypeMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsConstructSignatureTypeMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsConstructSignatureTypeMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsMethodSignatureTypeMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsMethodSignatureTypeMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsMethodSignatureTypeMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsMethodSignatureTypeMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsGetterSignatureTypeMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsGetterSignatureTypeMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsGetterSignatureTypeMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsGetterSignatureTypeMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsSetterSignatureTypeMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsSetterSignatureTypeMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsSetterSignatureTypeMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsSetterSignatureTypeMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsIndexSignatureTypeMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsIndexSignatureTypeMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsIndexSignatureTypeMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsIndexSignatureTypeMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsMappedTypeReadonlyModifierClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsMappedTypeReadonlyModifierClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsMappedTypeReadonlyModifierClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsMappedTypeReadonlyModifierClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsMappedTypeAsClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsMappedTypeAsClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsMappedTypeAsClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsMappedTypeAsClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsMappedTypeOptionalModifierClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsMappedTypeOptionalModifierClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsMappedTypeOptionalModifierClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsMappedTypeOptionalModifierClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsImportTypeQualifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsImportTypeQualifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsImportTypeQualifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsImportTypeQualifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsNamedTupleTypeElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsNamedTupleTypeElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsNamedTupleTypeElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsNamedTupleTypeElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsRestTupleTypeElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsRestTupleTypeElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsRestTupleTypeElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsRestTupleTypeElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsOptionalTupleTypeElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsOptionalTupleTypeElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsOptionalTupleTypeElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsOptionalTupleTypeElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTemplateChunkElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTemplateChunkElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTemplateChunkElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTemplateChunkElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsTemplateElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsTemplateElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTemplateElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsTemplateElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::TsQualifiedName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsQualifiedName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsQualifiedName { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsQualifiedName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxElement { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxSelfClosingElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxSelfClosingElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxSelfClosingElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxSelfClosingElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxFragment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxFragment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxFragment { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxFragment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxOpeningElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxOpeningElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxOpeningElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxOpeningElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxClosingElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxClosingElement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxClosingElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxClosingElement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxOpeningFragment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxOpeningFragment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxOpeningFragment { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxOpeningFragment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxClosingFragment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxClosingFragment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxClosingFragment { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxClosingFragment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxName { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsxName, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxName { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxReferenceIdentifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxReferenceIdentifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxReferenceIdentifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxReferenceIdentifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxNamespaceName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxNamespaceName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxNamespaceName { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxNamespaceName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxMemberName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxMemberName, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxMemberName { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxMemberName, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAttribute { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxAttribute, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAttribute { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxAttribute, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxSpreadAttribute { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxSpreadAttribute, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxSpreadAttribute { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxSpreadAttribute, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAttributeInitializerClause { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxAttributeInitializerClause, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAttributeInitializerClause { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxAttributeInitializerClause, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxString { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsxString, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxString { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxExpressionAttributeValue { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxExpressionAttributeValue, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxExpressionAttributeValue { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxExpressionAttributeValue, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxText { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsxText, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxText { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxExpressionChild { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxExpressionChild, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxExpressionChild { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxExpressionChild, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsxSpreadChild { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsxSpreadChild, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxSpreadChild { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsxSpreadChild, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsArrayAssignmentPatternElementList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrayAssignmentPatternElementList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsArrayAssignmentPatternElementList, + FormatJsArrayAssignmentPatternElementList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrayAssignmentPatternElementList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsArrayAssignmentPatternElementList, + FormatJsArrayAssignmentPatternElementList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsArrayBindingPatternElementList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrayBindingPatternElementList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsArrayBindingPatternElementList, + FormatJsArrayBindingPatternElementList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrayBindingPatternElementList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsArrayBindingPatternElementList, + FormatJsArrayBindingPatternElementList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsArrayElementList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsArrayElementList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsArrayElementList, FormatJsArrayElementList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsArrayElementList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsCallArgumentList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsCallArgumentList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsCallArgumentList, FormatJsCallArgumentList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsCallArgumentList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsClassMemberList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsClassMemberList { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsClassMemberList, FormatJsClassMemberList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsClassMemberList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsConstructorModifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsConstructorModifierList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsConstructorModifierList, + FormatJsConstructorModifierList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsConstructorModifierList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsConstructorModifierList, + FormatJsConstructorModifierList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsConstructorParameterList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsConstructorParameterList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsConstructorParameterList, + FormatJsConstructorParameterList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsConstructorParameterList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsConstructorParameterList, + FormatJsConstructorParameterList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsDirectiveList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsDirectiveList { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsDirectiveList, FormatJsDirectiveList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsDirectiveList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsExportNamedFromSpecifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportNamedFromSpecifierList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportNamedFromSpecifierList, + FormatJsExportNamedFromSpecifierList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportNamedFromSpecifierList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportNamedFromSpecifierList, + FormatJsExportNamedFromSpecifierList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsExportNamedSpecifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsExportNamedSpecifierList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsExportNamedSpecifierList, + FormatJsExportNamedSpecifierList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsExportNamedSpecifierList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsExportNamedSpecifierList, + FormatJsExportNamedSpecifierList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsImportAssertionEntryList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsImportAssertionEntryList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsImportAssertionEntryList, + FormatJsImportAssertionEntryList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsImportAssertionEntryList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsImportAssertionEntryList, + FormatJsImportAssertionEntryList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsMethodModifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsMethodModifierList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsMethodModifierList, FormatJsMethodModifierList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsMethodModifierList { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsModuleItemList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsModuleItemList { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsModuleItemList, FormatJsModuleItemList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsModuleItemList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsNamedImportSpecifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsNamedImportSpecifierList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsNamedImportSpecifierList, + FormatJsNamedImportSpecifierList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsNamedImportSpecifierList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsNamedImportSpecifierList, + FormatJsNamedImportSpecifierList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsObjectAssignmentPatternPropertyList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectAssignmentPatternPropertyList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectAssignmentPatternPropertyList, + FormatJsObjectAssignmentPatternPropertyList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectAssignmentPatternPropertyList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectAssignmentPatternPropertyList, + FormatJsObjectAssignmentPatternPropertyList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsObjectBindingPatternPropertyList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectBindingPatternPropertyList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsObjectBindingPatternPropertyList, + FormatJsObjectBindingPatternPropertyList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectBindingPatternPropertyList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsObjectBindingPatternPropertyList, + FormatJsObjectBindingPatternPropertyList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsObjectMemberList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsObjectMemberList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsObjectMemberList, FormatJsObjectMemberList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsObjectMemberList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsParameterList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsParameterList { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsParameterList, FormatJsParameterList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsParameterList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsPropertyModifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsPropertyModifierList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsPropertyModifierList, FormatJsPropertyModifierList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsPropertyModifierList { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsStatementList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsStatementList { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsStatementList, FormatJsStatementList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsStatementList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsSwitchCaseList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsSwitchCaseList { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsSwitchCaseList, FormatJsSwitchCaseList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsSwitchCaseList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsTemplateElementList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsTemplateElementList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsTemplateElementList, FormatJsTemplateElementList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsTemplateElementList { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsVariableDeclaratorList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsVariableDeclaratorList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsVariableDeclaratorList, + FormatJsVariableDeclaratorList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsVariableDeclaratorList { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsVariableDeclaratorList, + FormatJsVariableDeclaratorList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxAttributeList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAttributeList { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsxAttributeList, FormatJsxAttributeList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAttributeList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxChildList; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxChildList { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsxChildList, FormatJsxChildList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxChildList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsEnumMemberList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsEnumMemberList { + type Format = FormatRefWithRule<'a, rome_js_syntax::TsEnumMemberList, FormatTsEnumMemberList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsEnumMemberList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsIndexSignatureModifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsIndexSignatureModifierList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsIndexSignatureModifierList, + FormatTsIndexSignatureModifierList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsIndexSignatureModifierList { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsIndexSignatureModifierList, + FormatTsIndexSignatureModifierList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsIntersectionTypeElementList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsIntersectionTypeElementList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsIntersectionTypeElementList, + FormatTsIntersectionTypeElementList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsIntersectionTypeElementList { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsIntersectionTypeElementList, + FormatTsIntersectionTypeElementList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsMethodSignatureModifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsMethodSignatureModifierList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsMethodSignatureModifierList, + FormatTsMethodSignatureModifierList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsMethodSignatureModifierList { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsMethodSignatureModifierList, + FormatTsMethodSignatureModifierList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsPropertyParameterModifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsPropertyParameterModifierList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsPropertyParameterModifierList, + FormatTsPropertyParameterModifierList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsPropertyParameterModifierList { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsPropertyParameterModifierList, + FormatTsPropertyParameterModifierList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsPropertySignatureModifierList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsPropertySignatureModifierList { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsPropertySignatureModifierList, + FormatTsPropertySignatureModifierList, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsPropertySignatureModifierList { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsPropertySignatureModifierList, + FormatTsPropertySignatureModifierList, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsTemplateElementList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsTemplateElementList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::TsTemplateElementList, FormatTsTemplateElementList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTemplateElementList { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsTupleTypeElementList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsTupleTypeElementList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::TsTupleTypeElementList, FormatTsTupleTypeElementList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTupleTypeElementList { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsTypeArgumentList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeArgumentList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::TsTypeArgumentList, FormatTsTypeArgumentList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeArgumentList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsTypeList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeList { + type Format = FormatRefWithRule<'a, rome_js_syntax::TsTypeList, FormatTsTypeList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsTypeMemberList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeMemberList { + type Format = FormatRefWithRule<'a, rome_js_syntax::TsTypeMemberList, FormatTsTypeMemberList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeMemberList { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsTypeParameterList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsTypeParameterList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::TsTypeParameterList, FormatTsTypeParameterList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsTypeParameterList { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsUnionTypeVariantList; +impl<'a> AsFormat<'a> for rome_js_syntax::TsUnionTypeVariantList { + type Format = + FormatRefWithRule<'a, rome_js_syntax::TsUnionTypeVariantList, FormatTsUnionTypeVariantList>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsUnionTypeVariantList { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnknown { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsUnknown, FormatNodeRule>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnknown { + type Format = + FormatOwnedWithRule>; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnknownStatement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsUnknownStatement, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnknownStatement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsUnknownStatement, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnknownExpression { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsUnknownExpression, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnknownExpression { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsUnknownExpression, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnknownMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsUnknownMember, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnknownMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsUnknownMember, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnknownBinding { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsUnknownBinding, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnknownBinding { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsUnknownBinding, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnknownAssignment { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsUnknownAssignment, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnknownAssignment { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsUnknownAssignment, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnknownParameter { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsUnknownParameter, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnknownParameter { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsUnknownParameter, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnknownImportAssertionEntry { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsUnknownImportAssertionEntry, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnknownImportAssertionEntry { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsUnknownImportAssertionEntry, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +impl<'a> AsFormat<'a> for rome_js_syntax::JsUnknownNamedImportSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsUnknownNamedImportSpecifier, + FormatNodeRule, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsUnknownNamedImportSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsUnknownNamedImportSpecifier, + FormatNodeRule, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyRoot; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyRoot { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyRoot, FormatJsAnyRoot>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyRoot { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyExpression; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyExpression { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyExpression, FormatJsAnyExpression>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyExpression { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyStatement; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyStatement { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyStatement, FormatJsAnyStatement>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyStatement { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyForInitializer; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyForInitializer { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyForInitializer, FormatJsAnyForInitializer>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyForInitializer { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyForInOrOfInitializer; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyForInOrOfInitializer { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyForInOrOfInitializer, + FormatJsAnyForInOrOfInitializer, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyForInOrOfInitializer { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyForInOrOfInitializer, + FormatJsAnyForInOrOfInitializer, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyAssignmentPattern; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyAssignmentPattern { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyAssignmentPattern, FormatJsAnyAssignmentPattern>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyAssignmentPattern { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnySwitchClause; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnySwitchClause { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnySwitchClause, FormatJsAnySwitchClause>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnySwitchClause { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyBindingPattern; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyBindingPattern { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyBindingPattern, FormatJsAnyBindingPattern>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyBindingPattern { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyDeclarationClause; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyDeclarationClause { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyDeclarationClause, FormatJsAnyDeclarationClause>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyDeclarationClause { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyLiteralExpression; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyLiteralExpression { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyLiteralExpression, FormatJsAnyLiteralExpression>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyLiteralExpression { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyTemplateElement; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyTemplateElement { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyTemplateElement, FormatJsAnyTemplateElement>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyTemplateElement { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyBinding; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyBinding { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyBinding, FormatJsAnyBinding>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyBinding { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyArrowFunctionParameters; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyArrowFunctionParameters { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyArrowFunctionParameters, + FormatJsAnyArrowFunctionParameters, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyArrowFunctionParameters { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyArrowFunctionParameters, + FormatJsAnyArrowFunctionParameters, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyFunctionBody; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyFunctionBody { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyFunctionBody, FormatJsAnyFunctionBody>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyFunctionBody { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyArrayElement; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyArrayElement { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyArrayElement, FormatJsAnyArrayElement>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyArrayElement { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyName; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyName { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyName, FormatJsAnyName>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyName { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyInProperty; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyInProperty { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyInProperty, FormatJsAnyInProperty>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyInProperty { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyAssignment; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyAssignment { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyAssignment, FormatJsAnyAssignment>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyAssignment { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyObjectMemberName; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyObjectMemberName { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyObjectMemberName, FormatJsAnyObjectMemberName>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyObjectMemberName { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyObjectMember; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyObjectMember { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyObjectMember, FormatJsAnyObjectMember>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyObjectMember { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyFormalParameter; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyFormalParameter { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyFormalParameter, FormatJsAnyFormalParameter>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyFormalParameter { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyClassMember; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyClassMember { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyClassMember, FormatJsAnyClassMember>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyClassMember { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyClass; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyClass { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyClass, FormatJsAnyClass>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyClass { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyClassMemberName; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyClassMemberName { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyClassMemberName, FormatJsAnyClassMemberName>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyClassMemberName { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyConstructorParameter; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyConstructorParameter { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyConstructorParameter, + FormatJsAnyConstructorParameter, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyConstructorParameter { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyConstructorParameter, + FormatJsAnyConstructorParameter, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyPropertyParameterModifier; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyPropertyParameterModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAnyPropertyParameterModifier, + FormatTsAnyPropertyParameterModifier, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyPropertyParameterModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAnyPropertyParameterModifier, + FormatTsAnyPropertyParameterModifier, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyPropertyAnnotation; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyPropertyAnnotation { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAnyPropertyAnnotation, + FormatTsAnyPropertyAnnotation, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyPropertyAnnotation { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyPropertyModifier; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyPropertyModifier { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyPropertyModifier, FormatJsAnyPropertyModifier>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyPropertyModifier { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyPropertySignatureAnnotation; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyPropertySignatureAnnotation { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAnyPropertySignatureAnnotation, + FormatTsAnyPropertySignatureAnnotation, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyPropertySignatureAnnotation { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAnyPropertySignatureAnnotation, + FormatTsAnyPropertySignatureAnnotation, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyPropertySignatureModifier; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyPropertySignatureModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAnyPropertySignatureModifier, + FormatTsAnyPropertySignatureModifier, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyPropertySignatureModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAnyPropertySignatureModifier, + FormatTsAnyPropertySignatureModifier, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyMethodModifier; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyMethodModifier { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsAnyMethodModifier, FormatJsAnyMethodModifier>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyMethodModifier { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyMethodSignatureModifier; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyMethodSignatureModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAnyMethodSignatureModifier, + FormatTsAnyMethodSignatureModifier, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyMethodSignatureModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAnyMethodSignatureModifier, + FormatTsAnyMethodSignatureModifier, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyIndexSignatureModifier; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyIndexSignatureModifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAnyIndexSignatureModifier, + FormatTsAnyIndexSignatureModifier, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyIndexSignatureModifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAnyIndexSignatureModifier, + FormatTsAnyIndexSignatureModifier, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsType; +impl<'a> AsFormat<'a> for rome_js_syntax::TsType { + type Format = FormatRefWithRule<'a, rome_js_syntax::TsType, FormatTsType>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsType { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyArrayAssignmentPatternElement; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyArrayAssignmentPatternElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyArrayAssignmentPatternElement, + FormatJsAnyArrayAssignmentPatternElement, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyArrayAssignmentPatternElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyArrayAssignmentPatternElement, + FormatJsAnyArrayAssignmentPatternElement, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyObjectAssignmentPatternMember; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyObjectAssignmentPatternMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyObjectAssignmentPatternMember, + FormatJsAnyObjectAssignmentPatternMember, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyObjectAssignmentPatternMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyObjectAssignmentPatternMember, + FormatJsAnyObjectAssignmentPatternMember, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyArrayBindingPatternElement; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyArrayBindingPatternElement { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyArrayBindingPatternElement, + FormatJsAnyArrayBindingPatternElement, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyArrayBindingPatternElement { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyArrayBindingPatternElement, + FormatJsAnyArrayBindingPatternElement, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyObjectBindingPatternMember; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyObjectBindingPatternMember { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyObjectBindingPatternMember, + FormatJsAnyObjectBindingPatternMember, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyObjectBindingPatternMember { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyObjectBindingPatternMember, + FormatJsAnyObjectBindingPatternMember, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyDeclaration; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyDeclaration { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyDeclaration, FormatJsAnyDeclaration>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyDeclaration { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyReturnType; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyReturnType { + type Format = FormatRefWithRule<'a, rome_js_syntax::TsAnyReturnType, FormatTsAnyReturnType>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyReturnType { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyVariableAnnotation; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyVariableAnnotation { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAnyVariableAnnotation, + FormatTsAnyVariableAnnotation, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyVariableAnnotation { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyModuleItem; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyModuleItem { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyModuleItem, FormatJsAnyModuleItem>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyModuleItem { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyImportClause; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyImportClause { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyImportClause, FormatJsAnyImportClause>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyImportClause { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyNamedImport; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyNamedImport { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyNamedImport, FormatJsAnyNamedImport>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyNamedImport { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyNamedImportSpecifier; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyNamedImportSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyNamedImportSpecifier, + FormatJsAnyNamedImportSpecifier, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyNamedImportSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyNamedImportSpecifier, + FormatJsAnyNamedImportSpecifier, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyImportAssertionEntry; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyImportAssertionEntry { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyImportAssertionEntry, + FormatJsAnyImportAssertionEntry, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyImportAssertionEntry { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyImportAssertionEntry, + FormatJsAnyImportAssertionEntry, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyExportClause; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyExportClause { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyExportClause, FormatJsAnyExportClause>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyExportClause { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyExportDefaultDeclaration; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyExportDefaultDeclaration { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyExportDefaultDeclaration, + FormatJsAnyExportDefaultDeclaration, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyExportDefaultDeclaration { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyExportDefaultDeclaration, + FormatJsAnyExportDefaultDeclaration, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyExportNamedSpecifier; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyExportNamedSpecifier { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::JsAnyExportNamedSpecifier, + FormatJsAnyExportNamedSpecifier, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyExportNamedSpecifier { + type Format = FormatOwnedWithRule< + rome_js_syntax::JsAnyExportNamedSpecifier, + FormatJsAnyExportNamedSpecifier, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyFunction; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyFunction { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyFunction, FormatJsAnyFunction>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyFunction { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyParameter; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyParameter { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyParameter, FormatJsAnyParameter>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyParameter { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsAnyCallArgument; +impl<'a> AsFormat<'a> for rome_js_syntax::JsAnyCallArgument { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsAnyCallArgument, FormatJsAnyCallArgument>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsAnyCallArgument { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyName; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyName { + type Format = FormatRefWithRule<'a, rome_js_syntax::TsAnyName, FormatTsAnyName>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyName { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyModuleReference; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyModuleReference { + type Format = + FormatRefWithRule<'a, rome_js_syntax::TsAnyModuleReference, FormatTsAnyModuleReference>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyModuleReference { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyModuleName; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyModuleName { + type Format = FormatRefWithRule<'a, rome_js_syntax::TsAnyModuleName, FormatTsAnyModuleName>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyModuleName { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyExternalModuleDeclarationBody; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyExternalModuleDeclarationBody { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAnyExternalModuleDeclarationBody, + FormatTsAnyExternalModuleDeclarationBody, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyExternalModuleDeclarationBody { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAnyExternalModuleDeclarationBody, + FormatTsAnyExternalModuleDeclarationBody, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyTypePredicateParameterName; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyTypePredicateParameterName { + type Format = FormatRefWithRule< + 'a, + rome_js_syntax::TsAnyTypePredicateParameterName, + FormatTsAnyTypePredicateParameterName, + >; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyTypePredicateParameterName { + type Format = FormatOwnedWithRule< + rome_js_syntax::TsAnyTypePredicateParameterName, + FormatTsAnyTypePredicateParameterName, + >; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyTypeMember; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyTypeMember { + type Format = FormatRefWithRule<'a, rome_js_syntax::TsAnyTypeMember, FormatTsAnyTypeMember>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyTypeMember { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyTupleTypeElement; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyTupleTypeElement { + type Format = + FormatRefWithRule<'a, rome_js_syntax::TsAnyTupleTypeElement, FormatTsAnyTupleTypeElement>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyTupleTypeElement { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatTsAnyTemplateElement; +impl<'a> AsFormat<'a> for rome_js_syntax::TsAnyTemplateElement { + type Format = + FormatRefWithRule<'a, rome_js_syntax::TsAnyTemplateElement, FormatTsAnyTemplateElement>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::TsAnyTemplateElement { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxAnyTag; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAnyTag { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsxAnyTag, FormatJsxAnyTag>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAnyTag { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxAnyElementName; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAnyElementName { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsxAnyElementName, FormatJsxAnyElementName>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAnyElementName { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxAnyObjectName; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAnyObjectName { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsxAnyObjectName, FormatJsxAnyObjectName>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAnyObjectName { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxAnyName; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAnyName { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsxAnyName, FormatJsxAnyName>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAnyName { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxAnyAttribute; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAnyAttribute { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsxAnyAttribute, FormatJsxAnyAttribute>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAnyAttribute { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxAnyAttributeName; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAnyAttributeName { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsxAnyAttributeName, FormatJsxAnyAttributeName>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAnyAttributeName { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxAnyAttributeValue; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAnyAttributeValue { + type Format = + FormatRefWithRule<'a, rome_js_syntax::JsxAnyAttributeValue, FormatJsxAnyAttributeValue>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAnyAttributeValue { + type Format = + FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } +} +pub struct FormatJsxAnyChild; +impl<'a> AsFormat<'a> for rome_js_syntax::JsxAnyChild { + type Format = FormatRefWithRule<'a, rome_js_syntax::JsxAnyChild, FormatJsxAnyChild>; + fn format(&'a self) -> Self::Format { FormatRefWithRule::new(self) } +} +impl IntoFormat for rome_js_syntax::JsxAnyChild { + type Format = FormatOwnedWithRule; + fn into_format(self) -> Self::Format { FormatOwnedWithRule::new(self) } } diff --git a/crates/rome_js_formatter/src/js/any/array_assignment_pattern_element.rs b/crates/rome_js_formatter/src/js/any/array_assignment_pattern_element.rs index 5af34f607e47..9330a10dfa07 100644 --- a/crates/rome_js_formatter/src/js/any/array_assignment_pattern_element.rs +++ b/crates/rome_js_formatter/src/js/any/array_assignment_pattern_element.rs @@ -1,14 +1,26 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyArrayAssignmentPatternElement; use crate::prelude::*; use rome_js_syntax::JsAnyArrayAssignmentPatternElement; -impl Format for JsAnyArrayAssignmentPatternElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAssignmentWithDefault(node) => node.format(formatter), - Self::JsAnyAssignmentPattern(node) => node.format(formatter), - Self::JsArrayAssignmentPatternRestElement(node) => node.format(formatter), - Self::JsArrayHole(node) => node.format(formatter), +impl FormatRule for FormatJsAnyArrayAssignmentPatternElement { + fn format( + node: &JsAnyArrayAssignmentPatternElement, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyArrayAssignmentPatternElement::JsAssignmentWithDefault(node) => { + formatted![formatter, [node.format()]] + } + JsAnyArrayAssignmentPatternElement::JsAnyAssignmentPattern(node) => { + formatted![formatter, [node.format()]] + } + JsAnyArrayAssignmentPatternElement::JsArrayAssignmentPatternRestElement(node) => { + formatted![formatter, [node.format()]] + } + JsAnyArrayAssignmentPatternElement::JsArrayHole(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/array_binding_pattern_element.rs b/crates/rome_js_formatter/src/js/any/array_binding_pattern_element.rs index 808e6d9c3dab..8345eef89ee0 100644 --- a/crates/rome_js_formatter/src/js/any/array_binding_pattern_element.rs +++ b/crates/rome_js_formatter/src/js/any/array_binding_pattern_element.rs @@ -1,14 +1,26 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyArrayBindingPatternElement; use crate::prelude::*; use rome_js_syntax::JsAnyArrayBindingPatternElement; -impl Format for JsAnyArrayBindingPatternElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsArrayHole(node) => node.format(formatter), - Self::JsAnyBindingPattern(node) => node.format(formatter), - Self::JsBindingPatternWithDefault(node) => node.format(formatter), - Self::JsArrayBindingPatternRestElement(node) => node.format(formatter), +impl FormatRule for FormatJsAnyArrayBindingPatternElement { + fn format( + node: &JsAnyArrayBindingPatternElement, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyArrayBindingPatternElement::JsArrayHole(node) => { + formatted![formatter, [node.format()]] + } + JsAnyArrayBindingPatternElement::JsAnyBindingPattern(node) => { + formatted![formatter, [node.format()]] + } + JsAnyArrayBindingPatternElement::JsBindingPatternWithDefault(node) => { + formatted![formatter, [node.format()]] + } + JsAnyArrayBindingPatternElement::JsArrayBindingPatternRestElement(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/array_element.rs b/crates/rome_js_formatter/src/js/any/array_element.rs index 12a6002c0a1d..828a4a5fa7d4 100644 --- a/crates/rome_js_formatter/src/js/any/array_element.rs +++ b/crates/rome_js_formatter/src/js/any/array_element.rs @@ -1,13 +1,14 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyArrayElement; use crate::prelude::*; use rome_js_syntax::JsAnyArrayElement; -impl Format for JsAnyArrayElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyExpression(node) => node.format(formatter), - Self::JsSpread(node) => node.format(formatter), - Self::JsArrayHole(node) => node.format(formatter), +impl FormatRule for FormatJsAnyArrayElement { + fn format(node: &JsAnyArrayElement, formatter: &Formatter) -> FormatResult { + match node { + JsAnyArrayElement::JsAnyExpression(node) => formatted![formatter, [node.format()]], + JsAnyArrayElement::JsSpread(node) => formatted![formatter, [node.format()]], + JsAnyArrayElement::JsArrayHole(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/arrow_function_parameters.rs b/crates/rome_js_formatter/src/js/any/arrow_function_parameters.rs index c9bca7df1457..bf686b0932a0 100644 --- a/crates/rome_js_formatter/src/js/any/arrow_function_parameters.rs +++ b/crates/rome_js_formatter/src/js/any/arrow_function_parameters.rs @@ -1,12 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyArrowFunctionParameters; use crate::prelude::*; use rome_js_syntax::JsAnyArrowFunctionParameters; -impl Format for JsAnyArrowFunctionParameters { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsParameters(node) => node.format(formatter), - Self::JsAnyBinding(node) => node.format(formatter), +impl FormatRule for FormatJsAnyArrowFunctionParameters { + fn format( + node: &JsAnyArrowFunctionParameters, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyArrowFunctionParameters::JsParameters(node) => { + formatted![formatter, [node.format()]] + } + JsAnyArrowFunctionParameters::JsAnyBinding(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/assignment.rs b/crates/rome_js_formatter/src/js/any/assignment.rs index 387bd537e001..19b61443301b 100644 --- a/crates/rome_js_formatter/src/js/any/assignment.rs +++ b/crates/rome_js_formatter/src/js/any/assignment.rs @@ -1,18 +1,29 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyAssignment; use crate::prelude::*; use rome_js_syntax::JsAnyAssignment; -impl Format for JsAnyAssignment { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsIdentifierAssignment(node) => node.format(formatter), - Self::JsStaticMemberAssignment(node) => node.format(formatter), - Self::JsComputedMemberAssignment(node) => node.format(formatter), - Self::JsParenthesizedAssignment(node) => node.format(formatter), - Self::TsNonNullAssertionAssignment(node) => node.format(formatter), - Self::TsAsAssignment(node) => node.format(formatter), - Self::TsTypeAssertionAssignment(node) => node.format(formatter), - Self::JsUnknownAssignment(node) => node.format(formatter), +impl FormatRule for FormatJsAnyAssignment { + fn format(node: &JsAnyAssignment, formatter: &Formatter) -> FormatResult { + match node { + JsAnyAssignment::JsIdentifierAssignment(node) => formatted![formatter, [node.format()]], + JsAnyAssignment::JsStaticMemberAssignment(node) => { + formatted![formatter, [node.format()]] + } + JsAnyAssignment::JsComputedMemberAssignment(node) => { + formatted![formatter, [node.format()]] + } + JsAnyAssignment::JsParenthesizedAssignment(node) => { + formatted![formatter, [node.format()]] + } + JsAnyAssignment::TsNonNullAssertionAssignment(node) => { + formatted![formatter, [node.format()]] + } + JsAnyAssignment::TsAsAssignment(node) => formatted![formatter, [node.format()]], + JsAnyAssignment::TsTypeAssertionAssignment(node) => { + formatted![formatter, [node.format()]] + } + JsAnyAssignment::JsUnknownAssignment(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/assignment_pattern.rs b/crates/rome_js_formatter/src/js/any/assignment_pattern.rs index 43d240a3e919..e5f264c34a85 100644 --- a/crates/rome_js_formatter/src/js/any/assignment_pattern.rs +++ b/crates/rome_js_formatter/src/js/any/assignment_pattern.rs @@ -1,13 +1,18 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyAssignmentPattern; use crate::prelude::*; use rome_js_syntax::JsAnyAssignmentPattern; -impl Format for JsAnyAssignmentPattern { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyAssignment(node) => node.format(formatter), - Self::JsArrayAssignmentPattern(node) => node.format(formatter), - Self::JsObjectAssignmentPattern(node) => node.format(formatter), +impl FormatRule for FormatJsAnyAssignmentPattern { + fn format(node: &JsAnyAssignmentPattern, formatter: &Formatter) -> FormatResult { + match node { + JsAnyAssignmentPattern::JsAnyAssignment(node) => formatted![formatter, [node.format()]], + JsAnyAssignmentPattern::JsArrayAssignmentPattern(node) => { + formatted![formatter, [node.format()]] + } + JsAnyAssignmentPattern::JsObjectAssignmentPattern(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/binding.rs b/crates/rome_js_formatter/src/js/any/binding.rs index 218fda5771b3..6835aa751e5d 100644 --- a/crates/rome_js_formatter/src/js/any/binding.rs +++ b/crates/rome_js_formatter/src/js/any/binding.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyBinding; use crate::prelude::*; use rome_js_syntax::JsAnyBinding; -impl Format for JsAnyBinding { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsIdentifierBinding(node) => node.format(formatter), - Self::JsUnknownBinding(node) => node.format(formatter), +impl FormatRule for FormatJsAnyBinding { + fn format(node: &JsAnyBinding, formatter: &Formatter) -> FormatResult { + match node { + JsAnyBinding::JsIdentifierBinding(node) => formatted![formatter, [node.format()]], + JsAnyBinding::JsUnknownBinding(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/binding_pattern.rs b/crates/rome_js_formatter/src/js/any/binding_pattern.rs index a9bc8bbc6043..9af47b42844f 100644 --- a/crates/rome_js_formatter/src/js/any/binding_pattern.rs +++ b/crates/rome_js_formatter/src/js/any/binding_pattern.rs @@ -1,13 +1,18 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyBindingPattern; use crate::prelude::*; use rome_js_syntax::JsAnyBindingPattern; -impl Format for JsAnyBindingPattern { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyBinding(node) => node.format(formatter), - Self::JsArrayBindingPattern(node) => node.format(formatter), - Self::JsObjectBindingPattern(node) => node.format(formatter), +impl FormatRule for FormatJsAnyBindingPattern { + fn format(node: &JsAnyBindingPattern, formatter: &Formatter) -> FormatResult { + match node { + JsAnyBindingPattern::JsAnyBinding(node) => formatted![formatter, [node.format()]], + JsAnyBindingPattern::JsArrayBindingPattern(node) => { + formatted![formatter, [node.format()]] + } + JsAnyBindingPattern::JsObjectBindingPattern(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/call_argument.rs b/crates/rome_js_formatter/src/js/any/call_argument.rs index edacbe715fa3..9b897c9ecc54 100644 --- a/crates/rome_js_formatter/src/js/any/call_argument.rs +++ b/crates/rome_js_formatter/src/js/any/call_argument.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyCallArgument; use crate::prelude::*; use rome_js_syntax::JsAnyCallArgument; -impl Format for JsAnyCallArgument { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyExpression(node) => node.format(formatter), - Self::JsSpread(node) => node.format(formatter), +impl FormatRule for FormatJsAnyCallArgument { + fn format(node: &JsAnyCallArgument, formatter: &Formatter) -> FormatResult { + match node { + JsAnyCallArgument::JsAnyExpression(node) => formatted![formatter, [node.format()]], + JsAnyCallArgument::JsSpread(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/class.rs b/crates/rome_js_formatter/src/js/any/class.rs index 26649d31e5fb..b80e2c47f3f6 100644 --- a/crates/rome_js_formatter/src/js/any/class.rs +++ b/crates/rome_js_formatter/src/js/any/class.rs @@ -1,46 +1,48 @@ -use crate::format_extensions::FormatOptional; -use crate::{ - formatted, join_elements_hard_line, space_token, FormatElement, Formatter, JsFormatter, -}; -use crate::{hard_group_elements, Format}; -use rome_formatter::FormatResult; +use crate::generated::FormatJsAnyClass; +use crate::prelude::*; use rome_js_syntax::JsAnyClass; use rome_rowan::AstNode; -impl Format for JsAnyClass { - fn format(&self, formatter: &Formatter) -> FormatResult { - let abstract_token = self.abstract_token(); - let id = self.id(); - let extends = self.extends_clause(); - let implements_clause = self.implements_clause(); +impl FormatRule for FormatJsAnyClass { + fn format(node: &JsAnyClass, formatter: &Formatter) -> FormatResult { + let abstract_token = node.abstract_token(); + let id = node.id(); + let extends = node.extends_clause(); + let implements_clause = node.implements_clause(); - let implements_clause = implements_clause.with_or_empty(|implements_clause| { - formatted![formatter, space_token(), implements_clause] + let format = implements_clause.format(); + + let implements_clause = format.with_or_empty(|implements_clause| { + formatted![formatter, [space_token(), implements_clause]] }); Ok(hard_group_elements(formatted![ formatter, - abstract_token.with_or_empty(|token| formatted![formatter, token, space_token()]), - self.class_token().format(formatter)?, - id.with_or_empty(|id| formatted![formatter, space_token(), id]), - self.type_parameters(), - extends.with_or_empty(|extends_clause| formatted![ - formatter, + [ + abstract_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + node.class_token().format(), + id.format() + .with_or_empty(|id| formatted![formatter, [space_token(), id]]), + node.type_parameters().format(), + extends.format().with_or_empty(|extends_clause| formatted![ + formatter, + [space_token(), extends_clause] + ]), + implements_clause, space_token(), - extends_clause - ]), - implements_clause, - space_token(), - formatter.format_delimited_block_indent( - &self.l_curly_token()?, - join_elements_hard_line( - self.members() - .into_iter() - .map(|node| node.syntax().clone()) - .zip(formatter.format_all(self.members())?) - ), - &self.r_curly_token()? - )? + formatter.format_delimited_block_indent( + &node.l_curly_token()?, + join_elements_hard_line( + node.members() + .into_iter() + .map(|node| node.syntax().clone()) + .zip(formatter.format_all(node.members().iter().formatted())?) + ), + &node.r_curly_token()? + )? + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/any/class_member.rs b/crates/rome_js_formatter/src/js/any/class_member.rs index cf5302610e80..6583ceb0d408 100644 --- a/crates/rome_js_formatter/src/js/any/class_member.rs +++ b/crates/rome_js_formatter/src/js/any/class_member.rs @@ -1,24 +1,41 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyClassMember; use crate::prelude::*; use rome_js_syntax::JsAnyClassMember; -impl Format for JsAnyClassMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsConstructorClassMember(node) => node.format(formatter), - Self::JsStaticInitializationBlockClassMember(node) => node.format(formatter), - Self::JsPropertyClassMember(node) => node.format(formatter), - Self::JsMethodClassMember(node) => node.format(formatter), - Self::JsGetterClassMember(node) => node.format(formatter), - Self::JsSetterClassMember(node) => node.format(formatter), - Self::TsConstructorSignatureClassMember(node) => node.format(formatter), - Self::TsPropertySignatureClassMember(node) => node.format(formatter), - Self::TsMethodSignatureClassMember(node) => node.format(formatter), - Self::TsGetterSignatureClassMember(node) => node.format(formatter), - Self::TsSetterSignatureClassMember(node) => node.format(formatter), - Self::TsIndexSignatureClassMember(node) => node.format(formatter), - Self::JsEmptyClassMember(node) => node.format(formatter), - Self::JsUnknownMember(node) => node.format(formatter), +impl FormatRule for FormatJsAnyClassMember { + fn format(node: &JsAnyClassMember, formatter: &Formatter) -> FormatResult { + match node { + JsAnyClassMember::JsConstructorClassMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMember::JsStaticInitializationBlockClassMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMember::JsPropertyClassMember(node) => formatted![formatter, [node.format()]], + JsAnyClassMember::JsMethodClassMember(node) => formatted![formatter, [node.format()]], + JsAnyClassMember::JsGetterClassMember(node) => formatted![formatter, [node.format()]], + JsAnyClassMember::JsSetterClassMember(node) => formatted![formatter, [node.format()]], + JsAnyClassMember::TsConstructorSignatureClassMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMember::TsPropertySignatureClassMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMember::TsMethodSignatureClassMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMember::TsGetterSignatureClassMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMember::TsSetterSignatureClassMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMember::TsIndexSignatureClassMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMember::JsEmptyClassMember(node) => formatted![formatter, [node.format()]], + JsAnyClassMember::JsUnknownMember(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/class_member_name.rs b/crates/rome_js_formatter/src/js/any/class_member_name.rs index 394b457f97aa..f2cc312feca1 100644 --- a/crates/rome_js_formatter/src/js/any/class_member_name.rs +++ b/crates/rome_js_formatter/src/js/any/class_member_name.rs @@ -1,13 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyClassMemberName; use crate::prelude::*; use rome_js_syntax::JsAnyClassMemberName; -impl Format for JsAnyClassMemberName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsLiteralMemberName(node) => node.format(formatter), - Self::JsComputedMemberName(node) => node.format(formatter), - Self::JsPrivateClassMemberName(node) => node.format(formatter), +impl FormatRule for FormatJsAnyClassMemberName { + fn format(node: &JsAnyClassMemberName, formatter: &Formatter) -> FormatResult { + match node { + JsAnyClassMemberName::JsLiteralMemberName(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMemberName::JsComputedMemberName(node) => { + formatted![formatter, [node.format()]] + } + JsAnyClassMemberName::JsPrivateClassMemberName(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/constructor_parameter.rs b/crates/rome_js_formatter/src/js/any/constructor_parameter.rs index 60cddf2e799b..b56ebe3cd2cd 100644 --- a/crates/rome_js_formatter/src/js/any/constructor_parameter.rs +++ b/crates/rome_js_formatter/src/js/any/constructor_parameter.rs @@ -1,13 +1,23 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyConstructorParameter; use crate::prelude::*; use rome_js_syntax::JsAnyConstructorParameter; -impl Format for JsAnyConstructorParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyFormalParameter(node) => node.format(formatter), - Self::JsRestParameter(node) => node.format(formatter), - Self::TsPropertyParameter(node) => node.format(formatter), +impl FormatRule for FormatJsAnyConstructorParameter { + fn format( + node: &JsAnyConstructorParameter, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyConstructorParameter::JsAnyFormalParameter(node) => { + formatted![formatter, [node.format()]] + } + JsAnyConstructorParameter::JsRestParameter(node) => { + formatted![formatter, [node.format()]] + } + JsAnyConstructorParameter::TsPropertyParameter(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/declaration.rs b/crates/rome_js_formatter/src/js/any/declaration.rs index 80a316f8c3f5..0f70a409ef3e 100644 --- a/crates/rome_js_formatter/src/js/any/declaration.rs +++ b/crates/rome_js_formatter/src/js/any/declaration.rs @@ -1,21 +1,32 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyDeclaration; use crate::prelude::*; use rome_js_syntax::JsAnyDeclaration; -impl Format for JsAnyDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsClassDeclaration(node) => node.format(formatter), - Self::JsFunctionDeclaration(node) => node.format(formatter), - Self::JsVariableDeclaration(node) => node.format(formatter), - Self::TsEnumDeclaration(node) => node.format(formatter), - Self::TsTypeAliasDeclaration(node) => node.format(formatter), - Self::TsInterfaceDeclaration(node) => node.format(formatter), - Self::TsDeclareFunctionDeclaration(node) => node.format(formatter), - Self::TsModuleDeclaration(node) => node.format(formatter), - Self::TsExternalModuleDeclaration(node) => node.format(formatter), - Self::TsGlobalDeclaration(node) => node.format(formatter), - Self::TsImportEqualsDeclaration(node) => node.format(formatter), +impl FormatRule for FormatJsAnyDeclaration { + fn format(node: &JsAnyDeclaration, formatter: &Formatter) -> FormatResult { + match node { + JsAnyDeclaration::JsClassDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyDeclaration::JsFunctionDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyDeclaration::JsVariableDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyDeclaration::TsEnumDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyDeclaration::TsTypeAliasDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclaration::TsInterfaceDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclaration::TsDeclareFunctionDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclaration::TsModuleDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyDeclaration::TsExternalModuleDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclaration::TsGlobalDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyDeclaration::TsImportEqualsDeclaration(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/declaration_clause.rs b/crates/rome_js_formatter/src/js/any/declaration_clause.rs index f9195bfcd1f7..28513ec54b73 100644 --- a/crates/rome_js_formatter/src/js/any/declaration_clause.rs +++ b/crates/rome_js_formatter/src/js/any/declaration_clause.rs @@ -1,21 +1,44 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyDeclarationClause; use crate::prelude::*; use rome_js_syntax::JsAnyDeclarationClause; -impl Format for JsAnyDeclarationClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsClassDeclaration(node) => node.format(formatter), - Self::JsFunctionDeclaration(node) => node.format(formatter), - Self::JsVariableDeclarationClause(node) => node.format(formatter), - Self::TsEnumDeclaration(node) => node.format(formatter), - Self::TsTypeAliasDeclaration(node) => node.format(formatter), - Self::TsInterfaceDeclaration(node) => node.format(formatter), - Self::TsDeclareFunctionDeclaration(node) => node.format(formatter), - Self::TsModuleDeclaration(node) => node.format(formatter), - Self::TsExternalModuleDeclaration(node) => node.format(formatter), - Self::TsGlobalDeclaration(node) => node.format(formatter), - Self::TsImportEqualsDeclaration(node) => node.format(formatter), +impl FormatRule for FormatJsAnyDeclarationClause { + fn format(node: &JsAnyDeclarationClause, formatter: &Formatter) -> FormatResult { + match node { + JsAnyDeclarationClause::JsClassDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::JsFunctionDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::JsVariableDeclarationClause(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::TsEnumDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::TsTypeAliasDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::TsInterfaceDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::TsDeclareFunctionDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::TsModuleDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::TsExternalModuleDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::TsGlobalDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyDeclarationClause::TsImportEqualsDeclaration(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/export_clause.rs b/crates/rome_js_formatter/src/js/any/export_clause.rs index a5e431bee8e1..197874fbea50 100644 --- a/crates/rome_js_formatter/src/js/any/export_clause.rs +++ b/crates/rome_js_formatter/src/js/any/export_clause.rs @@ -1,19 +1,34 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyExportClause; use crate::prelude::*; use rome_js_syntax::JsAnyExportClause; -impl Format for JsAnyExportClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsExportDefaultDeclarationClause(node) => node.format(formatter), - Self::JsExportDefaultExpressionClause(node) => node.format(formatter), - Self::JsExportNamedClause(node) => node.format(formatter), - Self::JsExportFromClause(node) => node.format(formatter), - Self::JsExportNamedFromClause(node) => node.format(formatter), - Self::JsAnyDeclarationClause(node) => node.format(formatter), - Self::TsExportAsNamespaceClause(node) => node.format(formatter), - Self::TsExportAssignmentClause(node) => node.format(formatter), - Self::TsExportDeclareClause(node) => node.format(formatter), +impl FormatRule for FormatJsAnyExportClause { + fn format(node: &JsAnyExportClause, formatter: &Formatter) -> FormatResult { + match node { + JsAnyExportClause::JsExportDefaultDeclarationClause(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportClause::JsExportDefaultExpressionClause(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportClause::JsExportNamedClause(node) => formatted![formatter, [node.format()]], + JsAnyExportClause::JsExportFromClause(node) => formatted![formatter, [node.format()]], + JsAnyExportClause::JsExportNamedFromClause(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportClause::JsAnyDeclarationClause(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportClause::TsExportAsNamespaceClause(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportClause::TsExportAssignmentClause(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportClause::TsExportDeclareClause(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/export_default_declaration.rs b/crates/rome_js_formatter/src/js/any/export_default_declaration.rs index e835819ff21a..aa3788b474ba 100644 --- a/crates/rome_js_formatter/src/js/any/export_default_declaration.rs +++ b/crates/rome_js_formatter/src/js/any/export_default_declaration.rs @@ -1,14 +1,26 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyExportDefaultDeclaration; use crate::prelude::*; use rome_js_syntax::JsAnyExportDefaultDeclaration; -impl Format for JsAnyExportDefaultDeclaration { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsClassExportDefaultDeclaration(node) => node.format(formatter), - Self::JsFunctionExportDefaultDeclaration(node) => node.format(formatter), - Self::TsDeclareFunctionDeclaration(node) => node.format(formatter), - Self::TsInterfaceDeclaration(node) => node.format(formatter), +impl FormatRule for FormatJsAnyExportDefaultDeclaration { + fn format( + node: &JsAnyExportDefaultDeclaration, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyExportDefaultDeclaration::JsClassExportDefaultDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportDefaultDeclaration::JsFunctionExportDefaultDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportDefaultDeclaration::TsDeclareFunctionDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportDefaultDeclaration::TsInterfaceDeclaration(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/export_named_specifier.rs b/crates/rome_js_formatter/src/js/any/export_named_specifier.rs index 93c3132b6fd6..5d34c031438f 100644 --- a/crates/rome_js_formatter/src/js/any/export_named_specifier.rs +++ b/crates/rome_js_formatter/src/js/any/export_named_specifier.rs @@ -1,12 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyExportNamedSpecifier; use crate::prelude::*; use rome_js_syntax::JsAnyExportNamedSpecifier; -impl Format for JsAnyExportNamedSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsExportNamedShorthandSpecifier(node) => node.format(formatter), - Self::JsExportNamedSpecifier(node) => node.format(formatter), +impl FormatRule for FormatJsAnyExportNamedSpecifier { + fn format( + node: &JsAnyExportNamedSpecifier, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyExportNamedSpecifier::JsExportNamedShorthandSpecifier(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExportNamedSpecifier::JsExportNamedSpecifier(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/expression.rs b/crates/rome_js_formatter/src/js/any/expression.rs index 9f213ca93c01..d1be773c4539 100644 --- a/crates/rome_js_formatter/src/js/any/expression.rs +++ b/crates/rome_js_formatter/src/js/any/expression.rs @@ -1,45 +1,60 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyExpression; use crate::prelude::*; use rome_js_syntax::JsAnyExpression; -impl Format for JsAnyExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyLiteralExpression(node) => node.format(formatter), - Self::ImportMeta(node) => node.format(formatter), - Self::JsArrayExpression(node) => node.format(formatter), - Self::JsArrowFunctionExpression(node) => node.format(formatter), - Self::JsAssignmentExpression(node) => node.format(formatter), - Self::JsAwaitExpression(node) => node.format(formatter), - Self::JsBinaryExpression(node) => node.format(formatter), - Self::JsCallExpression(node) => node.format(formatter), - Self::JsClassExpression(node) => node.format(formatter), - Self::JsComputedMemberExpression(node) => node.format(formatter), - Self::JsConditionalExpression(node) => node.format(formatter), - Self::JsFunctionExpression(node) => node.format(formatter), - Self::JsIdentifierExpression(node) => node.format(formatter), - Self::JsImportCallExpression(node) => node.format(formatter), - Self::JsInExpression(node) => node.format(formatter), - Self::JsInstanceofExpression(node) => node.format(formatter), - Self::JsLogicalExpression(node) => node.format(formatter), - Self::JsNewExpression(node) => node.format(formatter), - Self::JsObjectExpression(node) => node.format(formatter), - Self::JsParenthesizedExpression(node) => node.format(formatter), - Self::JsPostUpdateExpression(node) => node.format(formatter), - Self::JsPreUpdateExpression(node) => node.format(formatter), - Self::JsSequenceExpression(node) => node.format(formatter), - Self::JsStaticMemberExpression(node) => node.format(formatter), - Self::JsSuperExpression(node) => node.format(formatter), - Self::JsThisExpression(node) => node.format(formatter), - Self::JsUnaryExpression(node) => node.format(formatter), - Self::JsUnknownExpression(node) => node.format(formatter), - Self::JsYieldExpression(node) => node.format(formatter), - Self::NewTarget(node) => node.format(formatter), - Self::JsTemplate(node) => node.format(formatter), - Self::TsTypeAssertionExpression(node) => node.format(formatter), - Self::TsAsExpression(node) => node.format(formatter), - Self::TsNonNullAssertionExpression(node) => node.format(formatter), - Self::JsxTagExpression(node) => node.format(formatter), +impl FormatRule for FormatJsAnyExpression { + fn format(node: &JsAnyExpression, formatter: &Formatter) -> FormatResult { + match node { + JsAnyExpression::JsAnyLiteralExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::ImportMeta(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsArrayExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsArrowFunctionExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExpression::JsAssignmentExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsAwaitExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsBinaryExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsCallExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsClassExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsComputedMemberExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExpression::JsConditionalExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExpression::JsFunctionExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsIdentifierExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsImportCallExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsInExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsInstanceofExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsLogicalExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsNewExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsObjectExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsParenthesizedExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExpression::JsPostUpdateExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsPreUpdateExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsSequenceExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsStaticMemberExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExpression::JsSuperExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsThisExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsUnaryExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsUnknownExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsYieldExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::NewTarget(node) => formatted![formatter, [node.format()]], + JsAnyExpression::JsTemplate(node) => formatted![formatter, [node.format()]], + JsAnyExpression::TsTypeAssertionExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExpression::TsAsExpression(node) => formatted![formatter, [node.format()]], + JsAnyExpression::TsNonNullAssertionExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyExpression::JsxTagExpression(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/for_in_or_of_initializer.rs b/crates/rome_js_formatter/src/js/any/for_in_or_of_initializer.rs index 251ba9ac4ab6..d624add8c123 100644 --- a/crates/rome_js_formatter/src/js/any/for_in_or_of_initializer.rs +++ b/crates/rome_js_formatter/src/js/any/for_in_or_of_initializer.rs @@ -1,12 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyForInOrOfInitializer; use crate::prelude::*; use rome_js_syntax::JsAnyForInOrOfInitializer; -impl Format for JsAnyForInOrOfInitializer { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyAssignmentPattern(node) => node.format(formatter), - Self::JsForVariableDeclaration(node) => node.format(formatter), +impl FormatRule for FormatJsAnyForInOrOfInitializer { + fn format( + node: &JsAnyForInOrOfInitializer, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyForInOrOfInitializer::JsAnyAssignmentPattern(node) => { + formatted![formatter, [node.format()]] + } + JsAnyForInOrOfInitializer::JsForVariableDeclaration(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/for_initializer.rs b/crates/rome_js_formatter/src/js/any/for_initializer.rs index d6847362b3ff..be2c3df14e35 100644 --- a/crates/rome_js_formatter/src/js/any/for_initializer.rs +++ b/crates/rome_js_formatter/src/js/any/for_initializer.rs @@ -1,12 +1,15 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyForInitializer; use crate::prelude::*; use rome_js_syntax::JsAnyForInitializer; -impl Format for JsAnyForInitializer { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsVariableDeclaration(node) => node.format(formatter), - Self::JsAnyExpression(node) => node.format(formatter), +impl FormatRule for FormatJsAnyForInitializer { + fn format(node: &JsAnyForInitializer, formatter: &Formatter) -> FormatResult { + match node { + JsAnyForInitializer::JsVariableDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyForInitializer::JsAnyExpression(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/formal_parameter.rs b/crates/rome_js_formatter/src/js/any/formal_parameter.rs index ec463f3bbad9..f4d401ed430f 100644 --- a/crates/rome_js_formatter/src/js/any/formal_parameter.rs +++ b/crates/rome_js_formatter/src/js/any/formal_parameter.rs @@ -1,12 +1,15 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyFormalParameter; use crate::prelude::*; use rome_js_syntax::JsAnyFormalParameter; -impl Format for JsAnyFormalParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsFormalParameter(node) => node.format(formatter), - Self::JsUnknownParameter(node) => node.format(formatter), +impl FormatRule for FormatJsAnyFormalParameter { + fn format(node: &JsAnyFormalParameter, formatter: &Formatter) -> FormatResult { + match node { + JsAnyFormalParameter::JsFormalParameter(node) => formatted![formatter, [node.format()]], + JsAnyFormalParameter::JsUnknownParameter(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/function.rs b/crates/rome_js_formatter/src/js/any/function.rs index d1594f1e6dc4..872fe71b34d9 100644 --- a/crates/rome_js_formatter/src/js/any/function.rs +++ b/crates/rome_js_formatter/src/js/any/function.rs @@ -1,55 +1,60 @@ -use crate::format_extensions::FormatOptional; +use crate::prelude::*; use crate::utils::is_simple_expression; -use crate::{ - concat_elements, empty_element, formatted, group_elements, hard_group_elements, - if_group_breaks, soft_block_indent, soft_line_indent_or_space, space_token, token, Format, - FormatElement, FormatNode, Formatter, -}; -use rome_formatter::FormatResult; +use crate::generated::FormatJsAnyFunction; use rome_js_syntax::{ JsAnyArrowFunctionParameters, JsAnyExpression, JsAnyFunction, JsAnyFunctionBody, }; -impl Format for JsAnyFunction { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsAnyFunction { + fn format(node: &JsAnyFunction, formatter: &Formatter) -> FormatResult { let mut tokens = vec![]; tokens.push(formatted![ formatter, - self.async_token() - .with_or_empty(|token| { formatted![formatter, token, space_token()] }) + [node + .async_token() + .format() + .with_or_empty(|token| { formatted![formatter, [token, space_token()]] })] ]?); - tokens.push(self.function_token().format(formatter)?); - tokens.push(self.star_token().format(formatter)?); + tokens.push(formatted![formatter, [node.function_token().format()]]?); + tokens.push(formatted![formatter, [node.star_token().format()]]?); - tokens.push(match self { + tokens.push(match node { JsAnyFunction::JsArrowFunctionExpression(_) => empty_element(), _ => formatted![ formatter, - self.id() - .with_or(|id| formatted![formatter, space_token(), id], space_token,) + [node + .id() + .format() + .with_or(|id| formatted![formatter, [space_token(), id]], space_token,)] ]?, }); - tokens.push(self.type_parameters().format(formatter)?); + tokens.push(formatted![formatter, [node.type_parameters().format()]]?); - tokens.push(match self.parameters()? { + tokens.push(match node.parameters()? { JsAnyArrowFunctionParameters::JsAnyBinding(binding) => group_elements(formatted![ formatter, - token("("), - soft_block_indent(formatted![ - formatter, - binding.format(formatter)?, - if_group_breaks(token(",")), - ]?), - token(")"), + [ + token("("), + soft_block_indent(formatted![ + formatter, + [binding.format(), if_group_breaks(token(",")),] + ]?), + token(")"), + ] ]?), - JsAnyArrowFunctionParameters::JsParameters(params) => params.format_node(formatter)?, + JsAnyArrowFunctionParameters::JsParameters(params) => { + formatted![formatter, [params.format()]]? + } }); - tokens.push(self.return_type_annotation().format(formatter)?); + tokens.push(formatted![ + formatter, + [node.return_type_annotation().format()] + ]?); tokens.push(space_token()); @@ -66,12 +71,12 @@ impl Format for JsAnyFunction { // The line break for `a + b` is not necessary // let mut body_group = vec![]; - if let JsAnyFunction::JsArrowFunctionExpression(arrow) = self { - body_group.push(arrow.fat_arrow_token().format(formatter)?); + if let JsAnyFunction::JsArrowFunctionExpression(arrow) = node { + body_group.push(formatted![formatter, [arrow.fat_arrow_token().format()]]?); body_group.push(space_token()); } - let body = self.body()?; + let body = node.body()?; // With arrays, arrow functions and objects, they have a natural line breaking strategy: // Arrays and objects become blocks: // @@ -102,9 +107,12 @@ impl Format for JsAnyFunction { }; if body_has_soft_line_break { - body_group.push(self.body().format(formatter)?); + body_group.push(formatted![formatter, [node.body().format()]]?); } else { - body_group.push(soft_line_indent_or_space(self.body().format(formatter)?)); + body_group.push(soft_line_indent_or_space(formatted![ + formatter, + [node.body().format()] + ]?)); } tokens.push(group_elements(concat_elements(body_group))); diff --git a/crates/rome_js_formatter/src/js/any/function_body.rs b/crates/rome_js_formatter/src/js/any/function_body.rs index ce3047074e2b..f5c001adba85 100644 --- a/crates/rome_js_formatter/src/js/any/function_body.rs +++ b/crates/rome_js_formatter/src/js/any/function_body.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyFunctionBody; use crate::prelude::*; use rome_js_syntax::JsAnyFunctionBody; -impl Format for JsAnyFunctionBody { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyExpression(node) => node.format(formatter), - Self::JsFunctionBody(node) => node.format(formatter), +impl FormatRule for FormatJsAnyFunctionBody { + fn format(node: &JsAnyFunctionBody, formatter: &Formatter) -> FormatResult { + match node { + JsAnyFunctionBody::JsAnyExpression(node) => formatted![formatter, [node.format()]], + JsAnyFunctionBody::JsFunctionBody(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/import_assertion_entry.rs b/crates/rome_js_formatter/src/js/any/import_assertion_entry.rs index 0333ef115fad..8e15f1abf91f 100644 --- a/crates/rome_js_formatter/src/js/any/import_assertion_entry.rs +++ b/crates/rome_js_formatter/src/js/any/import_assertion_entry.rs @@ -1,12 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyImportAssertionEntry; use crate::prelude::*; use rome_js_syntax::JsAnyImportAssertionEntry; -impl Format for JsAnyImportAssertionEntry { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsImportAssertionEntry(node) => node.format(formatter), - Self::JsUnknownImportAssertionEntry(node) => node.format(formatter), +impl FormatRule for FormatJsAnyImportAssertionEntry { + fn format( + node: &JsAnyImportAssertionEntry, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyImportAssertionEntry::JsImportAssertionEntry(node) => { + formatted![formatter, [node.format()]] + } + JsAnyImportAssertionEntry::JsUnknownImportAssertionEntry(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/import_clause.rs b/crates/rome_js_formatter/src/js/any/import_clause.rs index e46e62cf6a67..440c3a5d52c5 100644 --- a/crates/rome_js_formatter/src/js/any/import_clause.rs +++ b/crates/rome_js_formatter/src/js/any/import_clause.rs @@ -1,14 +1,19 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyImportClause; use crate::prelude::*; use rome_js_syntax::JsAnyImportClause; -impl Format for JsAnyImportClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsImportBareClause(node) => node.format(formatter), - Self::JsImportNamedClause(node) => node.format(formatter), - Self::JsImportDefaultClause(node) => node.format(formatter), - Self::JsImportNamespaceClause(node) => node.format(formatter), +impl FormatRule for FormatJsAnyImportClause { + fn format(node: &JsAnyImportClause, formatter: &Formatter) -> FormatResult { + match node { + JsAnyImportClause::JsImportBareClause(node) => formatted![formatter, [node.format()]], + JsAnyImportClause::JsImportNamedClause(node) => formatted![formatter, [node.format()]], + JsAnyImportClause::JsImportDefaultClause(node) => { + formatted![formatter, [node.format()]] + } + JsAnyImportClause::JsImportNamespaceClause(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/in_property.rs b/crates/rome_js_formatter/src/js/any/in_property.rs index dd24c64e399b..e404f5489179 100644 --- a/crates/rome_js_formatter/src/js/any/in_property.rs +++ b/crates/rome_js_formatter/src/js/any/in_property.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyInProperty; use crate::prelude::*; use rome_js_syntax::JsAnyInProperty; -impl Format for JsAnyInProperty { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsPrivateName(node) => node.format(formatter), - Self::JsAnyExpression(node) => node.format(formatter), +impl FormatRule for FormatJsAnyInProperty { + fn format(node: &JsAnyInProperty, formatter: &Formatter) -> FormatResult { + match node { + JsAnyInProperty::JsPrivateName(node) => formatted![formatter, [node.format()]], + JsAnyInProperty::JsAnyExpression(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/literal_expression.rs b/crates/rome_js_formatter/src/js/any/literal_expression.rs index ab95e9587fa2..4f51136a6feb 100644 --- a/crates/rome_js_formatter/src/js/any/literal_expression.rs +++ b/crates/rome_js_formatter/src/js/any/literal_expression.rs @@ -1,16 +1,29 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyLiteralExpression; use crate::prelude::*; use rome_js_syntax::JsAnyLiteralExpression; -impl Format for JsAnyLiteralExpression { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsStringLiteralExpression(node) => node.format(formatter), - Self::JsNumberLiteralExpression(node) => node.format(formatter), - Self::JsBigIntLiteralExpression(node) => node.format(formatter), - Self::JsBooleanLiteralExpression(node) => node.format(formatter), - Self::JsNullLiteralExpression(node) => node.format(formatter), - Self::JsRegexLiteralExpression(node) => node.format(formatter), +impl FormatRule for FormatJsAnyLiteralExpression { + fn format(node: &JsAnyLiteralExpression, formatter: &Formatter) -> FormatResult { + match node { + JsAnyLiteralExpression::JsStringLiteralExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyLiteralExpression::JsNumberLiteralExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyLiteralExpression::JsBigIntLiteralExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyLiteralExpression::JsBooleanLiteralExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyLiteralExpression::JsNullLiteralExpression(node) => { + formatted![formatter, [node.format()]] + } + JsAnyLiteralExpression::JsRegexLiteralExpression(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/method_modifier.rs b/crates/rome_js_formatter/src/js/any/method_modifier.rs index 1923cc8c2ed5..61624e1b6fb2 100644 --- a/crates/rome_js_formatter/src/js/any/method_modifier.rs +++ b/crates/rome_js_formatter/src/js/any/method_modifier.rs @@ -1,13 +1,16 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyMethodModifier; use crate::prelude::*; use rome_js_syntax::JsAnyMethodModifier; -impl Format for JsAnyMethodModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsAccessibilityModifier(node) => node.format(formatter), - Self::JsStaticModifier(node) => node.format(formatter), - Self::TsOverrideModifier(node) => node.format(formatter), +impl FormatRule for FormatJsAnyMethodModifier { + fn format(node: &JsAnyMethodModifier, formatter: &Formatter) -> FormatResult { + match node { + JsAnyMethodModifier::TsAccessibilityModifier(node) => { + formatted![formatter, [node.format()]] + } + JsAnyMethodModifier::JsStaticModifier(node) => formatted![formatter, [node.format()]], + JsAnyMethodModifier::TsOverrideModifier(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/module_item.rs b/crates/rome_js_formatter/src/js/any/module_item.rs index d10038b07a45..4ca765bc6e1c 100644 --- a/crates/rome_js_formatter/src/js/any/module_item.rs +++ b/crates/rome_js_formatter/src/js/any/module_item.rs @@ -1,13 +1,14 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyModuleItem; use crate::prelude::*; use rome_js_syntax::JsAnyModuleItem; -impl Format for JsAnyModuleItem { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyStatement(node) => node.format(formatter), - Self::JsExport(node) => node.format(formatter), - Self::JsImport(node) => node.format(formatter), +impl FormatRule for FormatJsAnyModuleItem { + fn format(node: &JsAnyModuleItem, formatter: &Formatter) -> FormatResult { + match node { + JsAnyModuleItem::JsAnyStatement(node) => formatted![formatter, [node.format()]], + JsAnyModuleItem::JsExport(node) => formatted![formatter, [node.format()]], + JsAnyModuleItem::JsImport(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/name.rs b/crates/rome_js_formatter/src/js/any/name.rs index 5297780a1c86..110d9c2b9904 100644 --- a/crates/rome_js_formatter/src/js/any/name.rs +++ b/crates/rome_js_formatter/src/js/any/name.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyName; use crate::prelude::*; use rome_js_syntax::JsAnyName; -impl Format for JsAnyName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsName(node) => node.format(formatter), - Self::JsPrivateName(node) => node.format(formatter), +impl FormatRule for FormatJsAnyName { + fn format(node: &JsAnyName, formatter: &Formatter) -> FormatResult { + match node { + JsAnyName::JsName(node) => formatted![formatter, [node.format()]], + JsAnyName::JsPrivateName(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/named_import.rs b/crates/rome_js_formatter/src/js/any/named_import.rs index b278ca3b3b40..69b5add860f4 100644 --- a/crates/rome_js_formatter/src/js/any/named_import.rs +++ b/crates/rome_js_formatter/src/js/any/named_import.rs @@ -1,12 +1,17 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyNamedImport; use crate::prelude::*; use rome_js_syntax::JsAnyNamedImport; -impl Format for JsAnyNamedImport { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsNamedImportSpecifiers(node) => node.format(formatter), - Self::JsNamespaceImportSpecifier(node) => node.format(formatter), +impl FormatRule for FormatJsAnyNamedImport { + fn format(node: &JsAnyNamedImport, formatter: &Formatter) -> FormatResult { + match node { + JsAnyNamedImport::JsNamedImportSpecifiers(node) => { + formatted![formatter, [node.format()]] + } + JsAnyNamedImport::JsNamespaceImportSpecifier(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/named_import_specifier.rs b/crates/rome_js_formatter/src/js/any/named_import_specifier.rs index b1fc311dfc00..9bff6fff0d4f 100644 --- a/crates/rome_js_formatter/src/js/any/named_import_specifier.rs +++ b/crates/rome_js_formatter/src/js/any/named_import_specifier.rs @@ -1,13 +1,23 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyNamedImportSpecifier; use crate::prelude::*; use rome_js_syntax::JsAnyNamedImportSpecifier; -impl Format for JsAnyNamedImportSpecifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsShorthandNamedImportSpecifier(node) => node.format(formatter), - Self::JsNamedImportSpecifier(node) => node.format(formatter), - Self::JsUnknownNamedImportSpecifier(node) => node.format(formatter), +impl FormatRule for FormatJsAnyNamedImportSpecifier { + fn format( + node: &JsAnyNamedImportSpecifier, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyNamedImportSpecifier::JsShorthandNamedImportSpecifier(node) => { + formatted![formatter, [node.format()]] + } + JsAnyNamedImportSpecifier::JsNamedImportSpecifier(node) => { + formatted![formatter, [node.format()]] + } + JsAnyNamedImportSpecifier::JsUnknownNamedImportSpecifier(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/object_assignment_pattern_member.rs b/crates/rome_js_formatter/src/js/any/object_assignment_pattern_member.rs index b87bce6b5ba7..535a1a8bea0d 100644 --- a/crates/rome_js_formatter/src/js/any/object_assignment_pattern_member.rs +++ b/crates/rome_js_formatter/src/js/any/object_assignment_pattern_member.rs @@ -1,14 +1,26 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyObjectAssignmentPatternMember; use crate::prelude::*; use rome_js_syntax::JsAnyObjectAssignmentPatternMember; -impl Format for JsAnyObjectAssignmentPatternMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsObjectAssignmentPatternShorthandProperty(node) => node.format(formatter), - Self::JsObjectAssignmentPatternProperty(node) => node.format(formatter), - Self::JsObjectAssignmentPatternRest(node) => node.format(formatter), - Self::JsUnknownAssignment(node) => node.format(formatter), +impl FormatRule for FormatJsAnyObjectAssignmentPatternMember { + fn format( + node: &JsAnyObjectAssignmentPatternMember, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyObjectAssignmentPatternMember::JsObjectAssignmentPatternShorthandProperty( + node, + ) => formatted![formatter, [node.format()]], + JsAnyObjectAssignmentPatternMember::JsObjectAssignmentPatternProperty(node) => { + formatted![formatter, [node.format()]] + } + JsAnyObjectAssignmentPatternMember::JsObjectAssignmentPatternRest(node) => { + formatted![formatter, [node.format()]] + } + JsAnyObjectAssignmentPatternMember::JsUnknownAssignment(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/object_binding_pattern_member.rs b/crates/rome_js_formatter/src/js/any/object_binding_pattern_member.rs index 0bad0ea2db8e..908770af8542 100644 --- a/crates/rome_js_formatter/src/js/any/object_binding_pattern_member.rs +++ b/crates/rome_js_formatter/src/js/any/object_binding_pattern_member.rs @@ -1,15 +1,29 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyObjectBindingPatternMember; use crate::prelude::*; use rome_js_syntax::JsAnyObjectBindingPatternMember; -impl Format for JsAnyObjectBindingPatternMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsObjectBindingPatternProperty(node) => node.format(formatter), - Self::JsObjectBindingPatternRest(node) => node.format(formatter), - Self::JsObjectBindingPatternShorthandProperty(node) => node.format(formatter), - Self::JsIdentifierBinding(node) => node.format(formatter), - Self::JsUnknownBinding(node) => node.format(formatter), +impl FormatRule for FormatJsAnyObjectBindingPatternMember { + fn format( + node: &JsAnyObjectBindingPatternMember, + formatter: &Formatter, + ) -> FormatResult { + match node { + JsAnyObjectBindingPatternMember::JsObjectBindingPatternProperty(node) => { + formatted![formatter, [node.format()]] + } + JsAnyObjectBindingPatternMember::JsObjectBindingPatternRest(node) => { + formatted![formatter, [node.format()]] + } + JsAnyObjectBindingPatternMember::JsObjectBindingPatternShorthandProperty(node) => { + formatted![formatter, [node.format()]] + } + JsAnyObjectBindingPatternMember::JsIdentifierBinding(node) => { + formatted![formatter, [node.format()]] + } + JsAnyObjectBindingPatternMember::JsUnknownBinding(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/object_member.rs b/crates/rome_js_formatter/src/js/any/object_member.rs index 592d8018f509..751c95560201 100644 --- a/crates/rome_js_formatter/src/js/any/object_member.rs +++ b/crates/rome_js_formatter/src/js/any/object_member.rs @@ -1,17 +1,22 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyObjectMember; use crate::prelude::*; use rome_js_syntax::JsAnyObjectMember; -impl Format for JsAnyObjectMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsPropertyObjectMember(node) => node.format(formatter), - Self::JsMethodObjectMember(node) => node.format(formatter), - Self::JsGetterObjectMember(node) => node.format(formatter), - Self::JsSetterObjectMember(node) => node.format(formatter), - Self::JsShorthandPropertyObjectMember(node) => node.format(formatter), - Self::JsSpread(node) => node.format(formatter), - Self::JsUnknownMember(node) => node.format(formatter), +impl FormatRule for FormatJsAnyObjectMember { + fn format(node: &JsAnyObjectMember, formatter: &Formatter) -> FormatResult { + match node { + JsAnyObjectMember::JsPropertyObjectMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyObjectMember::JsMethodObjectMember(node) => formatted![formatter, [node.format()]], + JsAnyObjectMember::JsGetterObjectMember(node) => formatted![formatter, [node.format()]], + JsAnyObjectMember::JsSetterObjectMember(node) => formatted![formatter, [node.format()]], + JsAnyObjectMember::JsShorthandPropertyObjectMember(node) => { + formatted![formatter, [node.format()]] + } + JsAnyObjectMember::JsSpread(node) => formatted![formatter, [node.format()]], + JsAnyObjectMember::JsUnknownMember(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/object_member_name.rs b/crates/rome_js_formatter/src/js/any/object_member_name.rs index 318c8dfb80d5..9041fdca2972 100644 --- a/crates/rome_js_formatter/src/js/any/object_member_name.rs +++ b/crates/rome_js_formatter/src/js/any/object_member_name.rs @@ -1,12 +1,17 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyObjectMemberName; use crate::prelude::*; use rome_js_syntax::JsAnyObjectMemberName; -impl Format for JsAnyObjectMemberName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsLiteralMemberName(node) => node.format(formatter), - Self::JsComputedMemberName(node) => node.format(formatter), +impl FormatRule for FormatJsAnyObjectMemberName { + fn format(node: &JsAnyObjectMemberName, formatter: &Formatter) -> FormatResult { + match node { + JsAnyObjectMemberName::JsLiteralMemberName(node) => { + formatted![formatter, [node.format()]] + } + JsAnyObjectMemberName::JsComputedMemberName(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/parameter.rs b/crates/rome_js_formatter/src/js/any/parameter.rs index 83851a127007..170dfe9e3885 100644 --- a/crates/rome_js_formatter/src/js/any/parameter.rs +++ b/crates/rome_js_formatter/src/js/any/parameter.rs @@ -1,13 +1,14 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyParameter; use crate::prelude::*; use rome_js_syntax::JsAnyParameter; -impl Format for JsAnyParameter { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsAnyFormalParameter(node) => node.format(formatter), - Self::JsRestParameter(node) => node.format(formatter), - Self::TsThisParameter(node) => node.format(formatter), +impl FormatRule for FormatJsAnyParameter { + fn format(node: &JsAnyParameter, formatter: &Formatter) -> FormatResult { + match node { + JsAnyParameter::JsAnyFormalParameter(node) => formatted![formatter, [node.format()]], + JsAnyParameter::JsRestParameter(node) => formatted![formatter, [node.format()]], + JsAnyParameter::TsThisParameter(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/property_modifier.rs b/crates/rome_js_formatter/src/js/any/property_modifier.rs index 87be8beb3286..db3440298f32 100644 --- a/crates/rome_js_formatter/src/js/any/property_modifier.rs +++ b/crates/rome_js_formatter/src/js/any/property_modifier.rs @@ -1,14 +1,21 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyPropertyModifier; use crate::prelude::*; use rome_js_syntax::JsAnyPropertyModifier; -impl Format for JsAnyPropertyModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsAccessibilityModifier(node) => node.format(formatter), - Self::JsStaticModifier(node) => node.format(formatter), - Self::TsReadonlyModifier(node) => node.format(formatter), - Self::TsOverrideModifier(node) => node.format(formatter), +impl FormatRule for FormatJsAnyPropertyModifier { + fn format(node: &JsAnyPropertyModifier, formatter: &Formatter) -> FormatResult { + match node { + JsAnyPropertyModifier::TsAccessibilityModifier(node) => { + formatted![formatter, [node.format()]] + } + JsAnyPropertyModifier::JsStaticModifier(node) => formatted![formatter, [node.format()]], + JsAnyPropertyModifier::TsReadonlyModifier(node) => { + formatted![formatter, [node.format()]] + } + JsAnyPropertyModifier::TsOverrideModifier(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/root.rs b/crates/rome_js_formatter/src/js/any/root.rs index 1b91dd33d950..3da447aff9ba 100644 --- a/crates/rome_js_formatter/src/js/any/root.rs +++ b/crates/rome_js_formatter/src/js/any/root.rs @@ -1,13 +1,14 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyRoot; use crate::prelude::*; use rome_js_syntax::JsAnyRoot; -impl Format for JsAnyRoot { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsScript(node) => node.format(formatter), - Self::JsModule(node) => node.format(formatter), - Self::JsExpressionSnipped(node) => node.format(formatter), +impl FormatRule for FormatJsAnyRoot { + fn format(node: &JsAnyRoot, formatter: &Formatter) -> FormatResult { + match node { + JsAnyRoot::JsScript(node) => formatted![formatter, [node.format()]], + JsAnyRoot::JsModule(node) => formatted![formatter, [node.format()]], + JsAnyRoot::JsExpressionSnipped(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/statement.rs b/crates/rome_js_formatter/src/js/any/statement.rs index d3dae0356839..408525c347c9 100644 --- a/crates/rome_js_formatter/src/js/any/statement.rs +++ b/crates/rome_js_formatter/src/js/any/statement.rs @@ -1,42 +1,49 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyStatement; use crate::prelude::*; use rome_js_syntax::JsAnyStatement; -impl Format for JsAnyStatement { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsBlockStatement(node) => node.format(formatter), - Self::JsBreakStatement(node) => node.format(formatter), - Self::JsClassDeclaration(node) => node.format(formatter), - Self::JsContinueStatement(node) => node.format(formatter), - Self::JsDebuggerStatement(node) => node.format(formatter), - Self::JsDoWhileStatement(node) => node.format(formatter), - Self::JsEmptyStatement(node) => node.format(formatter), - Self::JsExpressionStatement(node) => node.format(formatter), - Self::JsForInStatement(node) => node.format(formatter), - Self::JsForOfStatement(node) => node.format(formatter), - Self::JsForStatement(node) => node.format(formatter), - Self::JsIfStatement(node) => node.format(formatter), - Self::JsLabeledStatement(node) => node.format(formatter), - Self::JsReturnStatement(node) => node.format(formatter), - Self::JsSwitchStatement(node) => node.format(formatter), - Self::JsThrowStatement(node) => node.format(formatter), - Self::JsTryFinallyStatement(node) => node.format(formatter), - Self::JsTryStatement(node) => node.format(formatter), - Self::JsUnknownStatement(node) => node.format(formatter), - Self::JsVariableStatement(node) => node.format(formatter), - Self::JsWhileStatement(node) => node.format(formatter), - Self::JsWithStatement(node) => node.format(formatter), - Self::JsFunctionDeclaration(node) => node.format(formatter), - Self::TsEnumDeclaration(node) => node.format(formatter), - Self::TsTypeAliasDeclaration(node) => node.format(formatter), - Self::TsInterfaceDeclaration(node) => node.format(formatter), - Self::TsDeclareFunctionDeclaration(node) => node.format(formatter), - Self::TsDeclareStatement(node) => node.format(formatter), - Self::TsModuleDeclaration(node) => node.format(formatter), - Self::TsExternalModuleDeclaration(node) => node.format(formatter), - Self::TsGlobalDeclaration(node) => node.format(formatter), - Self::TsImportEqualsDeclaration(node) => node.format(formatter), +impl FormatRule for FormatJsAnyStatement { + fn format(node: &JsAnyStatement, formatter: &Formatter) -> FormatResult { + match node { + JsAnyStatement::JsBlockStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsBreakStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsClassDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsContinueStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsDebuggerStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsDoWhileStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsEmptyStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsExpressionStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsForInStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsForOfStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsForStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsIfStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsLabeledStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsReturnStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsSwitchStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsThrowStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsTryFinallyStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsTryStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsUnknownStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsVariableStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsWhileStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsWithStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::JsFunctionDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyStatement::TsEnumDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyStatement::TsTypeAliasDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyStatement::TsInterfaceDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyStatement::TsDeclareFunctionDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyStatement::TsDeclareStatement(node) => formatted![formatter, [node.format()]], + JsAnyStatement::TsModuleDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyStatement::TsExternalModuleDeclaration(node) => { + formatted![formatter, [node.format()]] + } + JsAnyStatement::TsGlobalDeclaration(node) => formatted![formatter, [node.format()]], + JsAnyStatement::TsImportEqualsDeclaration(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/js/any/switch_clause.rs b/crates/rome_js_formatter/src/js/any/switch_clause.rs index 14a8e95f7ec7..9b26dc43f8de 100644 --- a/crates/rome_js_formatter/src/js/any/switch_clause.rs +++ b/crates/rome_js_formatter/src/js/any/switch_clause.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnySwitchClause; use crate::prelude::*; use rome_js_syntax::JsAnySwitchClause; -impl Format for JsAnySwitchClause { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsCaseClause(node) => node.format(formatter), - Self::JsDefaultClause(node) => node.format(formatter), +impl FormatRule for FormatJsAnySwitchClause { + fn format(node: &JsAnySwitchClause, formatter: &Formatter) -> FormatResult { + match node { + JsAnySwitchClause::JsCaseClause(node) => formatted![formatter, [node.format()]], + JsAnySwitchClause::JsDefaultClause(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/any/template_element.rs b/crates/rome_js_formatter/src/js/any/template_element.rs index b10313ecab55..5c26623a7bb6 100644 --- a/crates/rome_js_formatter/src/js/any/template_element.rs +++ b/crates/rome_js_formatter/src/js/any/template_element.rs @@ -1,12 +1,15 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsAnyTemplateElement; use crate::prelude::*; use rome_js_syntax::JsAnyTemplateElement; -impl Format for JsAnyTemplateElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsTemplateChunkElement(node) => node.format(formatter), - Self::JsTemplateElement(node) => node.format(formatter), +impl FormatRule for FormatJsAnyTemplateElement { + fn format(node: &JsAnyTemplateElement, formatter: &Formatter) -> FormatResult { + match node { + JsAnyTemplateElement::JsTemplateChunkElement(node) => { + formatted![formatter, [node.format()]] + } + JsAnyTemplateElement::JsTemplateElement(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/assignments/array_assignment_pattern.rs b/crates/rome_js_formatter/src/js/assignments/array_assignment_pattern.rs index 67aa78ec56e7..83fb3a77e5e2 100644 --- a/crates/rome_js_formatter/src/js/assignments/array_assignment_pattern.rs +++ b/crates/rome_js_formatter/src/js/assignments/array_assignment_pattern.rs @@ -1,19 +1,23 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsArrayAssignmentPattern; use rome_js_syntax::JsArrayAssignmentPatternFields; -impl FormatNode for JsArrayAssignmentPattern { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsArrayAssignmentPattern, + formatter: &Formatter, + ) -> FormatResult { let JsArrayAssignmentPatternFields { l_brack_token, elements, r_brack_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_indent( &l_brack_token?, - elements.format(formatter)?, + formatted![formatter, [elements.format()]]?, &r_brack_token?, ) } diff --git a/crates/rome_js_formatter/src/js/assignments/array_assignment_pattern_rest_element.rs b/crates/rome_js_formatter/src/js/assignments/array_assignment_pattern_rest_element.rs index 2b8cd09a55a6..2ea2d3cd589b 100644 --- a/crates/rome_js_formatter/src/js/assignments/array_assignment_pattern_rest_element.rs +++ b/crates/rome_js_formatter/src/js/assignments/array_assignment_pattern_rest_element.rs @@ -1,19 +1,21 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsArrayAssignmentPatternRestElement; use rome_js_syntax::JsArrayAssignmentPatternRestElementFields; -impl FormatNode for JsArrayAssignmentPatternRestElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsArrayAssignmentPatternRestElement, + formatter: &Formatter, + ) -> FormatResult { let JsArrayAssignmentPatternRestElementFields { dotdotdot_token, pattern, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - dotdotdot_token.format(formatter)?, - pattern.format(formatter)? - ] + formatted![formatter, [dotdotdot_token.format(), pattern.format()]] } } diff --git a/crates/rome_js_formatter/src/js/assignments/assignment_with_default.rs b/crates/rome_js_formatter/src/js/assignments/assignment_with_default.rs index cf63b32487f4..d42291c85477 100644 --- a/crates/rome_js_formatter/src/js/assignments/assignment_with_default.rs +++ b/crates/rome_js_formatter/src/js/assignments/assignment_with_default.rs @@ -1,23 +1,29 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsAssignmentWithDefault; use rome_js_syntax::JsAssignmentWithDefaultFields; -impl FormatNode for JsAssignmentWithDefault { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsAssignmentWithDefault, + formatter: &Formatter, + ) -> FormatResult { let JsAssignmentWithDefaultFields { pattern, eq_token, default, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - pattern.format(formatter)?, - space_token(), - eq_token.format(formatter)?, - space_token(), - default.format(formatter)?, + [ + pattern.format(), + space_token(), + eq_token.format(), + space_token(), + default.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/assignments/computed_member_assignment.rs b/crates/rome_js_formatter/src/js/assignments/computed_member_assignment.rs index a8a4700735c9..0b9969d3d465 100644 --- a/crates/rome_js_formatter/src/js/assignments/computed_member_assignment.rs +++ b/crates/rome_js_formatter/src/js/assignments/computed_member_assignment.rs @@ -1,23 +1,29 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsComputedMemberAssignment; use rome_js_syntax::JsComputedMemberAssignmentFields; -impl FormatNode for JsComputedMemberAssignment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsComputedMemberAssignment, + formatter: &Formatter, + ) -> FormatResult { let JsComputedMemberAssignmentFields { object, l_brack_token, member, r_brack_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - object.format(formatter)?, - l_brack_token.format(formatter)?, - member.format(formatter)?, - r_brack_token.format(formatter)?, + [ + object.format(), + l_brack_token.format(), + member.format(), + r_brack_token.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/assignments/identifier_assignment.rs b/crates/rome_js_formatter/src/js/assignments/identifier_assignment.rs index 769d6ab5b7bc..d5d6b7f6d7e3 100644 --- a/crates/rome_js_formatter/src/js/assignments/identifier_assignment.rs +++ b/crates/rome_js_formatter/src/js/assignments/identifier_assignment.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsIdentifierAssignment; use rome_js_syntax::JsIdentifierAssignmentFields; -impl FormatNode for JsIdentifierAssignment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsIdentifierAssignmentFields { name_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsIdentifierAssignment, + formatter: &Formatter, + ) -> FormatResult { + let JsIdentifierAssignmentFields { name_token } = node.as_fields(); - name_token.format(formatter) + formatted![formatter, [name_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern.rs b/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern.rs index 7bd314e77bf4..c2feab5aecb8 100644 --- a/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern.rs +++ b/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern.rs @@ -1,18 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsObjectAssignmentPattern; use rome_js_syntax::JsObjectAssignmentPatternFields; -impl FormatNode for JsObjectAssignmentPattern { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsObjectAssignmentPattern, + formatter: &Formatter, + ) -> FormatResult { let JsObjectAssignmentPatternFields { l_curly_token, properties, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_spaces( &l_curly_token?, - properties.format(formatter)?, + formatted![formatter, [properties.format()]]?, &r_curly_token?, ) } diff --git a/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_property.rs b/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_property.rs index 61142c0fa83d..822bd55cc101 100644 --- a/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_property.rs +++ b/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_property.rs @@ -1,25 +1,33 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsObjectAssignmentPatternProperty; use rome_js_syntax::JsObjectAssignmentPatternPropertyFields; -impl FormatNode for JsObjectAssignmentPatternProperty { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsObjectAssignmentPatternProperty, + formatter: &Formatter, + ) -> FormatResult { let JsObjectAssignmentPatternPropertyFields { member, colon_token, pattern, init, - } = self.as_fields(); + } = node.as_fields(); - let init_node = init.with_or_empty(|node| formatted![formatter, space_token(), node]); formatted![ formatter, - member.format(formatter)?, - colon_token.format(formatter)?, - space_token(), - pattern.format(formatter)?, - init_node, + [ + member.format(), + colon_token.format(), + space_token(), + pattern.format(), + init.format() + .with_or_empty(|node| formatted![formatter, [space_token(), node]]), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_rest.rs b/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_rest.rs index 8800df62885f..4095864d3ec2 100644 --- a/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_rest.rs +++ b/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_rest.rs @@ -1,19 +1,21 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsObjectAssignmentPatternRest; use rome_js_syntax::JsObjectAssignmentPatternRestFields; -impl FormatNode for JsObjectAssignmentPatternRest { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsObjectAssignmentPatternRest, + formatter: &Formatter, + ) -> FormatResult { let JsObjectAssignmentPatternRestFields { dotdotdot_token, target, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - dotdotdot_token.format(formatter)?, - target.format(formatter)?, - ] + formatted![formatter, [dotdotdot_token.format(), target.format()?,]] } } diff --git a/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_shorthand_property.rs b/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_shorthand_property.rs index c0667d89eabd..820a4d76dfb3 100644 --- a/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_shorthand_property.rs +++ b/crates/rome_js_formatter/src/js/assignments/object_assignment_pattern_shorthand_property.rs @@ -1,14 +1,26 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsObjectAssignmentPatternShorthandProperty; use rome_js_syntax::JsObjectAssignmentPatternShorthandPropertyFields; -impl FormatNode for JsObjectAssignmentPatternShorthandProperty { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsObjectAssignmentPatternShorthandProperty, + formatter: &Formatter, + ) -> FormatResult { let JsObjectAssignmentPatternShorthandPropertyFields { identifier, init } = - self.as_fields(); + node.as_fields(); - let init_node = init.with_or_empty(|node| formatted![formatter, space_token(), node]); - formatted![formatter, identifier.format(formatter)?, init_node] + formatted![ + formatter, + [ + identifier.format()?, + init.format() + .with_or_empty(|node| formatted![formatter, [space_token(), node]]) + ] + ] } } diff --git a/crates/rome_js_formatter/src/js/assignments/parenthesized_assignment.rs b/crates/rome_js_formatter/src/js/assignments/parenthesized_assignment.rs index 2eb29758fdf0..6a18583318f5 100644 --- a/crates/rome_js_formatter/src/js/assignments/parenthesized_assignment.rs +++ b/crates/rome_js_formatter/src/js/assignments/parenthesized_assignment.rs @@ -1,20 +1,26 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsParenthesizedAssignment; use rome_js_syntax::JsParenthesizedAssignmentFields; -impl FormatNode for JsParenthesizedAssignment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsParenthesizedAssignment, + formatter: &Formatter, + ) -> FormatResult { let JsParenthesizedAssignmentFields { l_paren_token, assignment, r_paren_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - l_paren_token.format(formatter)?, - assignment.format(formatter)?, - r_paren_token.format(formatter)?, + [ + l_paren_token.format(), + assignment.format(), + r_paren_token.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/assignments/static_member_assignment.rs b/crates/rome_js_formatter/src/js/assignments/static_member_assignment.rs index c1f21ee464e8..d905dbe4c0ea 100644 --- a/crates/rome_js_formatter/src/js/assignments/static_member_assignment.rs +++ b/crates/rome_js_formatter/src/js/assignments/static_member_assignment.rs @@ -1,20 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsStaticMemberAssignment; use rome_js_syntax::JsStaticMemberAssignmentFields; -impl FormatNode for JsStaticMemberAssignment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsStaticMemberAssignment, + formatter: &Formatter, + ) -> FormatResult { let JsStaticMemberAssignmentFields { object, dot_token, member, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - object.format(formatter)?, - dot_token.format(formatter)?, - member.format(formatter)?, + [object.format(), dot_token.format(), member.format(),] ] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/array_hole.rs b/crates/rome_js_formatter/src/js/auxiliary/array_hole.rs index fa74d0a1c6df..125cee4f952b 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/array_hole.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/array_hole.rs @@ -1,9 +1,10 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsArrayHole; -impl FormatNode for JsArrayHole { - fn format_fields(&self, _: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(_: &JsArrayHole, _: &Formatter) -> FormatResult { Ok(empty_element()) } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/case_clause.rs b/crates/rome_js_formatter/src/js/auxiliary/case_clause.rs index 734be39f1881..537b098cce22 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/case_clause.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/case_clause.rs @@ -2,26 +2,27 @@ use crate::prelude::*; use rome_js_syntax::JsAnyStatement; use rome_rowan::AstNodeList; +use crate::FormatNodeFields; use rome_js_syntax::JsCaseClause; use rome_js_syntax::JsCaseClauseFields; -impl FormatNode for JsCaseClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsCaseClause, formatter: &Formatter) -> FormatResult { let JsCaseClauseFields { case_token, test, colon_token, consequent, - } = self.as_fields(); + } = node.as_fields(); let is_first_child_block_stmt = matches!( consequent.iter().next(), Some(JsAnyStatement::JsBlockStatement(_)) ); - let case_word = case_token.format(formatter)?; - let colon = colon_token.format(formatter)?; - let test = test.format(formatter)?; - let cons = formatter.format_list(consequent); + let case_word = case_token.format(); + let colon = colon_token.format(); + let test = test.format(); + let cons = formatter.format_list(&consequent); let cons = if cons.is_empty() { // Skip inserting an indent block is the consequent is empty to print @@ -29,12 +30,12 @@ impl FormatNode for JsCaseClause { // block to push them into hard_line_break() } else if is_first_child_block_stmt { - formatted![formatter, space_token(), cons]? + formatted![formatter, [space_token(), cons]]? } else { // no line break needed after because it is added by the indent in the switch statement - indent(formatted![formatter, hard_line_break(), cons]?) + indent(formatted![formatter, [hard_line_break(), cons]]?) }; - formatted![formatter, case_word, space_token(), test, colon, cons] + formatted![formatter, [case_word, space_token(), test, colon, cons]] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/catch_clause.rs b/crates/rome_js_formatter/src/js/auxiliary/catch_clause.rs index ffcab2148fc9..9a062096c7b7 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/catch_clause.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/catch_clause.rs @@ -1,38 +1,39 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsCatchClause; use rome_js_syntax::JsCatchClauseFields; -impl FormatNode for JsCatchClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsCatchClause, formatter: &Formatter) -> FormatResult { let JsCatchClauseFields { catch_token, declaration, body, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - declaration.with_or( + [declaration.format().with_or( |declaration| { formatted![ formatter, - catch_token.format(formatter)?, - space_token(), - declaration, - space_token(), - body.format(formatter)? + [ + catch_token.format(), + space_token(), + declaration, + space_token(), + body.format() + ] ] }, || { formatted![ formatter, - catch_token.format(formatter)?, - space_token(), - body.format(formatter)? + [catch_token.format(), space_token(), body.format()] ] }, - ) + )] ] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/default_clause.rs b/crates/rome_js_formatter/src/js/auxiliary/default_clause.rs index b27785b516b1..bb0469ea6fce 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/default_clause.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/default_clause.rs @@ -1,34 +1,35 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsDefaultClause; use rome_js_syntax::{JsAnyStatement, JsDefaultClauseFields}; use rome_rowan::AstNodeList; -impl FormatNode for JsDefaultClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsDefaultClause, formatter: &Formatter) -> FormatResult { let JsDefaultClauseFields { default_token, colon_token, consequent, - } = self.as_fields(); + } = node.as_fields(); let first_child_is_block_stmt = matches!( consequent.iter().next(), Some(JsAnyStatement::JsBlockStatement(_)) ); - let default = default_token.format(formatter)?; - let colon = colon_token.format(formatter)?; - let statements = formatter.format_list(consequent); + let default = default_token.format(); + let colon = colon_token.format(); + let statements = formatter.format_list(&consequent); let formatted_cons = if statements.is_empty() { hard_line_break() } else if first_child_is_block_stmt { - formatted![formatter, space_token(), statements]? + formatted![formatter, [space_token(), statements]]? } else { // no line break needed after because it is added by the indent in the switch statement - indent(formatted![formatter, hard_line_break(), statements]?) + indent(formatted![formatter, [hard_line_break(), statements]]?) }; - formatted![formatter, default, colon, space_token(), formatted_cons] + formatted![formatter, [default, colon, space_token(), formatted_cons]] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/directive.rs b/crates/rome_js_formatter/src/js/auxiliary/directive.rs index 0edc7b0732a7..0ad1f30ab482 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/directive.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/directive.rs @@ -1,15 +1,16 @@ use crate::prelude::*; use crate::utils::{format_string_literal_token, format_with_semicolon}; +use crate::FormatNodeFields; use rome_js_syntax::JsDirective; use rome_js_syntax::JsDirectiveFields; -impl FormatNode for JsDirective { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsDirective, formatter: &Formatter) -> FormatResult { let JsDirectiveFields { value_token, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); format_with_semicolon( formatter, diff --git a/crates/rome_js_formatter/src/js/auxiliary/else_clause.rs b/crates/rome_js_formatter/src/js/auxiliary/else_clause.rs index e0b434812141..a02bcacf7e0d 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/else_clause.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/else_clause.rs @@ -1,20 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsElseClause; use rome_js_syntax::JsElseClauseFields; -impl FormatNode for JsElseClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsElseClause, formatter: &Formatter) -> FormatResult { let JsElseClauseFields { else_token, alternate, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - else_token.format(formatter)?, - space_token(), - alternate.format(formatter)?, + [else_token.format(), space_token(), alternate.format(),] ] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/expression_snipped.rs b/crates/rome_js_formatter/src/js/auxiliary/expression_snipped.rs index 2506e3a9bf64..d00b1fa1e6c6 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/expression_snipped.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/expression_snipped.rs @@ -1,19 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsExpressionSnipped; use rome_js_syntax::JsExpressionSnippedFields; -impl FormatNode for JsExpressionSnipped { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsExpressionSnipped, + formatter: &Formatter, + ) -> FormatResult { let JsExpressionSnippedFields { expression, eof_token, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - expression.format(formatter)?, - eof_token.format(formatter)?, - ] + formatted![formatter, [expression.format(), eof_token.format(),]] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/finally_clause.rs b/crates/rome_js_formatter/src/js/auxiliary/finally_clause.rs index 6bbf9c9af269..4b8fc92f382d 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/finally_clause.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/finally_clause.rs @@ -1,20 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsFinallyClause; use rome_js_syntax::JsFinallyClauseFields; -impl FormatNode for JsFinallyClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsFinallyClause, formatter: &Formatter) -> FormatResult { let JsFinallyClauseFields { finally_token, body, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - finally_token.format(formatter)?, - space_token(), - body.format(formatter)? + [finally_token.format(), space_token(), body.format()] ] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/function_body.rs b/crates/rome_js_formatter/src/js/auxiliary/function_body.rs index c3cbff4ad902..ae7c8e4581ec 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/function_body.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/function_body.rs @@ -1,23 +1,23 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsFunctionBody; use rome_js_syntax::JsFunctionBodyFields; -impl FormatNode for JsFunctionBody { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsFunctionBody, formatter: &Formatter) -> FormatResult { let JsFunctionBodyFields { l_curly_token, directives, statements, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_block_indent( &l_curly_token?, formatted![ formatter, - directives.format(formatter)?, - formatter.format_list(statements), + [directives.format(), formatter.format_list(&statements),] ]?, &r_curly_token?, ) diff --git a/crates/rome_js_formatter/src/js/auxiliary/initializer_clause.rs b/crates/rome_js_formatter/src/js/auxiliary/initializer_clause.rs index c18b8278b48f..7500a87af7a7 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/initializer_clause.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/initializer_clause.rs @@ -1,20 +1,26 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsInitializerClause; use rome_js_syntax::JsInitializerClauseFields; -impl FormatNode for JsInitializerClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsInitializerClause, + formatter: &Formatter, + ) -> FormatResult { let JsInitializerClauseFields { eq_token, expression, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - hard_group_elements(eq_token.format(formatter)?), - space_token(), - expression.format(formatter)? + [ + hard_group_elements(formatted![formatter, [eq_token.format()]]?), + space_token(), + expression.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/module.rs b/crates/rome_js_formatter/src/js/auxiliary/module.rs index 9c72dce00ff5..5b53f5072952 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/module.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/module.rs @@ -1,25 +1,28 @@ use crate::prelude::*; use crate::utils::format_interpreter; +use crate::FormatNodeFields; use rome_js_syntax::JsModule; use rome_js_syntax::JsModuleFields; -impl FormatNode for JsModule { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsModule, formatter: &Formatter) -> FormatResult { let JsModuleFields { interpreter_token, directives, items, eof_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - format_interpreter(interpreter_token, formatter)?, - directives.format(formatter)?, - formatter.format_list(items), - eof_token.format(formatter)?, - hard_line_break() + [ + format_interpreter(interpreter_token, formatter)?, + directives.format(), + formatter.format_list(&items), + eof_token.format(), + hard_line_break() + ] ] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/name.rs b/crates/rome_js_formatter/src/js/auxiliary/name.rs index 348c72ca88f1..aabdb2c813de 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/name.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/name.rs @@ -1,12 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsName; use rome_js_syntax::JsNameFields; -impl FormatNode for JsName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsNameFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsName, formatter: &Formatter) -> FormatResult { + let JsNameFields { value_token } = node.as_fields(); - value_token.format(formatter) + formatted![formatter, [value_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/new_target.rs b/crates/rome_js_formatter/src/js/auxiliary/new_target.rs index e7dc76a2f874..d0769e085549 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/new_target.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/new_target.rs @@ -1,21 +1,24 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::NewTarget; use rome_js_syntax::NewTargetFields; -impl FormatNode for NewTarget { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &NewTarget, formatter: &Formatter) -> FormatResult { let NewTargetFields { new_token, dot_token, target_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - new_token.format(formatter)?, - dot_token.format(formatter)?, - target_token.format(formatter)?, + [ + new_token.format(), + dot_token.format(), + target_token.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/private_name.rs b/crates/rome_js_formatter/src/js/auxiliary/private_name.rs index 96f2af47bcb5..83d108ebaf7b 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/private_name.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/private_name.rs @@ -1,19 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsPrivateName; use rome_js_syntax::JsPrivateNameFields; -impl FormatNode for JsPrivateName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsPrivateName, formatter: &Formatter) -> FormatResult { let JsPrivateNameFields { hash_token, value_token, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - hash_token.format(formatter)?, - value_token.format(formatter)? - ] + formatted![formatter, [hash_token.format(), value_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/reference_identifier.rs b/crates/rome_js_formatter/src/js/auxiliary/reference_identifier.rs index 38c0a2897fc5..64e4e40e323c 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/reference_identifier.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/reference_identifier.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsReferenceIdentifier; use rome_js_syntax::JsReferenceIdentifierFields; -impl FormatNode for JsReferenceIdentifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsReferenceIdentifierFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsReferenceIdentifier, + formatter: &Formatter, + ) -> FormatResult { + let JsReferenceIdentifierFields { value_token } = node.as_fields(); - value_token.format(formatter) + formatted![formatter, [value_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/script.rs b/crates/rome_js_formatter/src/js/auxiliary/script.rs index 4c9b8c132e17..1ab35101e5ab 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/script.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/script.rs @@ -1,25 +1,28 @@ use crate::prelude::*; use crate::utils::format_interpreter; +use crate::FormatNodeFields; use rome_js_syntax::JsScript; use rome_js_syntax::JsScriptFields; -impl FormatNode for JsScript { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsScript, formatter: &Formatter) -> FormatResult { let JsScriptFields { interpreter_token, directives, statements, eof_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - format_interpreter(interpreter_token, formatter)?, - directives.format(formatter)?, - formatter.format_list(statements), - eof_token.format(formatter)?, - hard_line_break() + [ + format_interpreter(interpreter_token, formatter)?, + directives.format(), + formatter.format_list(&statements), + eof_token.format(), + hard_line_break() + ] ] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/spread.rs b/crates/rome_js_formatter/src/js/auxiliary/spread.rs index 8d082ae9bd61..2be811a36399 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/spread.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/spread.rs @@ -1,19 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsSpread; use rome_js_syntax::JsSpreadFields; -impl FormatNode for JsSpread { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsSpread, formatter: &Formatter) -> FormatResult { let JsSpreadFields { dotdotdot_token, argument, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - dotdotdot_token.format(formatter)?, - argument.format(formatter)? - ] + formatted![formatter, [dotdotdot_token.format(), argument.format()]] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/static_modifier.rs b/crates/rome_js_formatter/src/js/auxiliary/static_modifier.rs index 8eaedad9db72..1d27f7c34c6a 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/static_modifier.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/static_modifier.rs @@ -1,11 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsStaticModifier; use rome_js_syntax::JsStaticModifierFields; -impl FormatNode for JsStaticModifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsStaticModifierFields { modifier_token } = self.as_fields(); - modifier_token.format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsStaticModifier, + formatter: &Formatter, + ) -> FormatResult { + let JsStaticModifierFields { modifier_token } = node.as_fields(); + + formatted![formatter, [modifier_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/variable_declaration_clause.rs b/crates/rome_js_formatter/src/js/auxiliary/variable_declaration_clause.rs index 7f79796c15b3..8b4bf40407f6 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/variable_declaration_clause.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/variable_declaration_clause.rs @@ -1,16 +1,24 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsVariableDeclarationClause; use rome_js_syntax::JsVariableDeclarationClauseFields; -impl FormatNode for JsVariableDeclarationClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsVariableDeclarationClause, + formatter: &Formatter, + ) -> FormatResult { let JsVariableDeclarationClauseFields { declaration, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - format_with_semicolon(formatter, declaration.format(formatter)?, semicolon_token) + format_with_semicolon( + formatter, + formatted![formatter, [declaration.format()]]?, + semicolon_token, + ) } } diff --git a/crates/rome_js_formatter/src/js/auxiliary/variable_declarator.rs b/crates/rome_js_formatter/src/js/auxiliary/variable_declarator.rs index a5757ee47232..d1214bf9252f 100644 --- a/crates/rome_js_formatter/src/js/auxiliary/variable_declarator.rs +++ b/crates/rome_js_formatter/src/js/auxiliary/variable_declarator.rs @@ -1,24 +1,30 @@ use crate::prelude::*; use crate::utils::format_initializer_clause; +use crate::FormatNodeFields; use rome_js_syntax::JsVariableDeclarator; use rome_js_syntax::JsVariableDeclaratorFields; -impl FormatNode for JsVariableDeclarator { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsVariableDeclarator, + formatter: &Formatter, + ) -> FormatResult { let JsVariableDeclaratorFields { id, variable_annotation, initializer, - } = self.as_fields(); + } = node.as_fields(); let initializer = format_initializer_clause(formatter, initializer)?; formatted![ formatter, - hard_group_elements(id.format(formatter)?), - variable_annotation, - initializer + [ + hard_group_elements(formatted![formatter, [id.format()]]?), + variable_annotation.format(), + initializer + ] ] } } diff --git a/crates/rome_js_formatter/src/js/bindings/array_binding_pattern.rs b/crates/rome_js_formatter/src/js/bindings/array_binding_pattern.rs index 983b2897fa33..503c19416be5 100644 --- a/crates/rome_js_formatter/src/js/bindings/array_binding_pattern.rs +++ b/crates/rome_js_formatter/src/js/bindings/array_binding_pattern.rs @@ -1,19 +1,23 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsArrayBindingPattern; use rome_js_syntax::JsArrayBindingPatternFields; -impl FormatNode for JsArrayBindingPattern { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsArrayBindingPattern, + formatter: &Formatter, + ) -> FormatResult { let JsArrayBindingPatternFields { l_brack_token, elements, r_brack_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_indent( &l_brack_token?, - elements.format(formatter)?, + formatted![formatter, [elements.format()]]?, &r_brack_token?, ) } diff --git a/crates/rome_js_formatter/src/js/bindings/array_binding_pattern_rest_element.rs b/crates/rome_js_formatter/src/js/bindings/array_binding_pattern_rest_element.rs index 3addef67d9a6..2b46e098923c 100644 --- a/crates/rome_js_formatter/src/js/bindings/array_binding_pattern_rest_element.rs +++ b/crates/rome_js_formatter/src/js/bindings/array_binding_pattern_rest_element.rs @@ -1,19 +1,21 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsArrayBindingPatternRestElement; use rome_js_syntax::JsArrayBindingPatternRestElementFields; -impl FormatNode for JsArrayBindingPatternRestElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsArrayBindingPatternRestElement, + formatter: &Formatter, + ) -> FormatResult { let JsArrayBindingPatternRestElementFields { dotdotdot_token, pattern, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - dotdotdot_token.format(formatter)?, - pattern.format(formatter)?, - ] + formatted![formatter, [dotdotdot_token.format(), pattern.format(),]] } } diff --git a/crates/rome_js_formatter/src/js/bindings/binding_pattern_with_default.rs b/crates/rome_js_formatter/src/js/bindings/binding_pattern_with_default.rs index 060fe83eaf37..7a19b31861a2 100644 --- a/crates/rome_js_formatter/src/js/bindings/binding_pattern_with_default.rs +++ b/crates/rome_js_formatter/src/js/bindings/binding_pattern_with_default.rs @@ -1,23 +1,29 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsBindingPatternWithDefault; use rome_js_syntax::JsBindingPatternWithDefaultFields; -impl FormatNode for JsBindingPatternWithDefault { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsBindingPatternWithDefault, + formatter: &Formatter, + ) -> FormatResult { let JsBindingPatternWithDefaultFields { pattern, eq_token, default, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - pattern.format(formatter)?, - space_token(), - eq_token.format(formatter)?, - space_token(), - default.format(formatter)? + [ + pattern.format(), + space_token(), + eq_token.format(), + space_token(), + default.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/js/bindings/constructor_parameters.rs b/crates/rome_js_formatter/src/js/bindings/constructor_parameters.rs index 04193725db07..0115ffda8b23 100644 --- a/crates/rome_js_formatter/src/js/bindings/constructor_parameters.rs +++ b/crates/rome_js_formatter/src/js/bindings/constructor_parameters.rs @@ -1,19 +1,23 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsConstructorParameters; use rome_js_syntax::JsConstructorParametersFields; -impl FormatNode for JsConstructorParameters { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsConstructorParameters, + formatter: &Formatter, + ) -> FormatResult { let JsConstructorParametersFields { l_paren_token, parameters, r_paren_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_indent( &l_paren_token?, - parameters.format(formatter)?, + formatted![formatter, [parameters.format()]]?, &r_paren_token?, ) } diff --git a/crates/rome_js_formatter/src/js/bindings/formal_parameter.rs b/crates/rome_js_formatter/src/js/bindings/formal_parameter.rs index 188a328b281f..370e99ced024 100644 --- a/crates/rome_js_formatter/src/js/bindings/formal_parameter.rs +++ b/crates/rome_js_formatter/src/js/bindings/formal_parameter.rs @@ -1,26 +1,32 @@ use crate::prelude::*; use crate::utils::format_initializer_clause; +use crate::FormatNodeFields; use rome_js_syntax::JsFormalParameter; use rome_js_syntax::JsFormalParameterFields; -impl FormatNode for JsFormalParameter { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsFormalParameter, + formatter: &Formatter, + ) -> FormatResult { let JsFormalParameterFields { binding, question_mark_token, type_annotation, initializer, - } = self.as_fields(); + } = node.as_fields(); let initializer = format_initializer_clause(formatter, initializer)?; formatted![ formatter, - binding.format(formatter)?, - question_mark_token, - type_annotation, - initializer + [ + binding.format(), + question_mark_token.format(), + type_annotation.format(), + initializer + ] ] } } diff --git a/crates/rome_js_formatter/src/js/bindings/identifier_binding.rs b/crates/rome_js_formatter/src/js/bindings/identifier_binding.rs index 0b5f62ff54c3..c3816f576a44 100644 --- a/crates/rome_js_formatter/src/js/bindings/identifier_binding.rs +++ b/crates/rome_js_formatter/src/js/bindings/identifier_binding.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsIdentifierBinding; use rome_js_syntax::JsIdentifierBindingFields; -impl FormatNode for JsIdentifierBinding { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsIdentifierBindingFields { name_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsIdentifierBinding, + formatter: &Formatter, + ) -> FormatResult { + let JsIdentifierBindingFields { name_token } = node.as_fields(); - name_token.format(formatter) + formatted![formatter, [name_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/bindings/object_binding_pattern.rs b/crates/rome_js_formatter/src/js/bindings/object_binding_pattern.rs index a40c9c4bb2f1..8415df6d6af6 100644 --- a/crates/rome_js_formatter/src/js/bindings/object_binding_pattern.rs +++ b/crates/rome_js_formatter/src/js/bindings/object_binding_pattern.rs @@ -1,19 +1,23 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsObjectBindingPattern; use rome_js_syntax::JsObjectBindingPatternFields; -impl FormatNode for JsObjectBindingPattern { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsObjectBindingPattern, + formatter: &Formatter, + ) -> FormatResult { let JsObjectBindingPatternFields { l_curly_token, properties, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_spaces( &l_curly_token?, - properties.format(formatter)?, + formatted![formatter, [properties.format()]]?, &r_curly_token?, ) } diff --git a/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_property.rs b/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_property.rs index 1f0c9b42571b..209187284e1a 100644 --- a/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_property.rs +++ b/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_property.rs @@ -1,28 +1,33 @@ -use crate::format_extensions::FormatOptional; -use rome_formatter::FormatResult; - -use crate::{formatted, space_token, Format, FormatElement, FormatNode, Formatter}; +use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsObjectBindingPatternProperty; use rome_js_syntax::JsObjectBindingPatternPropertyFields; -impl FormatNode for JsObjectBindingPatternProperty { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsObjectBindingPatternProperty, + formatter: &Formatter, + ) -> FormatResult { let JsObjectBindingPatternPropertyFields { member, colon_token, pattern, init, - } = self.as_fields(); + } = node.as_fields(); - let init_node = init.with_or_empty(|node| formatted![formatter, space_token(), node]); formatted![ formatter, - member.format(formatter)?, - colon_token.format(formatter)?, - space_token(), - pattern.format(formatter)?, - init_node, + [ + member.format(), + colon_token.format(), + space_token(), + pattern.format(), + init.format() + .with_or_empty(|node| formatted![formatter, [space_token(), node]]), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_rest.rs b/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_rest.rs index 84a12311a572..634570dcbf2e 100644 --- a/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_rest.rs +++ b/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_rest.rs @@ -1,19 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsObjectBindingPatternRest; use rome_js_syntax::JsObjectBindingPatternRestFields; -impl FormatNode for JsObjectBindingPatternRest { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsObjectBindingPatternRest, + formatter: &Formatter, + ) -> FormatResult { let JsObjectBindingPatternRestFields { dotdotdot_token, binding, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - dotdotdot_token.format(formatter)?, - binding.format(formatter)?, - ] + formatted![formatter, [dotdotdot_token.format(), binding.format(),]] } } diff --git a/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_shorthand_property.rs b/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_shorthand_property.rs index 8d9bdd07432a..8d0971cf85bf 100644 --- a/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_shorthand_property.rs +++ b/crates/rome_js_formatter/src/js/bindings/object_binding_pattern_shorthand_property.rs @@ -1,16 +1,25 @@ -use crate::format_extensions::FormatOptional; -use rome_formatter::FormatResult; - -use crate::{formatted, space_token, Format, FormatElement, FormatNode, Formatter}; +use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsObjectBindingPatternShorthandProperty; use rome_js_syntax::JsObjectBindingPatternShorthandPropertyFields; -impl FormatNode for JsObjectBindingPatternShorthandProperty { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsObjectBindingPatternShorthandPropertyFields { identifier, init } = self.as_fields(); +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsObjectBindingPatternShorthandProperty, + formatter: &Formatter, + ) -> FormatResult { + let JsObjectBindingPatternShorthandPropertyFields { identifier, init } = node.as_fields(); - let init_node = init.with_or_empty(|node| formatted![formatter, space_token(), node]); - formatted![formatter, identifier.format(formatter)?, init_node] + formatted![ + formatter, + [ + identifier.format(), + init.format() + .with_or_empty(|node| formatted![formatter, [space_token(), node]]) + ] + ] } } diff --git a/crates/rome_js_formatter/src/js/bindings/parameters.rs b/crates/rome_js_formatter/src/js/bindings/parameters.rs index 42d0ccb98cd6..1419c2aa8254 100644 --- a/crates/rome_js_formatter/src/js/bindings/parameters.rs +++ b/crates/rome_js_formatter/src/js/bindings/parameters.rs @@ -1,19 +1,20 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsParameters; use rome_js_syntax::JsParametersFields; -impl FormatNode for JsParameters { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsParameters, formatter: &Formatter) -> FormatResult { let JsParametersFields { l_paren_token, items, r_paren_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_indent( &l_paren_token?, - items.format(formatter)?, + formatted![formatter, [items.format()]]?, &r_paren_token?, ) } diff --git a/crates/rome_js_formatter/src/js/bindings/rest_parameter.rs b/crates/rome_js_formatter/src/js/bindings/rest_parameter.rs index 87d7fbdee366..d5ee9d7a7f61 100644 --- a/crates/rome_js_formatter/src/js/bindings/rest_parameter.rs +++ b/crates/rome_js_formatter/src/js/bindings/rest_parameter.rs @@ -1,21 +1,24 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsRestParameter; use rome_js_syntax::JsRestParameterFields; -impl FormatNode for JsRestParameter { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsRestParameter, formatter: &Formatter) -> FormatResult { let JsRestParameterFields { dotdotdot_token, binding, type_annotation, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - dotdotdot_token.format(formatter)?, - binding.format(formatter)?, - type_annotation + [ + dotdotdot_token.format(), + binding.format(), + type_annotation.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/classes/constructor_class_member.rs b/crates/rome_js_formatter/src/js/classes/constructor_class_member.rs index 81b424718bf4..4568d4ed9fe0 100644 --- a/crates/rome_js_formatter/src/js/classes/constructor_class_member.rs +++ b/crates/rome_js_formatter/src/js/classes/constructor_class_member.rs @@ -1,25 +1,31 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsConstructorClassMember; use rome_js_syntax::JsConstructorClassMemberFields; -impl FormatNode for JsConstructorClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsConstructorClassMember, + formatter: &Formatter, + ) -> FormatResult { let JsConstructorClassMemberFields { modifiers, name, parameters, body, - } = self.as_fields(); + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - name.format(formatter)?, - parameters.format(formatter)?, - space_token(), - body.format(formatter)? + [ + modifiers.format(), + space_token(), + name.format(), + parameters.format(), + space_token(), + body.format() + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/classes/empty_class_member.rs b/crates/rome_js_formatter/src/js/classes/empty_class_member.rs index 3d1fa11d336a..aea8d39d1b41 100644 --- a/crates/rome_js_formatter/src/js/classes/empty_class_member.rs +++ b/crates/rome_js_formatter/src/js/classes/empty_class_member.rs @@ -1,11 +1,15 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsEmptyClassMember; use rome_js_syntax::JsEmptyClassMemberFields; -impl FormatNode for JsEmptyClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsEmptyClassMemberFields { semicolon_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsEmptyClassMember, + formatter: &Formatter, + ) -> FormatResult { + let JsEmptyClassMemberFields { semicolon_token } = node.as_fields(); Ok(formatter.format_replaced(&semicolon_token?, empty_element())) } diff --git a/crates/rome_js_formatter/src/js/classes/extends_clause.rs b/crates/rome_js_formatter/src/js/classes/extends_clause.rs index 138c8442ddb3..6d386494d355 100644 --- a/crates/rome_js_formatter/src/js/classes/extends_clause.rs +++ b/crates/rome_js_formatter/src/js/classes/extends_clause.rs @@ -1,22 +1,25 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsExtendsClause; use rome_js_syntax::JsExtendsClauseFields; -impl FormatNode for JsExtendsClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsExtendsClause, formatter: &Formatter) -> FormatResult { let JsExtendsClauseFields { extends_token, super_class, type_arguments, - } = self.as_fields(); + } = node.as_fields(); Ok(formatted![ formatter, - extends_token.format(formatter)?, - space_token(), - super_class.format(formatter)?, - type_arguments, + [ + extends_token.format(), + space_token(), + super_class.format(), + type_arguments.format(), + ] ]?) } } diff --git a/crates/rome_js_formatter/src/js/classes/getter_class_member.rs b/crates/rome_js_formatter/src/js/classes/getter_class_member.rs index 676f27e28d69..f357256278b7 100644 --- a/crates/rome_js_formatter/src/js/classes/getter_class_member.rs +++ b/crates/rome_js_formatter/src/js/classes/getter_class_member.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsGetterClassMember; use rome_js_syntax::JsGetterClassMemberFields; -impl FormatNode for JsGetterClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsGetterClassMember, + formatter: &Formatter, + ) -> FormatResult { let JsGetterClassMemberFields { modifiers, get_token, @@ -13,20 +17,22 @@ impl FormatNode for JsGetterClassMember { r_paren_token, return_type, body, - } = self.as_fields(); + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - get_token.format(formatter)?, - space_token(), - name.format(formatter)?, - l_paren_token.format(formatter)?, - r_paren_token.format(formatter)?, - return_type, - space_token(), - body.format(formatter)? + [ + modifiers.format(), + space_token(), + get_token.format(), + space_token(), + name.format(), + l_paren_token.format(), + r_paren_token.format(), + return_type.format(), + space_token(), + body.format() + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/classes/method_class_member.rs b/crates/rome_js_formatter/src/js/classes/method_class_member.rs index d3010655f711..e4ec6250951b 100644 --- a/crates/rome_js_formatter/src/js/classes/method_class_member.rs +++ b/crates/rome_js_formatter/src/js/classes/method_class_member.rs @@ -1,14 +1,14 @@ -use crate::format_extensions::FormatOptional; -use crate::{formatted, hard_group_elements, Format}; -use rome_formatter::FormatResult; - -use crate::{space_token, FormatElement, FormatNode, Formatter}; +use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsMethodClassMember; use rome_js_syntax::JsMethodClassMemberFields; -impl FormatNode for JsMethodClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsMethodClassMember, + formatter: &Formatter, + ) -> FormatResult { let JsMethodClassMemberFields { modifiers, async_token, @@ -19,28 +19,25 @@ impl FormatNode for JsMethodClassMember { parameters, return_type_annotation, body, - } = self.as_fields(); - - let async_token = - async_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - - let name = name.format(formatter)?; - let params = parameters.format(formatter)?; - let body = body.format(formatter)?; + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - async_token, - star_token, - name, - question_mark_token, - type_parameters, - params, - return_type_annotation, - space_token(), - body + [ + modifiers.format(), + space_token(), + async_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + star_token.format(), + name.format(), + question_mark_token.format(), + type_parameters.format(), + parameters.format(), + return_type_annotation.format(), + space_token(), + body.format() + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/classes/property_class_member.rs b/crates/rome_js_formatter/src/js/classes/property_class_member.rs index 5f791c817efa..e4859602a5a7 100644 --- a/crates/rome_js_formatter/src/js/classes/property_class_member.rs +++ b/crates/rome_js_formatter/src/js/classes/property_class_member.rs @@ -1,33 +1,37 @@ -use crate::format_extensions::FormatOptional; -use rome_formatter::FormatResult; +use crate::prelude::*; use crate::utils::format_with_semicolon; -use crate::{formatted, space_token, Format, FormatElement, FormatNode, Formatter}; +use crate::FormatNodeFields; use rome_js_syntax::JsPropertyClassMember; use rome_js_syntax::JsPropertyClassMemberFields; -impl FormatNode for JsPropertyClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsPropertyClassMember, + formatter: &Formatter, + ) -> FormatResult { let JsPropertyClassMemberFields { modifiers, name, property_annotation, value, semicolon_token, - } = self.as_fields(); - - let init = value.with_or_empty(|node| formatted![formatter, space_token(), node]); + } = node.as_fields(); format_with_semicolon( formatter, formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - name.format(formatter)?, - property_annotation, - init, + [ + modifiers.format(), + space_token(), + name.format(), + property_annotation.format(), + value + .format() + .with_or_empty(|node| formatted![formatter, [space_token(), node]]), + ] ]?, semicolon_token, ) diff --git a/crates/rome_js_formatter/src/js/classes/setter_class_member.rs b/crates/rome_js_formatter/src/js/classes/setter_class_member.rs index 4d00c50303f5..016bd36f46a8 100644 --- a/crates/rome_js_formatter/src/js/classes/setter_class_member.rs +++ b/crates/rome_js_formatter/src/js/classes/setter_class_member.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsSetterClassMember; use rome_js_syntax::JsSetterClassMemberFields; -impl FormatNode for JsSetterClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsSetterClassMember, + formatter: &Formatter, + ) -> FormatResult { let JsSetterClassMemberFields { modifiers, set_token, @@ -13,20 +17,22 @@ impl FormatNode for JsSetterClassMember { parameter, r_paren_token, body, - } = self.as_fields(); + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - set_token.format(formatter)?, - space_token(), - name.format(formatter)?, - l_paren_token.format(formatter)?, - parameter.format(formatter)?, - r_paren_token.format(formatter)?, - space_token(), - body.format(formatter)?, + [ + modifiers.format(), + space_token(), + set_token.format(), + space_token(), + name.format(), + l_paren_token.format(), + parameter.format(), + r_paren_token.format(), + space_token(), + body.format(), + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/classes/static_initialization_block_class_member.rs b/crates/rome_js_formatter/src/js/classes/static_initialization_block_class_member.rs index 9703b19a082d..c710f9fe5fd8 100644 --- a/crates/rome_js_formatter/src/js/classes/static_initialization_block_class_member.rs +++ b/crates/rome_js_formatter/src/js/classes/static_initialization_block_class_member.rs @@ -1,23 +1,29 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsStaticInitializationBlockClassMember; use rome_js_syntax::JsStaticInitializationBlockClassMemberFields; -impl FormatNode for JsStaticInitializationBlockClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsStaticInitializationBlockClassMember, + formatter: &Formatter, + ) -> FormatResult { let JsStaticInitializationBlockClassMemberFields { static_token, l_curly_token, statements, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); - let static_token = static_token.format(formatter)?; + let static_token = static_token.format(); let separated = formatter.format_delimited_block_indent( &l_curly_token?, - formatter.format_list(statements), + formatter.format_list(&statements), &r_curly_token?, )?; - formatted![formatter, static_token, space_token(), separated] + formatted![formatter, [static_token, space_token(), separated]] } } diff --git a/crates/rome_js_formatter/src/js/declarations/catch_declaration.rs b/crates/rome_js_formatter/src/js/declarations/catch_declaration.rs index 0f1fe32d98cb..cb2e9ac492d0 100644 --- a/crates/rome_js_formatter/src/js/declarations/catch_declaration.rs +++ b/crates/rome_js_formatter/src/js/declarations/catch_declaration.rs @@ -1,20 +1,24 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsCatchDeclaration; use rome_js_syntax::JsCatchDeclarationFields; -impl FormatNode for JsCatchDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsCatchDeclaration, + formatter: &Formatter, + ) -> FormatResult { let JsCatchDeclarationFields { l_paren_token, binding, r_paren_token, type_annotation, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_indent( &l_paren_token?, - formatted![formatter, binding.format(formatter)?, type_annotation]?, + formatted![formatter, [binding.format(), type_annotation.format()]]?, &r_paren_token?, ) } diff --git a/crates/rome_js_formatter/src/js/declarations/class_declaration.rs b/crates/rome_js_formatter/src/js/declarations/class_declaration.rs index 1092c425f616..5d3db5bb3219 100644 --- a/crates/rome_js_formatter/src/js/declarations/class_declaration.rs +++ b/crates/rome_js_formatter/src/js/declarations/class_declaration.rs @@ -1,9 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsAnyClass, JsClassDeclaration}; -impl FormatNode for JsClassDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - JsAnyClass::from(self.clone()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsClassDeclaration, + formatter: &Formatter, + ) -> FormatResult { + formatted![formatter, [JsAnyClass::from(node.clone()).format()]] } } diff --git a/crates/rome_js_formatter/src/js/declarations/class_export_default_declaration.rs b/crates/rome_js_formatter/src/js/declarations/class_export_default_declaration.rs index b02c8314c814..ec250e14cc1f 100644 --- a/crates/rome_js_formatter/src/js/declarations/class_export_default_declaration.rs +++ b/crates/rome_js_formatter/src/js/declarations/class_export_default_declaration.rs @@ -1,10 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsAnyClass; use rome_js_syntax::JsClassExportDefaultDeclaration; -impl FormatNode for JsClassExportDefaultDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - JsAnyClass::from(self.clone()).format(formatter) +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsClassExportDefaultDeclaration, + formatter: &Formatter, + ) -> FormatResult { + formatted![formatter, [JsAnyClass::from(node.clone()).format()]] } } diff --git a/crates/rome_js_formatter/src/js/declarations/for_variable_declaration.rs b/crates/rome_js_formatter/src/js/declarations/for_variable_declaration.rs index 42fd9230343e..c5bbf8fc7c1a 100644 --- a/crates/rome_js_formatter/src/js/declarations/for_variable_declaration.rs +++ b/crates/rome_js_formatter/src/js/declarations/for_variable_declaration.rs @@ -1,20 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsForVariableDeclaration; use rome_js_syntax::JsForVariableDeclarationFields; -impl FormatNode for JsForVariableDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsForVariableDeclaration, + formatter: &Formatter, + ) -> FormatResult { let JsForVariableDeclarationFields { kind_token, declarator, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - kind_token.format(formatter)?, - space_token(), - declarator.format(formatter)?, + [kind_token.format(), space_token(), declarator.format(),] ] } } diff --git a/crates/rome_js_formatter/src/js/declarations/function_declaration.rs b/crates/rome_js_formatter/src/js/declarations/function_declaration.rs index df2e6b85cea8..81a1b2e3e01b 100644 --- a/crates/rome_js_formatter/src/js/declarations/function_declaration.rs +++ b/crates/rome_js_formatter/src/js/declarations/function_declaration.rs @@ -1,9 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsAnyFunction, JsFunctionDeclaration}; -impl FormatNode for JsFunctionDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - JsAnyFunction::from(self.clone()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsFunctionDeclaration, + formatter: &Formatter, + ) -> FormatResult { + formatted![formatter, [JsAnyFunction::from(node.clone()).format()]] } } diff --git a/crates/rome_js_formatter/src/js/declarations/function_export_default_declaration.rs b/crates/rome_js_formatter/src/js/declarations/function_export_default_declaration.rs index bf8f8fb48d47..6b0dab246b99 100644 --- a/crates/rome_js_formatter/src/js/declarations/function_export_default_declaration.rs +++ b/crates/rome_js_formatter/src/js/declarations/function_export_default_declaration.rs @@ -1,10 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsAnyFunction; use rome_js_syntax::JsFunctionExportDefaultDeclaration; -impl FormatNode for JsFunctionExportDefaultDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - JsAnyFunction::from(self.clone()).format(formatter) +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsFunctionExportDefaultDeclaration, + formatter: &Formatter, + ) -> FormatResult { + formatted![formatter, [JsAnyFunction::from(node.clone()).format()]] } } diff --git a/crates/rome_js_formatter/src/js/declarations/variable_declaration.rs b/crates/rome_js_formatter/src/js/declarations/variable_declaration.rs index 0d879964f43d..bc9b5ebaddc5 100644 --- a/crates/rome_js_formatter/src/js/declarations/variable_declaration.rs +++ b/crates/rome_js_formatter/src/js/declarations/variable_declaration.rs @@ -1,17 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsVariableDeclaration; use rome_js_syntax::JsVariableDeclarationFields; -impl FormatNode for JsVariableDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsVariableDeclarationFields { kind, declarators } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsVariableDeclaration, + formatter: &Formatter, + ) -> FormatResult { + let JsVariableDeclarationFields { kind, declarators } = node.as_fields(); formatted![ formatter, - kind.format(formatter)?, - space_token(), - declarators.format(formatter)?, + [kind.format(), space_token(), declarators.format(),] ] } } diff --git a/crates/rome_js_formatter/src/js/expressions/array_expression.rs b/crates/rome_js_formatter/src/js/expressions/array_expression.rs index 5944f79957d1..d330e433dbdb 100644 --- a/crates/rome_js_formatter/src/js/expressions/array_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/array_expression.rs @@ -1,19 +1,23 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsArrayExpression; use rome_js_syntax::JsArrayExpressionFields; -impl FormatNode for JsArrayExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsArrayExpression, + formatter: &Formatter, + ) -> FormatResult { let JsArrayExpressionFields { l_brack_token, elements, r_brack_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_indent( &l_brack_token?, - elements.format(formatter)?, + formatted![formatter, [elements.format()]]?, &r_brack_token?, ) } diff --git a/crates/rome_js_formatter/src/js/expressions/arrow_function_expression.rs b/crates/rome_js_formatter/src/js/expressions/arrow_function_expression.rs index e6c5db671200..d9870e696604 100644 --- a/crates/rome_js_formatter/src/js/expressions/arrow_function_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/arrow_function_expression.rs @@ -1,9 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsAnyFunction, JsArrowFunctionExpression}; -impl FormatNode for JsArrowFunctionExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - JsAnyFunction::from(self.clone()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsArrowFunctionExpression, + formatter: &Formatter, + ) -> FormatResult { + formatted![formatter, [JsAnyFunction::from(node.clone()).format()]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/assignment_expression.rs b/crates/rome_js_formatter/src/js/expressions/assignment_expression.rs index 176bdef2f49e..bbe403b60cc1 100644 --- a/crates/rome_js_formatter/src/js/expressions/assignment_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/assignment_expression.rs @@ -1,22 +1,31 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsAssignmentExpression; use rome_js_syntax::JsAssignmentExpressionFields; -impl FormatNode for JsAssignmentExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsAssignmentExpression, + formatter: &Formatter, + ) -> FormatResult { let JsAssignmentExpressionFields { left, operator_token, right, - } = self.as_fields(); + } = node.as_fields(); Ok(group_elements(formatted![ formatter, - left.format(formatter)?, - space_token(), - operator_token.format(formatter)?, - group_elements(soft_line_indent_or_space(right.format(formatter)?)), + [ + left.format(), + space_token(), + operator_token.format(), + group_elements(soft_line_indent_or_space(formatted![ + formatter, + [right.format()] + ]?)), + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/expressions/await_expression.rs b/crates/rome_js_formatter/src/js/expressions/await_expression.rs index 01fd3ea6fdac..b8ec65eb0d20 100644 --- a/crates/rome_js_formatter/src/js/expressions/await_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/await_expression.rs @@ -1,20 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsAwaitExpression; use rome_js_syntax::JsAwaitExpressionFields; -impl FormatNode for JsAwaitExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsAwaitExpression, + formatter: &Formatter, + ) -> FormatResult { let JsAwaitExpressionFields { await_token, argument, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - await_token.format(formatter)?, - space_token(), - argument.format(formatter)?, + [await_token.format(), space_token(), argument.format(),] ] } } diff --git a/crates/rome_js_formatter/src/js/expressions/big_int_literal_expression.rs b/crates/rome_js_formatter/src/js/expressions/big_int_literal_expression.rs index d82a418d186f..2a840c995718 100644 --- a/crates/rome_js_formatter/src/js/expressions/big_int_literal_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/big_int_literal_expression.rs @@ -3,17 +3,21 @@ use std::borrow::Cow; use crate::prelude::*; use crate::utils::string_utils::ToAsciiLowercaseCow; +use crate::FormatNodeFields; use rome_js_syntax::JsBigIntLiteralExpression; use rome_js_syntax::JsBigIntLiteralExpressionFields; -impl FormatNode for JsBigIntLiteralExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsBigIntLiteralExpressionFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsBigIntLiteralExpression, + formatter: &Formatter, + ) -> FormatResult { + let JsBigIntLiteralExpressionFields { value_token } = node.as_fields(); let value_token = value_token?; let original = value_token.text_trimmed(); match original.to_ascii_lowercase_cow() { - Cow::Borrowed(_) => value_token.format(formatter), + Cow::Borrowed(_) => formatted![formatter, [value_token.format()]], Cow::Owned(lowercase) => Ok(formatter.format_replaced( &value_token, Token::new_dynamic(lowercase, value_token.text_trimmed_range().start()).into(), diff --git a/crates/rome_js_formatter/src/js/expressions/binary_expression.rs b/crates/rome_js_formatter/src/js/expressions/binary_expression.rs index dc6e60d832c3..972d0cfb504e 100644 --- a/crates/rome_js_formatter/src/js/expressions/binary_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/binary_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; use crate::utils::{format_binary_like_expression, JsAnyBinaryLikeExpression}; +use crate::FormatNodeFields; use rome_js_syntax::JsBinaryExpression; -impl FormatNode for JsBinaryExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsBinaryExpression, + formatter: &Formatter, + ) -> FormatResult { format_binary_like_expression( - JsAnyBinaryLikeExpression::JsBinaryExpression(self.clone()), + JsAnyBinaryLikeExpression::JsBinaryExpression(node.clone()), formatter, ) } diff --git a/crates/rome_js_formatter/src/js/expressions/boolean_literal_expression.rs b/crates/rome_js_formatter/src/js/expressions/boolean_literal_expression.rs index 7282488e8793..c2abb757c6f3 100644 --- a/crates/rome_js_formatter/src/js/expressions/boolean_literal_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/boolean_literal_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsBooleanLiteralExpression; use rome_js_syntax::JsBooleanLiteralExpressionFields; -impl FormatNode for JsBooleanLiteralExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsBooleanLiteralExpressionFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsBooleanLiteralExpression, + formatter: &Formatter, + ) -> FormatResult { + let JsBooleanLiteralExpressionFields { value_token } = node.as_fields(); - value_token.format(formatter) + formatted![formatter, [value_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/call_arguments.rs b/crates/rome_js_formatter/src/js/expressions/call_arguments.rs index 667ae1bf5779..2a40886924c9 100644 --- a/crates/rome_js_formatter/src/js/expressions/call_arguments.rs +++ b/crates/rome_js_formatter/src/js/expressions/call_arguments.rs @@ -1,30 +1,33 @@ use crate::prelude::*; use crate::utils::{is_simple_expression, token_has_comments}; +use crate::FormatNodeFields; use rome_js_syntax::JsCallArgumentsFields; use rome_js_syntax::{JsAnyCallArgument, JsCallArguments}; use rome_rowan::{AstSeparatedList, SyntaxResult}; -impl FormatNode for JsCallArguments { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsCallArguments, formatter: &Formatter) -> FormatResult { let JsCallArgumentsFields { l_paren_token, args, r_paren_token, - } = self.as_fields(); + } = node.as_fields(); - if is_simple_function_arguments(self)? { + if is_simple_function_arguments(node)? { return Ok(hard_group_elements(formatted![ formatter, - l_paren_token.format(formatter)?, - args.format(formatter)?, - r_paren_token.format(formatter)?, + [ + l_paren_token.format(), + args.format(), + r_paren_token.format(), + ] ]?)); } formatter.format_delimited_soft_block_indent( &l_paren_token?, - args.format(formatter)?, + formatted![formatter, [args.format()]]?, &r_paren_token?, ) } diff --git a/crates/rome_js_formatter/src/js/expressions/call_expression.rs b/crates/rome_js_formatter/src/js/expressions/call_expression.rs index fe295a86fff5..6091c23601a0 100644 --- a/crates/rome_js_formatter/src/js/expressions/call_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/call_expression.rs @@ -1,11 +1,15 @@ use crate::prelude::*; use crate::utils::format_call_expression; +use crate::FormatNodeFields; use rome_js_syntax::JsCallExpression; use rome_rowan::AstNode; -impl FormatNode for JsCallExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - format_call_expression(self.syntax(), formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsCallExpression, + formatter: &Formatter, + ) -> FormatResult { + format_call_expression(node.syntax(), formatter) } } 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 1d75ec3259f4..c2a26730a99b 100644 --- a/crates/rome_js_formatter/src/js/expressions/class_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/class_expression.rs @@ -1,9 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsAnyClass, JsClassExpression}; -impl FormatNode for JsClassExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - JsAnyClass::from(self.clone()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsClassExpression, + formatter: &Formatter, + ) -> FormatResult { + formatted![formatter, [JsAnyClass::from(node.clone()).format()]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/computed_member_expression.rs b/crates/rome_js_formatter/src/js/expressions/computed_member_expression.rs index 175692021005..d726e5000a4a 100644 --- a/crates/rome_js_formatter/src/js/expressions/computed_member_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/computed_member_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsComputedMemberExpression; use rome_js_syntax::JsComputedMemberExpressionFields; use rome_rowan::AstNode; -impl FormatNode for JsComputedMemberExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let mut current = self.clone(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsComputedMemberExpression, + formatter: &Formatter, + ) -> FormatResult { + let mut current = node.clone(); // Find the left most computed expression while let Some(computed_expression) = @@ -26,15 +30,19 @@ impl FormatNode for JsComputedMemberExpression { let mut formatted = vec![formatted![ formatter, - object.format(formatter)?, - group_elements(formatted![ - formatter, - optional_chain_token, - l_brack_token.format(formatter)?, - soft_line_break(), - soft_block_indent(member.format(formatter)?), - r_brack_token.format(formatter)?, - ]?), + [ + object.format(), + group_elements(formatted![ + formatter, + [ + optional_chain_token.format(), + l_brack_token.format(), + soft_line_break(), + soft_block_indent(formatted![formatter, [member.format()]]?), + r_brack_token.format(), + ] + ]?), + ] ]?]; // Traverse upwards again and concatenate the computed expression until we find the first non-computed expression @@ -44,7 +52,7 @@ impl FormatNode for JsComputedMemberExpression { .and_then(JsComputedMemberExpression::cast) { // Don't traverse up if self is a member of a computed member expression - if current == *self { + if current == *node { break; } @@ -58,11 +66,13 @@ impl FormatNode for JsComputedMemberExpression { formatted.push(group_elements(formatted![ formatter, - optional_chain_token, - l_brack_token.format(formatter)?, - soft_line_break(), - soft_block_indent(member.format(formatter)?), - r_brack_token.format(formatter)?, + [ + optional_chain_token.format(), + l_brack_token.format(), + soft_line_break(), + soft_block_indent(formatted![formatter, [member.format()]]?), + r_brack_token.format(), + ] ]?)); current = parent; diff --git a/crates/rome_js_formatter/src/js/expressions/conditional_expression.rs b/crates/rome_js_formatter/src/js/expressions/conditional_expression.rs index 99c02209fdf8..89fe9570034a 100644 --- a/crates/rome_js_formatter/src/js/expressions/conditional_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/conditional_expression.rs @@ -1,10 +1,14 @@ use crate::prelude::*; use crate::utils::{format_conditional, Conditional}; +use crate::FormatNodeFields; use rome_js_syntax::JsConditionalExpression; -impl FormatNode for JsConditionalExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - format_conditional(Conditional::Expression(self.clone()), formatter, false) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsConditionalExpression, + formatter: &Formatter, + ) -> FormatResult { + format_conditional(Conditional::Expression(node.clone()), formatter, false) } } diff --git a/crates/rome_js_formatter/src/js/expressions/function_expression.rs b/crates/rome_js_formatter/src/js/expressions/function_expression.rs index b3ef1535b030..339c25ad74c2 100644 --- a/crates/rome_js_formatter/src/js/expressions/function_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/function_expression.rs @@ -1,9 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsAnyFunction, JsFunctionExpression}; -impl FormatNode for JsFunctionExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - JsAnyFunction::from(self.clone()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsFunctionExpression, + formatter: &Formatter, + ) -> FormatResult { + formatted![formatter, [JsAnyFunction::from(node.clone()).format()]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/identifier_expression.rs b/crates/rome_js_formatter/src/js/expressions/identifier_expression.rs index f1badc720f58..bddb9a30ba35 100644 --- a/crates/rome_js_formatter/src/js/expressions/identifier_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/identifier_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsIdentifierExpression; use rome_js_syntax::JsIdentifierExpressionFields; -impl FormatNode for JsIdentifierExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsIdentifierExpressionFields { name } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsIdentifierExpression, + formatter: &Formatter, + ) -> FormatResult { + let JsIdentifierExpressionFields { name } = node.as_fields(); - name.format(formatter) + formatted![formatter, [name.format()]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/import_call_expression.rs b/crates/rome_js_formatter/src/js/expressions/import_call_expression.rs index 4842e5d33883..c725ad016623 100644 --- a/crates/rome_js_formatter/src/js/expressions/import_call_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/import_call_expression.rs @@ -1,19 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsImportCallExpression; use rome_js_syntax::JsImportCallExpressionFields; -impl FormatNode for JsImportCallExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsImportCallExpression, + formatter: &Formatter, + ) -> FormatResult { let JsImportCallExpressionFields { import_token, arguments, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - import_token.format(formatter)?, - arguments.format(formatter)?, - ] + formatted![formatter, [import_token.format(), arguments.format(),]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/in_expression.rs b/crates/rome_js_formatter/src/js/expressions/in_expression.rs index 58f98553ca5f..6331a2231166 100644 --- a/crates/rome_js_formatter/src/js/expressions/in_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/in_expression.rs @@ -1,12 +1,13 @@ use crate::prelude::*; use crate::utils::{format_binary_like_expression, JsAnyBinaryLikeExpression}; +use crate::FormatNodeFields; use rome_js_syntax::JsInExpression; -impl FormatNode for JsInExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsInExpression, formatter: &Formatter) -> FormatResult { format_binary_like_expression( - JsAnyBinaryLikeExpression::JsInExpression(self.clone()), + JsAnyBinaryLikeExpression::JsInExpression(node.clone()), formatter, ) } diff --git a/crates/rome_js_formatter/src/js/expressions/instanceof_expression.rs b/crates/rome_js_formatter/src/js/expressions/instanceof_expression.rs index d6a19931d6c9..41eee34b92b8 100644 --- a/crates/rome_js_formatter/src/js/expressions/instanceof_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/instanceof_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; use crate::utils::{format_binary_like_expression, JsAnyBinaryLikeExpression}; +use crate::FormatNodeFields; use rome_js_syntax::JsInstanceofExpression; -impl FormatNode for JsInstanceofExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsInstanceofExpression, + formatter: &Formatter, + ) -> FormatResult { format_binary_like_expression( - JsAnyBinaryLikeExpression::JsInstanceofExpression(self.clone()), + JsAnyBinaryLikeExpression::JsInstanceofExpression(node.clone()), formatter, ) } diff --git a/crates/rome_js_formatter/src/js/expressions/logical_expression.rs b/crates/rome_js_formatter/src/js/expressions/logical_expression.rs index 178ea133d165..e36d87744b85 100644 --- a/crates/rome_js_formatter/src/js/expressions/logical_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/logical_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; use crate::utils::{format_binary_like_expression, JsAnyBinaryLikeExpression}; +use crate::FormatNodeFields; use rome_js_syntax::JsLogicalExpression; -impl FormatNode for JsLogicalExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsLogicalExpression, + formatter: &Formatter, + ) -> FormatResult { format_binary_like_expression( - JsAnyBinaryLikeExpression::JsLogicalExpression(self.clone()), + JsAnyBinaryLikeExpression::JsLogicalExpression(node.clone()), formatter, ) } diff --git a/crates/rome_js_formatter/src/js/expressions/new_expression.rs b/crates/rome_js_formatter/src/js/expressions/new_expression.rs index f64e9f942a0c..98e698eb9907 100644 --- a/crates/rome_js_formatter/src/js/expressions/new_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/new_expression.rs @@ -1,26 +1,29 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsNewExpression; use rome_js_syntax::JsNewExpressionFields; -impl FormatNode for JsNewExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsNewExpression, formatter: &Formatter) -> FormatResult { let JsNewExpressionFields { new_token, callee, type_arguments, arguments, - } = self.as_fields(); - - let arguments = arguments.or_format(|| formatted![formatter, token("("), token(")")]); + } = node.as_fields(); formatted![ formatter, - new_token.format(formatter)?, - space_token(), - callee.format(formatter)?, - type_arguments, - arguments, + [ + new_token.format(), + space_token(), + callee.format(), + type_arguments.format(), + arguments + .format() + .or_format(|| formatted![formatter, [token("("), token(")")]]), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/expressions/null_literal_expression.rs b/crates/rome_js_formatter/src/js/expressions/null_literal_expression.rs index 128910fdfca4..2b16b0cb6317 100644 --- a/crates/rome_js_formatter/src/js/expressions/null_literal_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/null_literal_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsNullLiteralExpression; use rome_js_syntax::JsNullLiteralExpressionFields; -impl FormatNode for JsNullLiteralExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsNullLiteralExpressionFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsNullLiteralExpression, + formatter: &Formatter, + ) -> FormatResult { + let JsNullLiteralExpressionFields { value_token } = node.as_fields(); - value_token.format(formatter) + formatted![formatter, [value_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/number_literal_expression.rs b/crates/rome_js_formatter/src/js/expressions/number_literal_expression.rs index cde17e6c56ae..df6f8c31bd72 100644 --- a/crates/rome_js_formatter/src/js/expressions/number_literal_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/number_literal_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsNumberLiteralExpression; use rome_js_syntax::JsNumberLiteralExpressionFields; -impl FormatNode for JsNumberLiteralExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsNumberLiteralExpressionFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsNumberLiteralExpression, + formatter: &Formatter, + ) -> FormatResult { + let JsNumberLiteralExpressionFields { value_token } = node.as_fields(); - value_token.format(formatter) + formatted![formatter, [value_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/object_expression.rs b/crates/rome_js_formatter/src/js/expressions/object_expression.rs index be73214b77d5..7ce9f2a93769 100644 --- a/crates/rome_js_formatter/src/js/expressions/object_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/object_expression.rs @@ -1,22 +1,34 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsObjectExpression; use rome_js_syntax::JsObjectExpressionFields; -impl FormatNode for JsObjectExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsObjectExpression, + formatter: &Formatter, + ) -> FormatResult { let JsObjectExpressionFields { l_curly_token, members, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); - let members = members.format(formatter)?; + let members_content = formatted![formatter, [members.format()]]?; if members.is_empty() { - formatter.format_delimited_soft_block_indent(&l_curly_token?, members, &r_curly_token?) + formatter.format_delimited_soft_block_indent( + &l_curly_token?, + members_content, + &r_curly_token?, + ) } else { - formatter.format_delimited_soft_block_spaces(&l_curly_token?, members, &r_curly_token?) + formatter.format_delimited_soft_block_spaces( + &l_curly_token?, + members_content, + &r_curly_token?, + ) } } } diff --git a/crates/rome_js_formatter/src/js/expressions/parenthesized_expression.rs b/crates/rome_js_formatter/src/js/expressions/parenthesized_expression.rs index 3c4e7f4503a3..4a84c9550565 100644 --- a/crates/rome_js_formatter/src/js/expressions/parenthesized_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/parenthesized_expression.rs @@ -1,46 +1,54 @@ use crate::prelude::*; use crate::utils::{is_simple_expression, FormatPrecedence}; +use crate::FormatNodeFields; use rome_js_syntax::{ JsAnyExpression, JsAnyLiteralExpression, JsParenthesizedExpression, JsParenthesizedExpressionFields, JsStringLiteralExpression, JsSyntaxKind, JsSyntaxNode, }; use rome_rowan::{AstNode, SyntaxResult}; -impl FormatNode for JsParenthesizedExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsParenthesizedExpression, + formatter: &Formatter, + ) -> FormatResult { let JsParenthesizedExpressionFields { l_paren_token, expression, r_paren_token, - } = self.as_fields(); + } = node.as_fields(); - let parenthesis_can_be_omitted = parenthesis_can_be_omitted(self)?; + let parenthesis_can_be_omitted = parenthesis_can_be_omitted(node)?; let expression = expression?; - if is_simple_parenthesized_expression(self)? { + if is_simple_parenthesized_expression(node)? { Ok(hard_group_elements(formatted![ formatter, - if parenthesis_can_be_omitted { - formatter.format_replaced(&l_paren_token?, empty_element()) - } else { - l_paren_token.format(formatter)? - }, - expression.format(formatter)?, - if parenthesis_can_be_omitted { - formatter.format_replaced(&r_paren_token?, empty_element()) - } else { - r_paren_token.format(formatter)? - }, + [ + if parenthesis_can_be_omitted { + formatter.format_replaced(&l_paren_token?, empty_element()) + } else { + formatted![formatter, [l_paren_token.format()]]? + }, + expression.format(), + if parenthesis_can_be_omitted { + formatter.format_replaced(&r_paren_token?, empty_element()) + } else { + formatted![formatter, [r_paren_token.format()]]? + }, + ] ]?)) } else if parenthesis_can_be_omitted { // we mimic the format delimited utility function formatted![ formatter, - formatter.format_replaced(&l_paren_token?, empty_element()), - group_elements(expression.format(formatter)?), - formatter.format_replaced(&r_paren_token?, empty_element()), + [ + formatter.format_replaced(&l_paren_token?, empty_element()), + group_elements(formatted![formatter, [expression.format()]]?), + formatter.format_replaced(&r_paren_token?, empty_element()), + ] ] } // if the expression inside the parenthesis is a stringLiteralExpression, we should leave it as is rather than @@ -65,14 +73,16 @@ impl FormatNode for JsParenthesizedExpression { else if JsStringLiteralExpression::can_cast(expression.syntax().kind()) { formatted![ formatter, - &l_paren_token, - expression.format(formatter)?, - &r_paren_token, + [ + l_paren_token.format(), + expression.format(), + r_paren_token.format(), + ] ] } else { formatter.format_delimited_soft_block_indent( &l_paren_token?, - expression.format(formatter)?, + formatted![formatter, [expression.format()]]?, &r_paren_token?, ) } diff --git a/crates/rome_js_formatter/src/js/expressions/post_update_expression.rs b/crates/rome_js_formatter/src/js/expressions/post_update_expression.rs index cb4c2ac49e7f..65c7ed781f6a 100644 --- a/crates/rome_js_formatter/src/js/expressions/post_update_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/post_update_expression.rs @@ -1,19 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsPostUpdateExpression; use rome_js_syntax::JsPostUpdateExpressionFields; -impl FormatNode for JsPostUpdateExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsPostUpdateExpression, + formatter: &Formatter, + ) -> FormatResult { let JsPostUpdateExpressionFields { operand, operator_token, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - operand.format(formatter)?, - operator_token.format(formatter)?, - ] + formatted![formatter, [operand.format(), operator_token.format(),]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/pre_update_expression.rs b/crates/rome_js_formatter/src/js/expressions/pre_update_expression.rs index 283f206866d6..917a53c97a41 100644 --- a/crates/rome_js_formatter/src/js/expressions/pre_update_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/pre_update_expression.rs @@ -1,19 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsPreUpdateExpression; use rome_js_syntax::JsPreUpdateExpressionFields; -impl FormatNode for JsPreUpdateExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsPreUpdateExpression, + formatter: &Formatter, + ) -> FormatResult { let JsPreUpdateExpressionFields { operator_token, operand, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - operator_token.format(formatter)?, - operand.format(formatter)?, - ] + formatted![formatter, [operator_token.format(), operand.format(),]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/regex_literal_expression.rs b/crates/rome_js_formatter/src/js/expressions/regex_literal_expression.rs index 3f0079020354..b997ed9d6e78 100644 --- a/crates/rome_js_formatter/src/js/expressions/regex_literal_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/regex_literal_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_formatter::Token; use rome_js_syntax::JsRegexLiteralExpression; use rome_js_syntax::JsRegexLiteralExpressionFields; -impl FormatNode for JsRegexLiteralExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsRegexLiteralExpressionFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsRegexLiteralExpression, + formatter: &Formatter, + ) -> FormatResult { + let JsRegexLiteralExpressionFields { value_token } = node.as_fields(); let value_token = value_token?; let trimmed_raw_string = value_token.text_trimmed(); // find end slash, so we could split our regex literal to two part `body`: raw_string[0..end_slash_pos + 1] and `flags`: raw_string[end_slash_pos + 1..] @@ -14,7 +18,7 @@ impl FormatNode for JsRegexLiteralExpression { let ends_with_slash = trimmed_raw_string.ends_with('/'); // this means that we have a regex literal with no flags if ends_with_slash { - return value_token.format(formatter); + return formatted![formatter, [value_token.format()]]; } // SAFETY: a valid regex literal must have a end slash let end_slash_pos = trimmed_raw_string.rfind('/').unwrap(); diff --git a/crates/rome_js_formatter/src/js/expressions/sequence_expression.rs b/crates/rome_js_formatter/src/js/expressions/sequence_expression.rs index b5fccab7b52a..5186ee2fc689 100644 --- a/crates/rome_js_formatter/src/js/expressions/sequence_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/sequence_expression.rs @@ -1,11 +1,15 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsSequenceExpression, JsSequenceExpressionFields}; use rome_rowan::AstNode; -impl FormatNode for JsSequenceExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let mut current = self.clone(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsSequenceExpression, + formatter: &Formatter, + ) -> FormatResult { + let mut current = node.clone(); // Find the left most sequence expression while let Some(sequence_expression) = @@ -21,12 +25,15 @@ impl FormatNode for JsSequenceExpression { right, } = current.as_fields(); - let mut formatted = vec![ - left.format(formatter)?, - comma_token.format(formatter)?, - space_token(), - right.format(formatter)?, - ]; + let mut formatted = vec![formatted![ + formatter, + [ + left.format(), + comma_token.format(), + space_token(), + right.format(), + ] + ]?]; // Traverse upwards again and concatenate the sequence expression until we find the first non-sequence expression while let Some(parent) = current.syntax().parent() { @@ -39,9 +46,7 @@ impl FormatNode for JsSequenceExpression { formatted.push(formatted![ formatter, - comma_token.format(formatter)?, - space_token(), - right.format(formatter)? + [comma_token.format(), space_token(), right.format()] ]?); current = parent_sequence; diff --git a/crates/rome_js_formatter/src/js/expressions/static_member_expression.rs b/crates/rome_js_formatter/src/js/expressions/static_member_expression.rs index f014b5ea3d27..99f3c4bbbafb 100644 --- a/crates/rome_js_formatter/src/js/expressions/static_member_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/static_member_expression.rs @@ -3,16 +3,20 @@ use rome_rowan::AstNode; use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsStaticMemberExpression; use rome_js_syntax::JsStaticMemberExpressionFields; -impl FormatNode for JsStaticMemberExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsStaticMemberExpression, + formatter: &Formatter, + ) -> FormatResult { let JsStaticMemberExpressionFields { object, operator_token, member, - } = self.as_fields(); + } = node.as_fields(); let object_syntax = object.clone()?.syntax().clone(); @@ -24,27 +28,27 @@ impl FormatNode for JsStaticMemberExpression { let has_operator_leading_trivia = operator_token.clone()?.leading_trivia().pieces().len() > 0; - let formatted_object = object?.format(formatter)?; + let formatted_object = formatted![formatter, [object?.format()]]?; if is_object_number_literal && (has_object_trailing_trivia || has_operator_leading_trivia) { let (object_leading, object_content, object_trailing) = formatted_object.split_trivia(); Ok(group_elements(formatted![ formatter, - object_leading, - token("("), - object_content, - token(")"), - object_trailing, - operator_token.format(formatter)?, - member.format(formatter)?, + [ + object_leading, + token("("), + object_content, + token(")"), + object_trailing, + operator_token.format(), + member.format(), + ] ]?)) } else { Ok(group_elements(formatted![ formatter, - formatted_object, - operator_token.format(formatter)?, - member.format(formatter)?, + [formatted_object, operator_token.format(), member.format(),] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/expressions/string_literal_expression.rs b/crates/rome_js_formatter/src/js/expressions/string_literal_expression.rs index 654669ec7f30..a1e0cd7d1e44 100644 --- a/crates/rome_js_formatter/src/js/expressions/string_literal_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/string_literal_expression.rs @@ -1,17 +1,21 @@ use crate::prelude::*; use crate::utils::format_string_literal_token; +use crate::FormatNodeFields; use rome_js_syntax::JsExpressionStatement; use rome_js_syntax::JsStringLiteralExpression; use rome_js_syntax::JsStringLiteralExpressionFields; use rome_rowan::AstNode; -impl FormatNode for JsStringLiteralExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsStringLiteralExpressionFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsStringLiteralExpression, + formatter: &Formatter, + ) -> FormatResult { + let JsStringLiteralExpressionFields { value_token } = node.as_fields(); let value_token = value_token?; - let syntax_node = self.syntax(); + let syntax_node = node.syntax(); let parent = syntax_node.parent(); let needs_parenthesis = parent.and_then(JsExpressionStatement::cast).is_some(); diff --git a/crates/rome_js_formatter/src/js/expressions/super_expression.rs b/crates/rome_js_formatter/src/js/expressions/super_expression.rs index ac0e5322a006..65ee0d73558e 100644 --- a/crates/rome_js_formatter/src/js/expressions/super_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/super_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsSuperExpression; use rome_js_syntax::JsSuperExpressionFields; -impl FormatNode for JsSuperExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsSuperExpressionFields { super_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsSuperExpression, + formatter: &Formatter, + ) -> FormatResult { + let JsSuperExpressionFields { super_token } = node.as_fields(); - super_token.format(formatter) + formatted![formatter, [super_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/template.rs b/crates/rome_js_formatter/src/js/expressions/template.rs index 7e8505369be9..b4743b1e0dd7 100644 --- a/crates/rome_js_formatter/src/js/expressions/template.rs +++ b/crates/rome_js_formatter/src/js/expressions/template.rs @@ -1,28 +1,31 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsTemplate; use rome_js_syntax::JsTemplateFields; -impl FormatNode for JsTemplate { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsTemplate, formatter: &Formatter) -> FormatResult { let JsTemplateFields { tag, type_arguments, l_tick_token, elements, r_tick_token, - } = self.as_fields(); + } = node.as_fields(); - let l_tick = l_tick_token.format(formatter)?; - let r_tick = r_tick_token.format(formatter)?; + let l_tick = l_tick_token.format(); + let r_tick = r_tick_token.format(); Ok(hard_group_elements(formatted![ formatter, - tag, - type_arguments, - l_tick, - concat_elements(formatter.format_all(elements)?), - r_tick + [ + tag.format(), + type_arguments.format(), + l_tick, + concat_elements(formatter.format_all(elements.iter().formatted())?), + r_tick + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/expressions/template_chunk_element.rs b/crates/rome_js_formatter/src/js/expressions/template_chunk_element.rs index 6b4a698f3cca..33702d41117e 100644 --- a/crates/rome_js_formatter/src/js/expressions/template_chunk_element.rs +++ b/crates/rome_js_formatter/src/js/expressions/template_chunk_element.rs @@ -1,13 +1,17 @@ use crate::prelude::*; use crate::utils::format_template_chunk; +use crate::FormatNodeFields; use rome_js_syntax::{JsTemplateChunkElement, JsTemplateChunkElementFields}; -impl FormatNode for JsTemplateChunkElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsTemplateChunkElement, + formatter: &Formatter, + ) -> FormatResult { let JsTemplateChunkElementFields { template_chunk_token, - } = self.as_fields(); + } = node.as_fields(); let chunk = template_chunk_token?; format_template_chunk(chunk, formatter) diff --git a/crates/rome_js_formatter/src/js/expressions/template_element.rs b/crates/rome_js_formatter/src/js/expressions/template_element.rs index 7d873451e43e..d6e796bb39e1 100644 --- a/crates/rome_js_formatter/src/js/expressions/template_element.rs +++ b/crates/rome_js_formatter/src/js/expressions/template_element.rs @@ -1,9 +1,13 @@ use crate::prelude::*; use crate::utils::{format_template_literal, TemplateElement}; +use crate::FormatNodeFields; use rome_js_syntax::JsTemplateElement; -impl FormatNode for JsTemplateElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - format_template_literal(TemplateElement::Js(self.clone()), formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsTemplateElement, + formatter: &Formatter, + ) -> FormatResult { + format_template_literal(TemplateElement::Js(node.clone()), formatter) } } diff --git a/crates/rome_js_formatter/src/js/expressions/this_expression.rs b/crates/rome_js_formatter/src/js/expressions/this_expression.rs index a76c2c248478..79e9cd3d0b6f 100644 --- a/crates/rome_js_formatter/src/js/expressions/this_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/this_expression.rs @@ -1,12 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsThisExpression; use rome_js_syntax::JsThisExpressionFields; -impl FormatNode for JsThisExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsThisExpressionFields { this_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsThisExpression, + formatter: &Formatter, + ) -> FormatResult { + let JsThisExpressionFields { this_token } = node.as_fields(); - this_token.format(formatter) + formatted![formatter, [this_token.format()]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/unary_expression.rs b/crates/rome_js_formatter/src/js/expressions/unary_expression.rs index 2a9791f15fb6..1bfb28dc3881 100644 --- a/crates/rome_js_formatter/src/js/expressions/unary_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/unary_expression.rs @@ -1,18 +1,22 @@ use crate::prelude::*; use crate::utils::is_simple_expression; +use crate::FormatNodeFields; use rome_js_syntax::JsPreUpdateOperator; use rome_js_syntax::{JsAnyExpression, JsUnaryExpression}; use rome_js_syntax::{JsUnaryExpressionFields, JsUnaryOperator}; -impl FormatNode for JsUnaryExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsUnaryExpression, + formatter: &Formatter, + ) -> FormatResult { let JsUnaryExpressionFields { operator_token, argument, - } = self.as_fields(); + } = node.as_fields(); - let operation = self.operator()?; + let operation = node.operator()?; let operator_token = operator_token?; let argument = argument?; @@ -25,9 +29,7 @@ impl FormatNode for JsUnaryExpression { if is_keyword_operator { return formatted![ formatter, - operator_token.format(formatter)?, - space_token(), - argument.format(formatter)?, + [operator_token.format(), space_token(), argument.format(),] ]; } @@ -57,31 +59,33 @@ impl FormatNode for JsUnaryExpression { let parenthesized = if is_simple_expression(argument.clone())? { formatted![ formatter, - operator_token.format(formatter)?, - token("("), - argument.format(formatter)?, - token(")"), + [ + operator_token.format(), + token("("), + argument.format(), + token(")"), + ] ] } else { formatted![ formatter, - operator_token.format(formatter)?, - group_elements(formatted![ - formatter, - token("("), - soft_block_indent(argument.format(formatter)?), - token(")"), - ]?), + [ + operator_token.format(), + group_elements(formatted![ + formatter, + [ + token("("), + soft_block_indent(formatted![formatter, [argument.format()]]?), + token(")"), + ] + ]?), + ] ] }; return parenthesized; } - formatted![ - formatter, - operator_token.format(formatter)?, - argument.format(formatter)?, - ] + formatted![formatter, [operator_token.format(), argument.format(),]] } } diff --git a/crates/rome_js_formatter/src/js/expressions/yield_argument.rs b/crates/rome_js_formatter/src/js/expressions/yield_argument.rs index e618ac8e5458..2212cffbb87c 100644 --- a/crates/rome_js_formatter/src/js/expressions/yield_argument.rs +++ b/crates/rome_js_formatter/src/js/expressions/yield_argument.rs @@ -1,20 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsYieldArgument; use rome_js_syntax::JsYieldArgumentFields; -impl FormatNode for JsYieldArgument { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsYieldArgument, formatter: &Formatter) -> FormatResult { let JsYieldArgumentFields { star_token, expression, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - star_token, - space_token(), - expression.format(formatter)? + [star_token.format(), space_token(), expression.format()] ] } } diff --git a/crates/rome_js_formatter/src/js/expressions/yield_expression.rs b/crates/rome_js_formatter/src/js/expressions/yield_expression.rs index cc4fe4635273..520da9519151 100644 --- a/crates/rome_js_formatter/src/js/expressions/yield_expression.rs +++ b/crates/rome_js_formatter/src/js/expressions/yield_expression.rs @@ -1,15 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsYieldExpression; use rome_js_syntax::JsYieldExpressionFields; -impl FormatNode for JsYieldExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsYieldExpression, + formatter: &Formatter, + ) -> FormatResult { let JsYieldExpressionFields { yield_token, argument, - } = self.as_fields(); + } = node.as_fields(); - formatted![formatter, yield_token.format(formatter)?, argument] + formatted![formatter, [yield_token.format(), argument.format()]] } } diff --git a/crates/rome_js_formatter/src/js/lists/array_assignment_pattern_element_list.rs b/crates/rome_js_formatter/src/js/lists/array_assignment_pattern_element_list.rs index 9804fd407463..ebaca652e1e0 100644 --- a/crates/rome_js_formatter/src/js/lists/array_assignment_pattern_element_list.rs +++ b/crates/rome_js_formatter/src/js/lists/array_assignment_pattern_element_list.rs @@ -1,9 +1,13 @@ +use crate::generated::FormatJsArrayAssignmentPatternElementList; use crate::prelude::*; use crate::utils::array::format_array_node; use rome_js_syntax::JsArrayAssignmentPatternElementList; -impl Format for JsArrayAssignmentPatternElementList { - fn format(&self, formatter: &Formatter) -> FormatResult { - format_array_node(self, formatter) +impl FormatRule for FormatJsArrayAssignmentPatternElementList { + fn format( + node: &JsArrayAssignmentPatternElementList, + formatter: &Formatter, + ) -> FormatResult { + format_array_node(node, formatter) } } diff --git a/crates/rome_js_formatter/src/js/lists/array_binding_pattern_element_list.rs b/crates/rome_js_formatter/src/js/lists/array_binding_pattern_element_list.rs index e8eb35a41d30..8fa4599f1bc2 100644 --- a/crates/rome_js_formatter/src/js/lists/array_binding_pattern_element_list.rs +++ b/crates/rome_js_formatter/src/js/lists/array_binding_pattern_element_list.rs @@ -1,9 +1,13 @@ +use crate::generated::FormatJsArrayBindingPatternElementList; use crate::prelude::*; use crate::utils::array::format_array_node; use rome_js_syntax::JsArrayBindingPatternElementList; -impl Format for JsArrayBindingPatternElementList { - fn format(&self, formatter: &Formatter) -> FormatResult { - format_array_node(self, formatter) +impl FormatRule for FormatJsArrayBindingPatternElementList { + fn format( + node: &JsArrayBindingPatternElementList, + formatter: &Formatter, + ) -> FormatResult { + format_array_node(node, formatter) } } diff --git a/crates/rome_js_formatter/src/js/lists/array_element_list.rs b/crates/rome_js_formatter/src/js/lists/array_element_list.rs index 0245e908ef04..f66945b5fc0d 100644 --- a/crates/rome_js_formatter/src/js/lists/array_element_list.rs +++ b/crates/rome_js_formatter/src/js/lists/array_element_list.rs @@ -1,26 +1,24 @@ -use rome_formatter::FormatResult; +use crate::prelude::*; use std::convert::Infallible; use crate::formatter::TrailingSeparator; use crate::utils::array::format_array_node; -use crate::{ - fill_elements, token, utils::has_formatter_trivia, Format, FormatElement, Formatter, - JsFormatter, -}; +use crate::generated::FormatJsArrayElementList; +use crate::utils::has_formatter_trivia; use rome_js_syntax::{JsAnyExpression, JsArrayElementList}; use rome_rowan::{AstNode, AstSeparatedList}; -impl Format for JsArrayElementList { - fn format(&self, formatter: &Formatter) -> FormatResult { - if !has_formatter_trivia(self.syntax()) && can_print_fill(self) { +impl FormatRule for FormatJsArrayElementList { + fn format(node: &JsArrayElementList, formatter: &Formatter) -> FormatResult { + if !has_formatter_trivia(node.syntax()) && can_print_fill(node) { return Ok(fill_elements( // Using format_separated is valid in this case as can_print_fill does not allow holes - formatter.format_separated(self, || token(","), TrailingSeparator::default())?, + formatter.format_separated(node, || token(","), TrailingSeparator::default())?, )); } - format_array_node(self, formatter) + format_array_node(node, formatter) } } diff --git a/crates/rome_js_formatter/src/js/lists/call_argument_list.rs b/crates/rome_js_formatter/src/js/lists/call_argument_list.rs index edd26ea61f1b..1737db26bc06 100644 --- a/crates/rome_js_formatter/src/js/lists/call_argument_list.rs +++ b/crates/rome_js_formatter/src/js/lists/call_argument_list.rs @@ -1,12 +1,13 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsCallArgumentList; use crate::prelude::*; use rome_js_syntax::JsCallArgumentList; -impl Format for JsCallArgumentList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsCallArgumentList { + fn format(node: &JsCallArgumentList, formatter: &Formatter) -> FormatResult { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::default())?, + formatter.format_separated(node, || token(","), TrailingSeparator::default())?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/class_member_list.rs b/crates/rome_js_formatter/src/js/lists/class_member_list.rs index a2c54692c974..960d9c3bbe51 100644 --- a/crates/rome_js_formatter/src/js/lists/class_member_list.rs +++ b/crates/rome_js_formatter/src/js/lists/class_member_list.rs @@ -1,7 +1,9 @@ +use crate::generated::FormatJsClassMemberList; use crate::prelude::*; use rome_js_syntax::JsClassMemberList; -impl Format for JsClassMemberList { - fn format(&self, formatter: &Formatter) -> FormatResult { - Ok(formatter.format_list(self.clone())) + +impl FormatRule for FormatJsClassMemberList { + fn format(node: &JsClassMemberList, formatter: &Formatter) -> FormatResult { + Ok(formatter.format_list(node)) } } diff --git a/crates/rome_js_formatter/src/js/lists/constructor_modifier_list.rs b/crates/rome_js_formatter/src/js/lists/constructor_modifier_list.rs index 6a2cc40859db..33576d0600cd 100644 --- a/crates/rome_js_formatter/src/js/lists/constructor_modifier_list.rs +++ b/crates/rome_js_formatter/src/js/lists/constructor_modifier_list.rs @@ -1,12 +1,16 @@ +use crate::generated::FormatJsConstructorModifierList; use crate::prelude::*; use rome_js_syntax::JsConstructorModifierList; use rome_rowan::AstNodeList; -impl Format for JsConstructorModifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsConstructorModifierList { + fn format( + node: &JsConstructorModifierList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( space_token(), - formatter.format_all(self.iter())?, + formatter.format_all(node.iter().formatted())?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/constructor_parameter_list.rs b/crates/rome_js_formatter/src/js/lists/constructor_parameter_list.rs index d0db8f3dca57..c29fcd6cf462 100644 --- a/crates/rome_js_formatter/src/js/lists/constructor_parameter_list.rs +++ b/crates/rome_js_formatter/src/js/lists/constructor_parameter_list.rs @@ -1,12 +1,16 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsConstructorParameterList; use crate::prelude::*; use rome_js_syntax::JsConstructorParameterList; -impl Format for JsConstructorParameterList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsConstructorParameterList { + fn format( + node: &JsConstructorParameterList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::default())?, + formatter.format_separated(node, || token(","), TrailingSeparator::default())?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/directive_list.rs b/crates/rome_js_formatter/src/js/lists/directive_list.rs index 796f5f02b85d..eb288ea3720c 100644 --- a/crates/rome_js_formatter/src/js/lists/directive_list.rs +++ b/crates/rome_js_formatter/src/js/lists/directive_list.rs @@ -1,11 +1,12 @@ +use crate::generated::FormatJsDirectiveList; use crate::prelude::*; use rome_js_syntax::JsDirectiveList; use rome_rowan::{AstNode, AstNodeList}; -impl Format for JsDirectiveList { - fn format(&self, formatter: &Formatter) -> FormatResult { - if !self.is_empty() { - let syntax_node = self.syntax(); +impl FormatRule for FormatJsDirectiveList { + fn format(node: &JsDirectiveList, formatter: &Formatter) -> FormatResult { + if !node.is_empty() { + let syntax_node = node.syntax(); let next_sibling = syntax_node.next_sibling(); // if next_sibling's first leading_trivia has more than one new_line, we should add an extra empty line at the end of // JsDirectiveList, for example: @@ -24,13 +25,15 @@ impl Format for JsDirectiveList { }; formatted![ formatter, - formatter.format_list(self.clone()), - hard_line_break(), - if need_extra_empty_line { - empty_line() - } else { - empty_element() - } + [ + formatter.format_list(node), + hard_line_break(), + if need_extra_empty_line { + empty_line() + } else { + empty_element() + } + ] ] } else { Ok(empty_element()) diff --git a/crates/rome_js_formatter/src/js/lists/export_named_from_specifier_list.rs b/crates/rome_js_formatter/src/js/lists/export_named_from_specifier_list.rs index 808423e7bb21..2912894d31ea 100644 --- a/crates/rome_js_formatter/src/js/lists/export_named_from_specifier_list.rs +++ b/crates/rome_js_formatter/src/js/lists/export_named_from_specifier_list.rs @@ -1,12 +1,16 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsExportNamedFromSpecifierList; use crate::prelude::*; use rome_js_syntax::JsExportNamedFromSpecifierList; -impl Format for JsExportNamedFromSpecifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsExportNamedFromSpecifierList { + fn format( + node: &JsExportNamedFromSpecifierList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::default())?, + formatter.format_separated(node, || token(","), TrailingSeparator::default())?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/export_named_specifier_list.rs b/crates/rome_js_formatter/src/js/lists/export_named_specifier_list.rs index 5c61e9661e2b..d868bc086961 100644 --- a/crates/rome_js_formatter/src/js/lists/export_named_specifier_list.rs +++ b/crates/rome_js_formatter/src/js/lists/export_named_specifier_list.rs @@ -1,12 +1,16 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsExportNamedSpecifierList; use crate::prelude::*; use rome_js_syntax::JsExportNamedSpecifierList; -impl Format for JsExportNamedSpecifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsExportNamedSpecifierList { + fn format( + node: &JsExportNamedSpecifierList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::default())?, + formatter.format_separated(node, || token(","), TrailingSeparator::default())?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/import_assertion_entry_list.rs b/crates/rome_js_formatter/src/js/lists/import_assertion_entry_list.rs index c996c3bd839d..3786b74d12ee 100644 --- a/crates/rome_js_formatter/src/js/lists/import_assertion_entry_list.rs +++ b/crates/rome_js_formatter/src/js/lists/import_assertion_entry_list.rs @@ -1,12 +1,16 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsImportAssertionEntryList; use crate::prelude::*; use rome_js_syntax::JsImportAssertionEntryList; -impl Format for JsImportAssertionEntryList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsImportAssertionEntryList { + fn format( + node: &JsImportAssertionEntryList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::default())?, + formatter.format_separated(node, || token(","), TrailingSeparator::default())?, )) } } 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 47c5c1d76d8c..e70082c0fcf5 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,12 +1,13 @@ +use crate::generated::FormatJsMethodModifierList; use crate::prelude::*; use crate::utils::sort_modifiers_by_precedence; use rome_js_syntax::JsMethodModifierList; -impl Format for JsMethodModifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsMethodModifierList { + fn format(node: &JsMethodModifierList, formatter: &Formatter) -> FormatResult { Ok(join_elements( space_token(), - formatter.format_all(sort_modifiers_by_precedence(self))?, + formatter.format_all(sort_modifiers_by_precedence(node).into_iter().formatted())?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/module_item_list.rs b/crates/rome_js_formatter/src/js/lists/module_item_list.rs index b9edb34d28de..0b6ca0e9901a 100644 --- a/crates/rome_js_formatter/src/js/lists/module_item_list.rs +++ b/crates/rome_js_formatter/src/js/lists/module_item_list.rs @@ -1,7 +1,9 @@ +use crate::generated::FormatJsModuleItemList; use crate::prelude::*; use rome_js_syntax::JsModuleItemList; -impl Format for JsModuleItemList { - fn format(&self, formatter: &Formatter) -> FormatResult { - Ok(formatter.format_list(self.clone())) + +impl FormatRule for FormatJsModuleItemList { + fn format(node: &JsModuleItemList, formatter: &Formatter) -> FormatResult { + Ok(formatter.format_list(node)) } } diff --git a/crates/rome_js_formatter/src/js/lists/named_import_specifier_list.rs b/crates/rome_js_formatter/src/js/lists/named_import_specifier_list.rs index c60a59b179de..ba8cbe1a2ad6 100644 --- a/crates/rome_js_formatter/src/js/lists/named_import_specifier_list.rs +++ b/crates/rome_js_formatter/src/js/lists/named_import_specifier_list.rs @@ -1,12 +1,16 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsNamedImportSpecifierList; use crate::prelude::*; use rome_js_syntax::JsNamedImportSpecifierList; -impl Format for JsNamedImportSpecifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsNamedImportSpecifierList { + fn format( + node: &JsNamedImportSpecifierList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::default())?, + formatter.format_separated(node, || token(","), TrailingSeparator::default())?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/object_assignment_pattern_property_list.rs b/crates/rome_js_formatter/src/js/lists/object_assignment_pattern_property_list.rs index deec0e7bd17f..6229a6d639b4 100644 --- a/crates/rome_js_formatter/src/js/lists/object_assignment_pattern_property_list.rs +++ b/crates/rome_js_formatter/src/js/lists/object_assignment_pattern_property_list.rs @@ -1,11 +1,17 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsObjectAssignmentPatternPropertyList; use crate::prelude::*; use rome_js_syntax::{JsAnyObjectAssignmentPatternMember, JsObjectAssignmentPatternPropertyList}; -impl Format for JsObjectAssignmentPatternPropertyList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule + for FormatJsObjectAssignmentPatternPropertyList +{ + fn format( + node: &JsObjectAssignmentPatternPropertyList, + formatter: &Formatter, + ) -> FormatResult { // The trailing separator is disallowed after a rest element - let has_trailing_rest = match self.into_iter().last() { + let has_trailing_rest = match node.into_iter().last() { Some(elem) => matches!( elem?, JsAnyObjectAssignmentPatternMember::JsObjectAssignmentPatternRest(_) @@ -21,7 +27,7 @@ impl Format for JsObjectAssignmentPatternPropertyList { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), trailing_separator)?, + formatter.format_separated(node, || token(","), trailing_separator)?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/object_binding_pattern_property_list.rs b/crates/rome_js_formatter/src/js/lists/object_binding_pattern_property_list.rs index a3e0d338b94c..ea0574dd94f1 100644 --- a/crates/rome_js_formatter/src/js/lists/object_binding_pattern_property_list.rs +++ b/crates/rome_js_formatter/src/js/lists/object_binding_pattern_property_list.rs @@ -1,11 +1,15 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsObjectBindingPatternPropertyList; use crate::prelude::*; use rome_js_syntax::{JsAnyObjectBindingPatternMember, JsObjectBindingPatternPropertyList}; -impl Format for JsObjectBindingPatternPropertyList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsObjectBindingPatternPropertyList { + fn format( + node: &JsObjectBindingPatternPropertyList, + formatter: &Formatter, + ) -> FormatResult { // The trailing separator is disallowed after a rest element - let has_trailing_rest = match self.into_iter().last() { + let has_trailing_rest = match node.into_iter().last() { Some(elem) => matches!( elem?, JsAnyObjectBindingPatternMember::JsObjectBindingPatternRest(_) @@ -21,7 +25,7 @@ impl Format for JsObjectBindingPatternPropertyList { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), trailing_separator)?, + formatter.format_separated(node, || token(","), trailing_separator)?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/object_member_list.rs b/crates/rome_js_formatter/src/js/lists/object_member_list.rs index 1db8deb41c03..e45900582289 100644 --- a/crates/rome_js_formatter/src/js/lists/object_member_list.rs +++ b/crates/rome_js_formatter/src/js/lists/object_member_list.rs @@ -1,15 +1,16 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsObjectMemberList; use crate::prelude::*; use rome_js_syntax::JsObjectMemberList; use rome_rowan::{AstNode, AstSeparatedList}; -impl Format for JsObjectMemberList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsObjectMemberList { + fn format(node: &JsObjectMemberList, formatter: &Formatter) -> FormatResult { let members = - formatter.format_separated(self, || token(","), TrailingSeparator::default())?; + formatter.format_separated(node, || token(","), TrailingSeparator::default())?; Ok(join_elements_soft_line( - self.elements() + node.elements() // This unwrap is guarded by the call to format_separated above .map(|node| node.node().unwrap().syntax().clone()) .zip(members), diff --git a/crates/rome_js_formatter/src/js/lists/parameter_list.rs b/crates/rome_js_formatter/src/js/lists/parameter_list.rs index 889ac19c4643..ee275a2bf767 100644 --- a/crates/rome_js_formatter/src/js/lists/parameter_list.rs +++ b/crates/rome_js_formatter/src/js/lists/parameter_list.rs @@ -1,11 +1,12 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatJsParameterList; use crate::prelude::*; use rome_js_syntax::{JsAnyParameter, JsParameterList}; -impl Format for JsParameterList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsParameterList { + fn format(node: &JsParameterList, formatter: &Formatter) -> FormatResult { // The trailing separator is disallowed if the last element in the list is a rest parameter - let has_trailing_rest = match self.into_iter().last() { + let has_trailing_rest = match node.into_iter().last() { Some(elem) => matches!(elem?, JsAnyParameter::JsRestParameter(_)), None => false, }; @@ -18,7 +19,7 @@ impl Format for JsParameterList { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), trailing_separator)?, + formatter.format_separated(node, || token(","), trailing_separator)?, )) } } 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 a05ff19ae9e5..04734d477bbf 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,12 +1,13 @@ +use crate::generated::FormatJsPropertyModifierList; use crate::prelude::*; use crate::utils::sort_modifiers_by_precedence; use rome_js_syntax::JsPropertyModifierList; -impl Format for JsPropertyModifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatJsPropertyModifierList { + fn format(node: &JsPropertyModifierList, formatter: &Formatter) -> FormatResult { Ok(join_elements( space_token(), - formatter.format_all(sort_modifiers_by_precedence(self))?, + formatter.format_all(sort_modifiers_by_precedence(node).into_iter().formatted())?, )) } } diff --git a/crates/rome_js_formatter/src/js/lists/statement_list.rs b/crates/rome_js_formatter/src/js/lists/statement_list.rs index 9dc27d690745..0b71e2b34868 100644 --- a/crates/rome_js_formatter/src/js/lists/statement_list.rs +++ b/crates/rome_js_formatter/src/js/lists/statement_list.rs @@ -1,7 +1,9 @@ +use crate::generated::FormatJsStatementList; use crate::prelude::*; use rome_js_syntax::JsStatementList; -impl Format for JsStatementList { - fn format(&self, formatter: &Formatter) -> FormatResult { - Ok(formatter.format_list(self.clone())) + +impl FormatRule for FormatJsStatementList { + fn format(node: &JsStatementList, formatter: &Formatter) -> FormatResult { + Ok(formatter.format_list(node)) } } diff --git a/crates/rome_js_formatter/src/js/lists/switch_case_list.rs b/crates/rome_js_formatter/src/js/lists/switch_case_list.rs index 17518a1cff4c..1a272ebd7fb6 100644 --- a/crates/rome_js_formatter/src/js/lists/switch_case_list.rs +++ b/crates/rome_js_formatter/src/js/lists/switch_case_list.rs @@ -1,7 +1,9 @@ +use crate::generated::FormatJsSwitchCaseList; use crate::prelude::*; use rome_js_syntax::JsSwitchCaseList; -impl Format for JsSwitchCaseList { - fn format(&self, formatter: &Formatter) -> FormatResult { - Ok(formatter.format_list(self.clone())) + +impl FormatRule for FormatJsSwitchCaseList { + fn format(node: &JsSwitchCaseList, formatter: &Formatter) -> FormatResult { + Ok(formatter.format_list(node)) } } diff --git a/crates/rome_js_formatter/src/js/lists/template_element_list.rs b/crates/rome_js_formatter/src/js/lists/template_element_list.rs index 1237cb94faba..b2a3813ffd26 100644 --- a/crates/rome_js_formatter/src/js/lists/template_element_list.rs +++ b/crates/rome_js_formatter/src/js/lists/template_element_list.rs @@ -1,7 +1,9 @@ +use crate::generated::FormatJsTemplateElementList; use crate::prelude::*; use rome_js_syntax::JsTemplateElementList; -impl Format for JsTemplateElementList { - fn format(&self, formatter: &Formatter) -> FormatResult { - Ok(formatter.format_list(self.clone())) + +impl FormatRule for FormatJsTemplateElementList { + fn format(node: &JsTemplateElementList, formatter: &Formatter) -> FormatResult { + Ok(formatter.format_list(node)) } } diff --git a/crates/rome_js_formatter/src/js/lists/variable_declarator_list.rs b/crates/rome_js_formatter/src/js/lists/variable_declarator_list.rs index 1d1b68e28f08..8f5eeda641d4 100644 --- a/crates/rome_js_formatter/src/js/lists/variable_declarator_list.rs +++ b/crates/rome_js_formatter/src/js/lists/variable_declarator_list.rs @@ -1,39 +1,40 @@ -use crate::{ - concat_elements, empty_element, format_extensions::FormatOptional, formatted, group_elements, - indent, join_elements, soft_line_break_or_space, token, Format, FormatElement, Formatter, -}; -use rome_formatter::FormatResult; +use crate::prelude::*; + +use crate::generated::FormatJsVariableDeclaratorList; +use crate::AsFormat; use rome_js_syntax::JsVariableDeclaratorList; use rome_rowan::AstSeparatedList; -impl Format for JsVariableDeclaratorList { - fn format(&self, formatter: &Formatter) -> FormatResult { - let last_index = self.len().saturating_sub(1); +impl FormatRule for FormatJsVariableDeclaratorList { + fn format( + node: &JsVariableDeclaratorList, + formatter: &Formatter, + ) -> FormatResult { + let last_index = node.len().saturating_sub(1); - let declarators = self + let declarators = node .elements() .enumerate() .map(|(index, element)| { - let node = element.node().format(formatter)?; - let separator = element.trailing_separator(); - let separator = separator.with_or( - |separator| { + let node = formatted![formatter, [element.node()?.format()]]?; + let separator = match element.trailing_separator()? { + None => { if index == last_index { - Ok(empty_element()) + empty_element() } else { - Ok(separator) + token(",") } - }, - || { + } + Some(separator) => { if index == last_index { - Ok(empty_element()) + empty_element() } else { - Ok(token(",")) + formatted![formatter, [separator.format()]]? } - }, - ); + } + }; - formatted![formatter, node, separator] + formatted![formatter, [node, separator]] }) .collect::>>()?; @@ -48,8 +49,7 @@ impl Format for JsVariableDeclaratorList { .chain(if !trailing_elements.is_empty() { Some(indent(formatted![ formatter, - soft_line_break_or_space(), - trailing_elements + [soft_line_break_or_space(), trailing_elements] ]?)) } else { None diff --git a/crates/rome_js_formatter/src/js/module/default_import_specifier.rs b/crates/rome_js_formatter/src/js/module/default_import_specifier.rs index d671fb11b95f..8e08dbf44b3e 100644 --- a/crates/rome_js_formatter/src/js/module/default_import_specifier.rs +++ b/crates/rome_js_formatter/src/js/module/default_import_specifier.rs @@ -1,19 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsDefaultImportSpecifier; use rome_js_syntax::JsDefaultImportSpecifierFields; -impl FormatNode for JsDefaultImportSpecifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsDefaultImportSpecifier, + formatter: &Formatter, + ) -> FormatResult { let JsDefaultImportSpecifierFields { local_name, trailing_comma_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - local_name.format(formatter)?, - trailing_comma_token.format(formatter)? + [local_name.format(), trailing_comma_token.format()] ] } } diff --git a/crates/rome_js_formatter/src/js/module/export.rs b/crates/rome_js_formatter/src/js/module/export.rs index 711c025dc37e..808048b25eed 100644 --- a/crates/rome_js_formatter/src/js/module/export.rs +++ b/crates/rome_js_formatter/src/js/module/export.rs @@ -1,17 +1,18 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsExport; use rome_js_syntax::JsExportFields; -impl FormatNode for JsExport { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsExport, formatter: &Formatter) -> FormatResult { let JsExportFields { export_token, export_clause, - } = self.as_fields(); + } = node.as_fields(); - let export_token = export_token.format(formatter)?; - let export_clause = export_clause.format(formatter)?; - formatted![formatter, export_token, space_token(), export_clause] + let export_token = export_token.format(); + let export_clause = export_clause.format(); + formatted![formatter, [export_token, space_token(), export_clause]] } } diff --git a/crates/rome_js_formatter/src/js/module/export_as_clause.rs b/crates/rome_js_formatter/src/js/module/export_as_clause.rs index d651f0b7d888..6faf72b39592 100644 --- a/crates/rome_js_formatter/src/js/module/export_as_clause.rs +++ b/crates/rome_js_formatter/src/js/module/export_as_clause.rs @@ -1,18 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsExportAsClause; use rome_js_syntax::JsExportAsClauseFields; -impl FormatNode for JsExportAsClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsExportAsClause, + formatter: &Formatter, + ) -> FormatResult { let JsExportAsClauseFields { as_token, exported_name, - } = self.as_fields(); + } = node.as_fields(); - let as_token = as_token.format(formatter)?; - let exported_name = exported_name.format(formatter)?; + let as_token = as_token.format(); + let exported_name = exported_name.format(); - formatted![formatter, as_token, space_token(), exported_name] + formatted![formatter, [as_token, space_token(), exported_name]] } } diff --git a/crates/rome_js_formatter/src/js/module/export_default_declaration_clause.rs b/crates/rome_js_formatter/src/js/module/export_default_declaration_clause.rs index 6c42524dcfb3..c607787604db 100644 --- a/crates/rome_js_formatter/src/js/module/export_default_declaration_clause.rs +++ b/crates/rome_js_formatter/src/js/module/export_default_declaration_clause.rs @@ -1,13 +1,23 @@ use crate::prelude::*; -use rome_js_syntax::JsExportDefaultDeclarationClause; +use crate::FormatNodeFields; +use rome_js_syntax::{JsExportDefaultDeclarationClause, JsExportDefaultDeclarationClauseFields}; + +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsExportDefaultDeclarationClause, + formatter: &Formatter, + ) -> FormatResult { + let JsExportDefaultDeclarationClauseFields { + default_token, + declaration, + semicolon_token: _, + } = node.as_fields(); -impl FormatNode for JsExportDefaultDeclarationClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { formatted![ formatter, - self.default_token().format(formatter)?, - space_token(), - self.declaration().format(formatter)? + [default_token.format(), space_token(), declaration.format()] ] } } diff --git a/crates/rome_js_formatter/src/js/module/export_default_expression_clause.rs b/crates/rome_js_formatter/src/js/module/export_default_expression_clause.rs index 5a105d58b6b3..d613a0d09d1e 100644 --- a/crates/rome_js_formatter/src/js/module/export_default_expression_clause.rs +++ b/crates/rome_js_formatter/src/js/module/export_default_expression_clause.rs @@ -1,23 +1,29 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsExportDefaultExpressionClause; use rome_js_syntax::JsExportDefaultExpressionClauseFields; -impl FormatNode for JsExportDefaultExpressionClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsExportDefaultExpressionClause, + formatter: &Formatter, + ) -> FormatResult { let JsExportDefaultExpressionClauseFields { default_token, expression, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - let default_token = default_token.format(formatter)?; - let class = expression.format(formatter)?; + let default_token = default_token.format(); + let class = expression.format(); format_with_semicolon( formatter, - formatted![formatter, default_token, space_token(), class]?, + formatted![formatter, [default_token, space_token(), class]]?, semicolon_token, ) } diff --git a/crates/rome_js_formatter/src/js/module/export_from_clause.rs b/crates/rome_js_formatter/src/js/module/export_from_clause.rs index 12470f01a8e9..9b6e4c74e399 100644 --- a/crates/rome_js_formatter/src/js/module/export_from_clause.rs +++ b/crates/rome_js_formatter/src/js/module/export_from_clause.rs @@ -2,11 +2,15 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsExportFromClause; use rome_js_syntax::JsExportFromClauseFields; -impl FormatNode for JsExportFromClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsExportFromClause, + formatter: &Formatter, + ) -> FormatResult { let JsExportFromClauseFields { star_token, export_as, @@ -14,28 +18,26 @@ impl FormatNode for JsExportFromClause { source, assertion, semicolon_token, - } = self.as_fields(); - - let star = star_token.format(formatter)?; - - let export_as = - export_as.with_or_empty(|as_token| formatted![formatter, as_token, space_token()]); - let from = from_token.format(formatter)?; - let source = source.format(formatter)?; - let assertion = - assertion.with_or_empty(|assertion| formatted![formatter, space_token(), assertion]); + } = node.as_fields(); format_with_semicolon( formatter, formatted![ formatter, - star, - space_token(), - export_as, - from, - space_token(), - source, - assertion, + [ + star_token.format(), + space_token(), + export_as + .format() + .with_or_empty(|as_token| formatted![formatter, [as_token, space_token()]]), + from_token.format(), + space_token(), + source.format(), + assertion.format().with_or_empty(|assertion| formatted![ + formatter, + [space_token(), assertion] + ]), + ] ]?, semicolon_token, ) diff --git a/crates/rome_js_formatter/src/js/module/export_named_clause.rs b/crates/rome_js_formatter/src/js/module/export_named_clause.rs index c17936d34ee9..02c3bf577f6d 100644 --- a/crates/rome_js_formatter/src/js/module/export_named_clause.rs +++ b/crates/rome_js_formatter/src/js/module/export_named_clause.rs @@ -2,33 +2,42 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsExportNamedClause; use rome_js_syntax::JsExportNamedClauseFields; -impl FormatNode for JsExportNamedClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsExportNamedClause, + formatter: &Formatter, + ) -> FormatResult { let JsExportNamedClauseFields { type_token, l_curly_token, specifiers, r_curly_token, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - let type_token = - type_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - - let specifiers = specifiers.format(formatter)?; + let specifiers = specifiers.format(); let list = formatter.format_delimited_soft_block_spaces( &l_curly_token?, - specifiers, + formatted![formatter, [specifiers]]?, &r_curly_token?, )?; format_with_semicolon( formatter, - formatted![formatter, type_token, list]?, + formatted![ + formatter, + [ + type_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + list + ] + ]?, semicolon_token, ) } diff --git a/crates/rome_js_formatter/src/js/module/export_named_from_clause.rs b/crates/rome_js_formatter/src/js/module/export_named_from_clause.rs index 35a8696d68ce..74514dde6393 100644 --- a/crates/rome_js_formatter/src/js/module/export_named_from_clause.rs +++ b/crates/rome_js_formatter/src/js/module/export_named_from_clause.rs @@ -2,11 +2,15 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsExportNamedFromClause; use rome_js_syntax::JsExportNamedFromClauseFields; -impl FormatNode for JsExportNamedFromClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsExportNamedFromClause, + formatter: &Formatter, + ) -> FormatResult { let JsExportNamedFromClauseFields { type_token, l_curly_token, @@ -16,35 +20,32 @@ impl FormatNode for JsExportNamedFromClause { source, assertion, semicolon_token, - } = self.as_fields(); - - let type_token = - type_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - - let specifiers = specifiers.format(formatter)?; + } = node.as_fields(); let list = formatter.format_delimited_soft_block_spaces( &l_curly_token?, - specifiers, + formatted![formatter, [specifiers.format()]]?, &r_curly_token?, )?; - let from = from_token.format(formatter)?; - let source = source.format(formatter)?; - let assertion = - assertion.with_or_empty(|assertion| formatted![formatter, space_token(), assertion]); - format_with_semicolon( formatter, formatted![ formatter, - type_token, - list, - space_token(), - from, - space_token(), - source, - assertion, + [ + type_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + list, + space_token(), + from_token.format(), + space_token(), + source.format(), + assertion.format().with_or_empty(|assertion| formatted![ + formatter, + [space_token(), assertion] + ]), + ] ]?, semicolon_token, ) diff --git a/crates/rome_js_formatter/src/js/module/export_named_from_specifier.rs b/crates/rome_js_formatter/src/js/module/export_named_from_specifier.rs index 09e10d2fd582..d044e622f035 100644 --- a/crates/rome_js_formatter/src/js/module/export_named_from_specifier.rs +++ b/crates/rome_js_formatter/src/js/module/export_named_from_specifier.rs @@ -1,24 +1,31 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsExportNamedFromSpecifier; use rome_js_syntax::JsExportNamedFromSpecifierFields; -impl FormatNode for JsExportNamedFromSpecifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsExportNamedFromSpecifier, + formatter: &Formatter, + ) -> FormatResult { let JsExportNamedFromSpecifierFields { type_token, source_name, export_as, - } = self.as_fields(); + } = node.as_fields(); - let type_token = - type_token.with_or_empty(|type_token| formatted![formatter, type_token, space_token()]); - - let source_name = source_name.format(formatter)?; - - let export_as = - export_as.with_or_empty(|export_as| formatted![formatter, space_token(), export_as]); - - formatted![formatter, type_token, source_name, export_as] + formatted![ + formatter, + [ + type_token + .format() + .with_or_empty(|type_token| formatted![formatter, [type_token, space_token()]]), + source_name.format(), + export_as + .format() + .with_or_empty(|export_as| formatted![formatter, [space_token(), export_as]]) + ] + ] } } diff --git a/crates/rome_js_formatter/src/js/module/export_named_shorthand_specifier.rs b/crates/rome_js_formatter/src/js/module/export_named_shorthand_specifier.rs index f69d4dfe7fde..ead23eec6d5a 100644 --- a/crates/rome_js_formatter/src/js/module/export_named_shorthand_specifier.rs +++ b/crates/rome_js_formatter/src/js/module/export_named_shorthand_specifier.rs @@ -1,16 +1,26 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsExportNamedShorthandSpecifier; use rome_js_syntax::JsExportNamedShorthandSpecifierFields; -impl FormatNode for JsExportNamedShorthandSpecifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsExportNamedShorthandSpecifierFields { type_token, name } = self.as_fields(); +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsExportNamedShorthandSpecifier, + formatter: &Formatter, + ) -> FormatResult { + let JsExportNamedShorthandSpecifierFields { type_token, name } = node.as_fields(); - let type_token = - type_token.with_or_empty(|type_token| formatted![formatter, type_token, space_token()]); - let name = name.format(formatter)?; - - formatted![formatter, type_token, name] + formatted![ + formatter, + [ + type_token + .format() + .with_or_empty(|type_token| formatted![formatter, [type_token, space_token()]]), + name.format() + ] + ] } } diff --git a/crates/rome_js_formatter/src/js/module/export_named_specifier.rs b/crates/rome_js_formatter/src/js/module/export_named_specifier.rs index aa592496da8c..a6c9096571a3 100644 --- a/crates/rome_js_formatter/src/js/module/export_named_specifier.rs +++ b/crates/rome_js_formatter/src/js/module/export_named_specifier.rs @@ -1,31 +1,33 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsExportNamedSpecifier; use rome_js_syntax::JsExportNamedSpecifierFields; -impl FormatNode for JsExportNamedSpecifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsExportNamedSpecifier, + formatter: &Formatter, + ) -> FormatResult { let JsExportNamedSpecifierFields { type_token, local_name, as_token, exported_name, - } = self.as_fields(); - - let type_token = - type_token.with_or_empty(|type_token| formatted![formatter, type_token, space_token()]); - let as_token = as_token.format(formatter)?; - let local_name = local_name.format(formatter)?; - let exported_name = exported_name.format(formatter)?; + } = node.as_fields(); formatted![ formatter, - type_token, - local_name, - space_token(), - as_token, - space_token(), - exported_name + [ + type_token + .format() + .with_or_empty(|type_token| formatted![formatter, [type_token, space_token()]]), + local_name.format(), + space_token(), + as_token.format(), + space_token(), + exported_name.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/js/module/import.rs b/crates/rome_js_formatter/src/js/module/import.rs index 333a06645123..265962875956 100644 --- a/crates/rome_js_formatter/src/js/module/import.rs +++ b/crates/rome_js_formatter/src/js/module/import.rs @@ -1,23 +1,24 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsImport; use rome_js_syntax::JsImportFields; -impl FormatNode for JsImport { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsImport, formatter: &Formatter) -> FormatResult { let JsImportFields { import_token, import_clause, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - let import_token = import_token.format(formatter)?; - let import_clause = import_clause.format(formatter)?; + let import_token = import_token.format(); + let import_clause = import_clause.format(); format_with_semicolon( formatter, - formatted![formatter, import_token, space_token(), import_clause]?, + formatted![formatter, [import_token, space_token(), import_clause]]?, semicolon_token, ) } diff --git a/crates/rome_js_formatter/src/js/module/import_assertion.rs b/crates/rome_js_formatter/src/js/module/import_assertion.rs index 4557e3d3fe1a..47e6ac4ea982 100644 --- a/crates/rome_js_formatter/src/js/module/import_assertion.rs +++ b/crates/rome_js_formatter/src/js/module/import_assertion.rs @@ -1,26 +1,27 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsImportAssertion; use rome_js_syntax::JsImportAssertionFields; -impl FormatNode for JsImportAssertion { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsImportAssertion, + formatter: &Formatter, + ) -> FormatResult { let JsImportAssertionFields { assert_token, l_curly_token, assertions, r_curly_token, - } = self.as_fields(); - - let assert_token = assert_token.format(formatter)?; - let assertions = assertions.format(formatter)?; + } = node.as_fields(); let result = formatter.format_delimited_soft_block_spaces( &l_curly_token?, - assertions, + formatted![formatter, [assertions.format()]]?, &r_curly_token?, )?; - formatted![formatter, assert_token, space_token(), result] + formatted![formatter, [assert_token.format(), space_token(), result]] } } diff --git a/crates/rome_js_formatter/src/js/module/import_assertion_entry.rs b/crates/rome_js_formatter/src/js/module/import_assertion_entry.rs index 89e6f57b7e82..5fec5acd021b 100644 --- a/crates/rome_js_formatter/src/js/module/import_assertion_entry.rs +++ b/crates/rome_js_formatter/src/js/module/import_assertion_entry.rs @@ -1,30 +1,36 @@ use crate::prelude::*; use crate::utils::format_string_literal_token; +use crate::FormatNodeFields; use rome_js_syntax::JsImportAssertionEntryFields; use rome_js_syntax::{JsImportAssertionEntry, JsSyntaxKind}; -impl FormatNode for JsImportAssertionEntry { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsImportAssertionEntry, + formatter: &Formatter, + ) -> FormatResult { let JsImportAssertionEntryFields { key, colon_token, value_token, - } = self.as_fields(); + } = node.as_fields(); let key = key?; let formatted_key = match key.kind() { JsSyntaxKind::JS_STRING_LITERAL => format_string_literal_token(key, formatter), - _ => key.format(formatter)?, + _ => formatted![formatter, [key.format()]]?, }; formatted![ formatter, - formatted_key, - colon_token.format(formatter)?, - space_token(), - format_string_literal_token(value_token?, formatter), + [ + formatted_key, + colon_token.format(), + space_token(), + format_string_literal_token(value_token?, formatter), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/module/import_bare_clause.rs b/crates/rome_js_formatter/src/js/module/import_bare_clause.rs index aeb26e43a288..3f8216d52763 100644 --- a/crates/rome_js_formatter/src/js/module/import_bare_clause.rs +++ b/crates/rome_js_formatter/src/js/module/import_bare_clause.rs @@ -1,16 +1,24 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsImportBareClause; use rome_js_syntax::JsImportBareClauseFields; -impl FormatNode for JsImportBareClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsImportBareClauseFields { source, assertion } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsImportBareClause, + formatter: &Formatter, + ) -> FormatResult { + let JsImportBareClauseFields { source, assertion } = node.as_fields(); - let source = source.format(formatter)?; - let assertion = - assertion.with_or_empty(|assertion| formatted![formatter, space_token(), assertion]); - - formatted![formatter, source, assertion] + formatted![ + formatter, + [ + source.format(), + assertion + .format() + .with_or_empty(|assertion| formatted![formatter, [space_token(), assertion]]) + ] + ] } } diff --git a/crates/rome_js_formatter/src/js/module/import_default_clause.rs b/crates/rome_js_formatter/src/js/module/import_default_clause.rs index 9312d05da605..2a209cef9aa5 100644 --- a/crates/rome_js_formatter/src/js/module/import_default_clause.rs +++ b/crates/rome_js_formatter/src/js/module/import_default_clause.rs @@ -1,35 +1,37 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsImportDefaultClause; use rome_js_syntax::JsImportDefaultClauseFields; -impl FormatNode for JsImportDefaultClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsImportDefaultClause, + formatter: &Formatter, + ) -> FormatResult { let JsImportDefaultClauseFields { type_token, local_name, from_token, source, assertion, - } = self.as_fields(); - - let type_token = - type_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - let local_name = local_name.format(formatter)?; - let from = from_token.format(formatter)?; - let source = source.format(formatter)?; - let assertion = - assertion.with_or_empty(|assertion| formatted![formatter, space_token(), assertion]); + } = node.as_fields(); formatted![ formatter, - type_token, - local_name, - space_token(), - from, - space_token(), - source, - assertion + [ + type_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + local_name.format(), + space_token(), + from_token.format(), + space_token(), + source.format(), + assertion + .format() + .with_or_empty(|assertion| formatted![formatter, [space_token(), assertion]]) + ] ] } } diff --git a/crates/rome_js_formatter/src/js/module/import_meta.rs b/crates/rome_js_formatter/src/js/module/import_meta.rs index d433de5fa018..c7ec7620b043 100644 --- a/crates/rome_js_formatter/src/js/module/import_meta.rs +++ b/crates/rome_js_formatter/src/js/module/import_meta.rs @@ -1,21 +1,24 @@ use crate::prelude::*; use rome_js_syntax::ImportMeta; +use crate::FormatNodeFields; use rome_js_syntax::ImportMetaFields; -impl FormatNode for ImportMeta { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &ImportMeta, formatter: &Formatter) -> FormatResult { let ImportMetaFields { import_token, dot_token, meta_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - import_token.format(formatter)?, - dot_token.format(formatter)?, - meta_token.format(formatter)?, + [ + import_token.format(), + dot_token.format(), + meta_token.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/module/import_named_clause.rs b/crates/rome_js_formatter/src/js/module/import_named_clause.rs index 5060b2c68322..f4273af09b44 100644 --- a/crates/rome_js_formatter/src/js/module/import_named_clause.rs +++ b/crates/rome_js_formatter/src/js/module/import_named_clause.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsImportNamedClause; use rome_js_syntax::JsImportNamedClauseFields; -impl FormatNode for JsImportNamedClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsImportNamedClause, + formatter: &Formatter, + ) -> FormatResult { let JsImportNamedClauseFields { type_token, default_specifier, @@ -12,29 +16,26 @@ impl FormatNode for JsImportNamedClause { from_token, source, assertion, - } = self.as_fields(); + } = node.as_fields(); - let type_token = - type_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - - let source = source.format(formatter)?; - - let default = default_specifier - .with_or_empty(|specifier| formatted![formatter, specifier, space_token()]); - let from = from_token.format(formatter)?; - let name = named_import.format(formatter)?; - let assertion = - assertion.with_or_empty(|assertion| formatted![formatter, space_token(), assertion]); formatted![ formatter, - type_token, - default, - name, - space_token(), - from, - space_token(), - source, - assertion + [ + type_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + default_specifier + .format() + .with_or_empty(|specifier| formatted![formatter, [specifier, space_token()]]), + named_import.format(), + space_token(), + from_token.format(), + space_token(), + source.format(), + assertion + .format() + .with_or_empty(|assertion| formatted![formatter, [space_token(), assertion]]) + ] ] } } diff --git a/crates/rome_js_formatter/src/js/module/import_namespace_clause.rs b/crates/rome_js_formatter/src/js/module/import_namespace_clause.rs index 033ae199eff5..d0f5d7bb4dd4 100644 --- a/crates/rome_js_formatter/src/js/module/import_namespace_clause.rs +++ b/crates/rome_js_formatter/src/js/module/import_namespace_clause.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsImportNamespaceClause; use rome_js_syntax::JsImportNamespaceClauseFields; -impl FormatNode for JsImportNamespaceClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsImportNamespaceClause, + formatter: &Formatter, + ) -> FormatResult { let JsImportNamespaceClauseFields { type_token, star_token, @@ -13,31 +17,27 @@ impl FormatNode for JsImportNamespaceClause { from_token, source, assertion, - } = self.as_fields(); + } = node.as_fields(); - let type_token = - type_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - - let star = star_token.format(formatter)?; - let as_token = as_token.format(formatter)?; - let local_name = local_name.format(formatter)?; - let source = source.format(formatter)?; - let from = from_token.format(formatter)?; - let assertion = - assertion.with_or_empty(|assertion| formatted![formatter, space_token(), assertion]); formatted![ formatter, - type_token, - star, - space_token(), - as_token, - space_token(), - local_name, - space_token(), - from, - space_token(), - source, - assertion + [ + type_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + star_token.format(), + space_token(), + as_token.format(), + space_token(), + local_name.format(), + space_token(), + from_token.format(), + space_token(), + source.format(), + assertion + .format() + .with_or_empty(|assertion| formatted![formatter, [space_token(), assertion]]) + ] ] } } diff --git a/crates/rome_js_formatter/src/js/module/literal_export_name.rs b/crates/rome_js_formatter/src/js/module/literal_export_name.rs index 5d7a5897fcd1..cce5e15f3f98 100644 --- a/crates/rome_js_formatter/src/js/module/literal_export_name.rs +++ b/crates/rome_js_formatter/src/js/module/literal_export_name.rs @@ -1,11 +1,15 @@ use crate::prelude::*; use crate::utils::format_string_literal_token; +use crate::FormatNodeFields; use rome_js_syntax::JsLiteralExportName; use rome_js_syntax::JsLiteralExportNameFields; -impl FormatNode for JsLiteralExportName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsLiteralExportNameFields { value } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsLiteralExportName, + formatter: &Formatter, + ) -> FormatResult { + let JsLiteralExportNameFields { value } = node.as_fields(); Ok(format_string_literal_token(value?, formatter)) } diff --git a/crates/rome_js_formatter/src/js/module/module_source.rs b/crates/rome_js_formatter/src/js/module/module_source.rs index 9610972df2ba..6a612cec9eda 100644 --- a/crates/rome_js_formatter/src/js/module/module_source.rs +++ b/crates/rome_js_formatter/src/js/module/module_source.rs @@ -1,12 +1,13 @@ use crate::prelude::*; use crate::utils::format_string_literal_token; +use crate::FormatNodeFields; use rome_js_syntax::JsModuleSource; use rome_js_syntax::JsModuleSourceFields; -impl FormatNode for JsModuleSource { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsModuleSourceFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsModuleSource, formatter: &Formatter) -> FormatResult { + let JsModuleSourceFields { value_token } = node.as_fields(); Ok(format_string_literal_token(value_token?, formatter)) } diff --git a/crates/rome_js_formatter/src/js/module/named_import_specifier.rs b/crates/rome_js_formatter/src/js/module/named_import_specifier.rs index 7b01e63e93b4..05f3daa5213f 100644 --- a/crates/rome_js_formatter/src/js/module/named_import_specifier.rs +++ b/crates/rome_js_formatter/src/js/module/named_import_specifier.rs @@ -1,32 +1,33 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsNamedImportSpecifier; use rome_js_syntax::JsNamedImportSpecifierFields; -impl FormatNode for JsNamedImportSpecifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsNamedImportSpecifier, + formatter: &Formatter, + ) -> FormatResult { let JsNamedImportSpecifierFields { type_token, name, as_token, local_name, - } = self.as_fields(); - - let type_token = - type_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - - let name = name.format(formatter)?; - let as_token = as_token.format(formatter)?; - let local_name = local_name.format(formatter)?; + } = node.as_fields(); formatted![ formatter, - type_token, - name, - soft_line_break_or_space(), - as_token, - soft_line_break_or_space(), - local_name + [ + type_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + name.format(), + soft_line_break_or_space(), + as_token.format(), + soft_line_break_or_space(), + local_name.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/js/module/named_import_specifiers.rs b/crates/rome_js_formatter/src/js/module/named_import_specifiers.rs index e99fd61a977d..6ca9eee03af0 100644 --- a/crates/rome_js_formatter/src/js/module/named_import_specifiers.rs +++ b/crates/rome_js_formatter/src/js/module/named_import_specifiers.rs @@ -1,18 +1,24 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsNamedImportSpecifiers; use rome_js_syntax::JsNamedImportSpecifiersFields; -impl FormatNode for JsNamedImportSpecifiers { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsNamedImportSpecifiers, + formatter: &Formatter, + ) -> FormatResult { let JsNamedImportSpecifiersFields { l_curly_token, specifiers, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); - let specifiers = specifiers.format(formatter)?; - - formatter.format_delimited_soft_block_spaces(&l_curly_token?, specifiers, &r_curly_token?) + formatter.format_delimited_soft_block_spaces( + &l_curly_token?, + formatted![formatter, [specifiers.format()]]?, + &r_curly_token?, + ) } } diff --git a/crates/rome_js_formatter/src/js/module/namespace_import_specifier.rs b/crates/rome_js_formatter/src/js/module/namespace_import_specifier.rs index 0842de3f41d1..36ee9582290d 100644 --- a/crates/rome_js_formatter/src/js/module/namespace_import_specifier.rs +++ b/crates/rome_js_formatter/src/js/module/namespace_import_specifier.rs @@ -1,27 +1,27 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsNamespaceImportSpecifier; use rome_js_syntax::JsNamespaceImportSpecifierFields; -impl FormatNode for JsNamespaceImportSpecifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsNamespaceImportSpecifier, + formatter: &Formatter, + ) -> FormatResult { let JsNamespaceImportSpecifierFields { star_token, as_token, local_name, - } = self.as_fields(); + } = node.as_fields(); - let star = star_token.format(formatter)?; - let as_token = as_token.format(formatter)?; - let local_name = local_name.format(formatter)?; + let star = star_token.format(); + let as_token = as_token.format(); + let local_name = local_name.format(); formatted![ formatter, - star, - space_token(), - as_token, - space_token(), - local_name + [star, space_token(), as_token, space_token(), local_name] ] } } diff --git a/crates/rome_js_formatter/src/js/module/shorthand_named_import_specifier.rs b/crates/rome_js_formatter/src/js/module/shorthand_named_import_specifier.rs index 63264e0ca13a..b8ba6e13b268 100644 --- a/crates/rome_js_formatter/src/js/module/shorthand_named_import_specifier.rs +++ b/crates/rome_js_formatter/src/js/module/shorthand_named_import_specifier.rs @@ -1,20 +1,29 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsShorthandNamedImportSpecifier; use rome_js_syntax::JsShorthandNamedImportSpecifierFields; -impl FormatNode for JsShorthandNamedImportSpecifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsShorthandNamedImportSpecifier, + formatter: &Formatter, + ) -> FormatResult { let JsShorthandNamedImportSpecifierFields { type_token, local_name, - } = self.as_fields(); + } = node.as_fields(); - let type_token = - type_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - - let local_name = local_name.format(formatter)?; - - formatted![formatter, type_token, local_name] + formatted![ + formatter, + [ + type_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + local_name.format() + ] + ] } } diff --git a/crates/rome_js_formatter/src/js/objects/computed_member_name.rs b/crates/rome_js_formatter/src/js/objects/computed_member_name.rs index 713f30115622..1539898367d9 100644 --- a/crates/rome_js_formatter/src/js/objects/computed_member_name.rs +++ b/crates/rome_js_formatter/src/js/objects/computed_member_name.rs @@ -1,21 +1,27 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsComputedMemberName; use rome_js_syntax::JsComputedMemberNameFields; -impl FormatNode for JsComputedMemberName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsComputedMemberName, + formatter: &Formatter, + ) -> FormatResult { let JsComputedMemberNameFields { l_brack_token, expression, r_brack_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - l_brack_token.format(formatter)?, - expression.format(formatter)?, - r_brack_token.format(formatter)?, + [ + l_brack_token.format(), + expression.format(), + r_brack_token.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/objects/getter_object_member.rs b/crates/rome_js_formatter/src/js/objects/getter_object_member.rs index 9dbac17b87ba..b2fe03217ead 100644 --- a/crates/rome_js_formatter/src/js/objects/getter_object_member.rs +++ b/crates/rome_js_formatter/src/js/objects/getter_object_member.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsGetterObjectMember; use rome_js_syntax::JsGetterObjectMemberFields; -impl FormatNode for JsGetterObjectMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsGetterObjectMember, + formatter: &Formatter, + ) -> FormatResult { let JsGetterObjectMemberFields { get_token, name, @@ -12,18 +16,20 @@ impl FormatNode for JsGetterObjectMember { r_paren_token, return_type, body, - } = self.as_fields(); + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - get_token.format(formatter)?, - space_token(), - name.format(formatter)?, - l_paren_token.format(formatter)?, - r_paren_token.format(formatter)?, - return_type, - space_token(), - body.format(formatter)? + [ + get_token.format(), + space_token(), + name.format(), + l_paren_token.format(), + r_paren_token.format(), + return_type.format(), + space_token(), + body.format() + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/objects/literal_member_name.rs b/crates/rome_js_formatter/src/js/objects/literal_member_name.rs index 8f17c905b99b..651526d07c78 100644 --- a/crates/rome_js_formatter/src/js/objects/literal_member_name.rs +++ b/crates/rome_js_formatter/src/js/objects/literal_member_name.rs @@ -1,18 +1,22 @@ use crate::prelude::*; use crate::utils::format_string_literal_token; +use crate::FormatNodeFields; use rome_js_syntax::JsLiteralMemberNameFields; use rome_js_syntax::{JsLiteralMemberName, JsSyntaxKind}; -impl FormatNode for JsLiteralMemberName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsLiteralMemberNameFields { value } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsLiteralMemberName, + formatter: &Formatter, + ) -> FormatResult { + let JsLiteralMemberNameFields { value } = node.as_fields(); let value = value?; match value.kind() { JsSyntaxKind::JS_STRING_LITERAL => Ok(format_string_literal_token(value, formatter)), - _ => value.format(formatter), + _ => formatted![formatter, [value.format()]], } } } diff --git a/crates/rome_js_formatter/src/js/objects/method_object_member.rs b/crates/rome_js_formatter/src/js/objects/method_object_member.rs index 98aaa78d7429..f479b937f8f6 100644 --- a/crates/rome_js_formatter/src/js/objects/method_object_member.rs +++ b/crates/rome_js_formatter/src/js/objects/method_object_member.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsMethodObjectMember; use rome_js_syntax::JsMethodObjectMemberFields; -impl FormatNode for JsMethodObjectMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsMethodObjectMember, + formatter: &Formatter, + ) -> FormatResult { let JsMethodObjectMemberFields { async_token, star_token, @@ -13,20 +17,23 @@ impl FormatNode for JsMethodObjectMember { parameters, return_type_annotation, body, - } = self.as_fields(); + } = node.as_fields(); - let async_token = async_token - .with_or_empty(|async_token| formatted![formatter, async_token, space_token()]); Ok(hard_group_elements(formatted![ formatter, - async_token, - star_token, - name.format(formatter)?, - type_parameters, - parameters.format(formatter)?, - return_type_annotation, - space_token(), - body.format(formatter)?, + [ + async_token.format().with_or_empty(|async_token| formatted![ + formatter, + [async_token, space_token()] + ]), + star_token.format(), + name.format(), + type_parameters.format(), + parameters.format(), + return_type_annotation.format(), + space_token(), + body.format(), + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/objects/private_class_member_name.rs b/crates/rome_js_formatter/src/js/objects/private_class_member_name.rs index b13b03b94761..7eed3713c70f 100644 --- a/crates/rome_js_formatter/src/js/objects/private_class_member_name.rs +++ b/crates/rome_js_formatter/src/js/objects/private_class_member_name.rs @@ -1,19 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsPrivateClassMemberName; use rome_js_syntax::JsPrivateClassMemberNameFields; -impl FormatNode for JsPrivateClassMemberName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsPrivateClassMemberName, + formatter: &Formatter, + ) -> FormatResult { let JsPrivateClassMemberNameFields { hash_token, id_token, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - hash_token.format(formatter)?, - id_token.format(formatter)?, - ] + formatted![formatter, [hash_token.format(), id_token.format(),]] } } diff --git a/crates/rome_js_formatter/src/js/objects/property_object_member.rs b/crates/rome_js_formatter/src/js/objects/property_object_member.rs index 3642f1be4811..982d73eaf21b 100644 --- a/crates/rome_js_formatter/src/js/objects/property_object_member.rs +++ b/crates/rome_js_formatter/src/js/objects/property_object_member.rs @@ -1,19 +1,23 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsPropertyObjectMember; use rome_js_syntax::JsPropertyObjectMemberFields; -impl FormatNode for JsPropertyObjectMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsPropertyObjectMember, + formatter: &Formatter, + ) -> FormatResult { let JsPropertyObjectMemberFields { name, colon_token, value, - } = self.as_fields(); + } = node.as_fields(); - let key = name.format(formatter)?; - let colon = colon_token.format(formatter)?; - let value = value.format(formatter)?; - formatted![formatter, key, colon, space_token(), value] + let key = name.format(); + let colon = colon_token.format(); + let value = value.format(); + formatted![formatter, [key, colon, space_token(), value]] } } diff --git a/crates/rome_js_formatter/src/js/objects/setter_object_member.rs b/crates/rome_js_formatter/src/js/objects/setter_object_member.rs index 37e52625b2e3..c522d7e191ef 100644 --- a/crates/rome_js_formatter/src/js/objects/setter_object_member.rs +++ b/crates/rome_js_formatter/src/js/objects/setter_object_member.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsSetterObjectMember; use rome_js_syntax::JsSetterObjectMemberFields; -impl FormatNode for JsSetterObjectMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsSetterObjectMember, + formatter: &Formatter, + ) -> FormatResult { let JsSetterObjectMemberFields { set_token, name, @@ -12,18 +16,20 @@ impl FormatNode for JsSetterObjectMember { parameter, r_paren_token, body, - } = self.as_fields(); + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - set_token.format(formatter)?, - space_token(), - name.format(formatter)?, - l_paren_token.format(formatter)?, - parameter.format(formatter)?, - r_paren_token.format(formatter)?, - space_token(), - body.format(formatter)?, + [ + set_token.format(), + space_token(), + name.format(), + l_paren_token.format(), + parameter.format(), + r_paren_token.format(), + space_token(), + body.format(), + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/objects/shorthand_property_object_member.rs b/crates/rome_js_formatter/src/js/objects/shorthand_property_object_member.rs index 1730c302ff88..a7a6c961247e 100644 --- a/crates/rome_js_formatter/src/js/objects/shorthand_property_object_member.rs +++ b/crates/rome_js_formatter/src/js/objects/shorthand_property_object_member.rs @@ -1,12 +1,18 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsShorthandPropertyObjectMember; use rome_js_syntax::JsShorthandPropertyObjectMemberFields; -impl FormatNode for JsShorthandPropertyObjectMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsShorthandPropertyObjectMemberFields { name } = self.as_fields(); +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsShorthandPropertyObjectMember, + formatter: &Formatter, + ) -> FormatResult { + let JsShorthandPropertyObjectMemberFields { name } = node.as_fields(); - name.format(formatter) + formatted![formatter, [name.format()]] } } diff --git a/crates/rome_js_formatter/src/js/statements/block_statement.rs b/crates/rome_js_formatter/src/js/statements/block_statement.rs index 27697b356388..80bea8afcf79 100644 --- a/crates/rome_js_formatter/src/js/statements/block_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/block_statement.rs @@ -3,26 +3,32 @@ use crate::prelude::*; use rome_js_syntax::JsAnyStatement; use rome_js_syntax::JsBlockStatement; +use crate::FormatNodeFields; use rome_js_syntax::JsBlockStatementFields; use rome_js_syntax::JsSyntaxKind; use rome_rowan::{AstNode, AstNodeList}; -impl FormatNode for JsBlockStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsBlockStatement, + formatter: &Formatter, + ) -> FormatResult { let JsBlockStatementFields { l_curly_token, statements, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); - let stmts = formatter.format_list(statements); + let stmts = formatter.format_list(&statements); - if is_non_collapsable_empty_block(self) { + if is_non_collapsable_empty_block(node) { formatted![ formatter, - l_curly_token.format(formatter)?, - hard_line_break(), - r_curly_token.format(formatter)? + [ + l_curly_token.format(), + hard_line_break(), + r_curly_token.format() + ] ] } else { formatter.format_delimited_block_indent(&l_curly_token?, stmts, &r_curly_token?) diff --git a/crates/rome_js_formatter/src/js/statements/break_statement.rs b/crates/rome_js_formatter/src/js/statements/break_statement.rs index e356b03fb747..4a9b6d864d7b 100644 --- a/crates/rome_js_formatter/src/js/statements/break_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/break_statement.rs @@ -1,22 +1,32 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsBreakStatement; use rome_js_syntax::JsBreakStatementFields; -impl FormatNode for JsBreakStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsBreakStatement, + formatter: &Formatter, + ) -> FormatResult { let JsBreakStatementFields { break_token, label_token, semicolon_token, - } = self.as_fields(); - - let label = label_token.with_or_empty(|label| formatted![formatter, space_token(), label]); + } = node.as_fields(); format_with_semicolon( formatter, - formatted![formatter, break_token.format(formatter)?, label]?, + formatted![ + formatter, + [ + break_token.format(), + label_token + .format() + .with_or_empty(|label| formatted![formatter, [space_token(), label]]) + ] + ]?, semicolon_token, ) } diff --git a/crates/rome_js_formatter/src/js/statements/continue_statement.rs b/crates/rome_js_formatter/src/js/statements/continue_statement.rs index 64d33e900ea8..8df983603a89 100644 --- a/crates/rome_js_formatter/src/js/statements/continue_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/continue_statement.rs @@ -1,22 +1,32 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsContinueStatement; use rome_js_syntax::JsContinueStatementFields; -impl FormatNode for JsContinueStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsContinueStatement, + formatter: &Formatter, + ) -> FormatResult { let JsContinueStatementFields { continue_token, label_token, semicolon_token, - } = self.as_fields(); - - let label = label_token.with_or_empty(|token| formatted![formatter, space_token(), token]); + } = node.as_fields(); format_with_semicolon( formatter, - formatted![formatter, continue_token.format(formatter)?, label]?, + formatted![ + formatter, + [ + continue_token.format(), + label_token + .format() + .with_or_empty(|token| formatted![formatter, [space_token(), token]]) + ] + ]?, semicolon_token, ) } diff --git a/crates/rome_js_formatter/src/js/statements/debugger_statement.rs b/crates/rome_js_formatter/src/js/statements/debugger_statement.rs index 6d38a763737f..1714d456b7b8 100644 --- a/crates/rome_js_formatter/src/js/statements/debugger_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/debugger_statement.rs @@ -1,19 +1,23 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsDebuggerStatement; use rome_js_syntax::JsDebuggerStatementFields; -impl FormatNode for JsDebuggerStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsDebuggerStatement, + formatter: &Formatter, + ) -> FormatResult { let JsDebuggerStatementFields { debugger_token, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); format_with_semicolon( formatter, - formatted![formatter, debugger_token.format(formatter)?]?, + formatted![formatter, [debugger_token.format()]]?, semicolon_token, ) } diff --git a/crates/rome_js_formatter/src/js/statements/do_while_statement.rs b/crates/rome_js_formatter/src/js/statements/do_while_statement.rs index 8ec7bb4c5209..f647af9864f8 100644 --- a/crates/rome_js_formatter/src/js/statements/do_while_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/do_while_statement.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsDoWhileStatementFields; use rome_js_syntax::{JsAnyStatement, JsDoWhileStatement}; -impl FormatNode for JsDoWhileStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsDoWhileStatement, + formatter: &Formatter, + ) -> FormatResult { let JsDoWhileStatementFields { do_token, body, @@ -13,37 +17,39 @@ impl FormatNode for JsDoWhileStatement { test, r_paren_token, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - let head = formatted![formatter, do_token.format(formatter)?, space_token(),]?; + let head = formatted![formatter, [do_token.format(), space_token(),]]?; let tail = formatted![ formatter, - space_token(), - while_token.format(formatter)?, - space_token(), - formatter.format_delimited_soft_block_indent( - &l_paren_token?, - test.format(formatter)?, - &r_paren_token?, - )?, - semicolon_token.or_format(|| token(";")) + [ + space_token(), + while_token.format(), + space_token(), + formatter.format_delimited_soft_block_indent( + &l_paren_token?, + formatted![formatter, [test.format()]]?, + &r_paren_token?, + )?, + semicolon_token.format().or_format(|| token(";")) + ] ]?; let body = body?; if matches!(body, JsAnyStatement::JsBlockStatement(_)) { Ok(hard_group_elements(formatted![ formatter, - head, - body.format(formatter)?, - tail, + [head, body.format(), tail,] ]?)) } else { formatted![ formatter, - hard_group_elements(head), - body.format(formatter)?, - hard_group_elements(tail), + [ + hard_group_elements(head), + body.format(), + hard_group_elements(tail), + ] ] } } diff --git a/crates/rome_js_formatter/src/js/statements/empty_statement.rs b/crates/rome_js_formatter/src/js/statements/empty_statement.rs index e2f088fcd1d5..8b0b2ede4044 100644 --- a/crates/rome_js_formatter/src/js/statements/empty_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/empty_statement.rs @@ -1,11 +1,15 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsEmptyStatement; use rome_js_syntax::JsEmptyStatementFields; -impl FormatNode for JsEmptyStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsEmptyStatementFields { semicolon_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsEmptyStatement, + formatter: &Formatter, + ) -> FormatResult { + let JsEmptyStatementFields { semicolon_token } = node.as_fields(); Ok(formatter.format_replaced(&semicolon_token?, empty_element())) } diff --git a/crates/rome_js_formatter/src/js/statements/expression_statement.rs b/crates/rome_js_formatter/src/js/statements/expression_statement.rs index 67bdec8011c1..e73c93b89b4b 100644 --- a/crates/rome_js_formatter/src/js/statements/expression_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/expression_statement.rs @@ -1,16 +1,24 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsExpressionStatement; use rome_js_syntax::JsExpressionStatementFields; -impl FormatNode for JsExpressionStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsExpressionStatement, + formatter: &Formatter, + ) -> FormatResult { let JsExpressionStatementFields { expression, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - format_with_semicolon(formatter, expression.format(formatter)?, semicolon_token) + format_with_semicolon( + formatter, + formatted![formatter, [expression.format()]]?, + semicolon_token, + ) } } diff --git a/crates/rome_js_formatter/src/js/statements/for_in_statement.rs b/crates/rome_js_formatter/src/js/statements/for_in_statement.rs index 0f9789a40936..7841a9263cc2 100644 --- a/crates/rome_js_formatter/src/js/statements/for_in_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/for_in_statement.rs @@ -2,10 +2,14 @@ use rome_js_syntax::JsForInStatement; use crate::prelude::*; use crate::utils::format_head_body_statement; +use crate::FormatNodeFields; use rome_js_syntax::JsForInStatementFields; -impl FormatNode for JsForInStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsForInStatement, + formatter: &Formatter, + ) -> FormatResult { let JsForInStatementFields { for_token, l_paren_token, @@ -14,31 +18,35 @@ impl FormatNode for JsForInStatement { expression, r_paren_token, body, - } = self.as_fields(); + } = node.as_fields(); - let for_token = for_token.format(formatter)?; - let initializer = initializer.format(formatter)?; - let in_token = in_token.format(formatter)?; - let expression = expression.format(formatter)?; + let for_token = for_token.format(); + let initializer = initializer.format(); + let in_token = in_token.format(); + let expression = expression.format(); format_head_body_statement( formatter, formatted![ formatter, - for_token, - space_token(), - formatter.format_delimited_soft_block_indent( - &l_paren_token?, - formatted![ - formatter, - initializer, - soft_line_break_or_space(), - in_token, - soft_line_break_or_space(), - expression, - ]?, - &r_paren_token? - )?, + [ + for_token, + space_token(), + formatter.format_delimited_soft_block_indent( + &l_paren_token?, + formatted![ + formatter, + [ + initializer, + soft_line_break_or_space(), + in_token, + soft_line_break_or_space(), + expression, + ] + ]?, + &r_paren_token? + )?, + ] ]?, body?, ) diff --git a/crates/rome_js_formatter/src/js/statements/for_of_statement.rs b/crates/rome_js_formatter/src/js/statements/for_of_statement.rs index 2539275e1164..b15e64c3d5e4 100644 --- a/crates/rome_js_formatter/src/js/statements/for_of_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/for_of_statement.rs @@ -3,10 +3,14 @@ use rome_js_syntax::JsForOfStatement; use crate::prelude::*; use crate::utils::format_head_body_statement; +use crate::FormatNodeFields; use rome_js_syntax::JsForOfStatementFields; -impl FormatNode for JsForOfStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsForOfStatement, + formatter: &Formatter, + ) -> FormatResult { let JsForOfStatementFields { for_token, await_token, @@ -16,34 +20,33 @@ impl FormatNode for JsForOfStatement { expression, r_paren_token, body, - } = self.as_fields(); - - let for_token = for_token.format(formatter)?; - let await_token = - await_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - let initializer = initializer.format(formatter)?; - let of_token = of_token.format(formatter)?; - let expression = expression.format(formatter)?; + } = node.as_fields(); format_head_body_statement( formatter, formatted![ formatter, - for_token, - space_token(), - await_token, - formatter.format_delimited_soft_block_indent( - &l_paren_token?, - formatted![ - formatter, - initializer, - soft_line_break_or_space(), - of_token, - soft_line_break_or_space(), - expression, - ]?, - &r_paren_token? - )?, + [ + for_token.format(), + space_token(), + await_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + formatter.format_delimited_soft_block_indent( + &l_paren_token?, + formatted![ + formatter, + [ + initializer.format(), + soft_line_break_or_space(), + of_token.format(), + soft_line_break_or_space(), + expression.format(), + ] + ]?, + &r_paren_token? + )?, + ] ]?, body?, ) diff --git a/crates/rome_js_formatter/src/js/statements/for_statement.rs b/crates/rome_js_formatter/src/js/statements/for_statement.rs index 0436b09bd606..e0930076aaa3 100644 --- a/crates/rome_js_formatter/src/js/statements/for_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/for_statement.rs @@ -1,11 +1,12 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsAnyStatement; use rome_js_syntax::JsForStatement; use rome_js_syntax::JsForStatementFields; -impl FormatNode for JsForStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsForStatement, formatter: &Formatter) -> FormatResult { let JsForStatementFields { for_token, l_paren_token, @@ -16,45 +17,48 @@ impl FormatNode for JsForStatement { update, r_paren_token, body, - } = self.as_fields(); + } = node.as_fields(); let inner = if initializer.is_some() || test.is_some() || update.is_some() { formatted![ formatter, - initializer, - first_semi_token.format(formatter)?, - soft_line_break_or_space(), - test, - second_semi_token.format(formatter)?, - soft_line_break_or_space(), - update, + [ + initializer.format(), + first_semi_token.format(), + soft_line_break_or_space(), + test.format(), + second_semi_token.format(), + soft_line_break_or_space(), + update.format(), + ] ]? } else { formatted![ formatter, - first_semi_token.format(formatter)?, - second_semi_token.format(formatter)?, + [first_semi_token.format(), second_semi_token.format(),] ]? }; // Force semicolon insertion for empty bodies let body = body?; let body = if matches!(body, JsAnyStatement::JsEmptyStatement(_)) { - formatted![formatter, body.format(formatter)?, token(";")]? + formatted![formatter, [body.format(), token(";")]]? } else { - formatted![formatter, space_token(), body.format(formatter)?]? + formatted![formatter, [space_token(), body.format()]]? }; Ok(group_elements(formatted![ formatter, - for_token.format(formatter)?, - space_token(), - formatter.format_delimited_soft_block_indent( - &l_paren_token?, - inner, - &r_paren_token?, - )?, - body + [ + for_token.format(), + space_token(), + formatter.format_delimited_soft_block_indent( + &l_paren_token?, + inner, + &r_paren_token?, + )?, + body + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/statements/if_statement.rs b/crates/rome_js_formatter/src/js/statements/if_statement.rs index b4134eb87171..8d3a2be5c459 100644 --- a/crates/rome_js_formatter/src/js/statements/if_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/if_statement.rs @@ -1,12 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsSyntaxToken; use rome_js_syntax::{JsAnyStatement, JsElseClauseFields, JsIfStatement}; use rome_js_syntax::{JsElseClause, JsIfStatementFields}; -impl FormatNode for JsIfStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let (head, mut else_clause) = format_if_element(formatter, None, self)?; +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsIfStatement, formatter: &Formatter) -> FormatResult { + let (head, mut else_clause) = format_if_element(formatter, None, node)?; let mut if_chain = vec![head]; while let Some(clause) = else_clause.take() { @@ -25,10 +26,12 @@ impl FormatNode for JsIfStatement { alternate => { if_chain.push(formatted![ formatter, - space_token(), - else_token.format(formatter)?, - space_token(), - into_block(formatter, alternate)?, + [ + space_token(), + else_token.format(), + space_token(), + into_block(formatter, alternate)?, + ] ]?); } } @@ -55,21 +58,21 @@ fn format_if_element( let head = formatted![ formatter, - else_token.with_or_empty(|token| formatted![ - formatter, + [ + else_token.format().with_or_empty(|token| formatted![ + formatter, + [space_token(), token, space_token(),] + ]), + if_token.format(), space_token(), - token, + formatter.format_delimited_soft_block_indent( + &l_paren_token?, + formatted![formatter, [test.format()]]?, + &r_paren_token?, + )?, space_token(), - ]), - if_token.format(formatter)?, - space_token(), - formatter.format_delimited_soft_block_indent( - &l_paren_token?, - test.format(formatter)?, - &r_paren_token?, - )?, - space_token(), - into_block(formatter, consequent?)?, + into_block(formatter, consequent?)?, + ] ]?; Ok((head, else_clause)) @@ -78,7 +81,7 @@ fn format_if_element( /// Wraps the statement into a block if its not already a JsBlockStatement fn into_block(formatter: &Formatter, stmt: JsAnyStatement) -> FormatResult { if matches!(stmt, JsAnyStatement::JsBlockStatement(_)) { - return stmt.format(formatter); + return formatted![formatter, [stmt.format()]]; } // If the body is an empty statement, force a line break to ensure behavior @@ -86,17 +89,16 @@ fn into_block(formatter: &Formatter, stmt: JsAnyStatement) -> FormatResult FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsLabeledStatement, + formatter: &Formatter, + ) -> FormatResult { let JsLabeledStatementFields { label_token, colon_token, body, - } = self.as_fields(); + } = node.as_fields(); - let label = label_token.format(formatter)?; - let colon = colon_token.format(formatter)?; + let label = label_token.format(); + let colon = colon_token.format(); let body = body?; if matches!(body, JsAnyStatement::JsEmptyStatement(_)) { // If the body is an empty statement, force semicolon insertion - let statement = body.format(formatter)?; - formatted![formatter, label, colon, statement, token(";")] + let statement = body.format(); + formatted![formatter, [label, colon, statement, token(";")]] } else { - let statement = body.format(formatter)?; - formatted![formatter, label, colon, space_token(), statement] + let statement = body.format(); + formatted![formatter, [label, colon, space_token(), statement]] } } } diff --git a/crates/rome_js_formatter/src/js/statements/return_statement.rs b/crates/rome_js_formatter/src/js/statements/return_statement.rs index 46b109c5a9ee..38dcfb4dc292 100644 --- a/crates/rome_js_formatter/src/js/statements/return_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/return_statement.rs @@ -1,17 +1,21 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::{JsReturnStatement, JsReturnStatementFields, JsSyntaxKind}; use rome_rowan::AstNode; -impl FormatNode for JsReturnStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsReturnStatement, + formatter: &Formatter, + ) -> FormatResult { let JsReturnStatementFields { return_token, argument, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - let return_token = return_token.format(formatter)?; + let return_token = return_token.format(); let argument = if let Some(argument) = argument { if matches!( @@ -20,16 +24,20 @@ impl FormatNode for JsReturnStatement { ) { formatted![ formatter, - space_token(), - group_elements(formatted![ - formatter, - token("("), - soft_block_indent(argument.format(formatter)?), - token(")") - ]?), + [ + space_token(), + group_elements(formatted![ + formatter, + [ + token("("), + soft_block_indent(formatted![formatter, [argument.format()]]?), + token(")") + ] + ]?), + ] ]? } else { - formatted![formatter, space_token(), argument.format(formatter)?]? + formatted![formatter, [space_token(), argument.format()]]? } } else { empty_element() @@ -37,7 +45,7 @@ impl FormatNode for JsReturnStatement { format_with_semicolon( formatter, - formatted![formatter, return_token, argument]?, + formatted![formatter, [return_token, argument]]?, semicolon_token, ) } diff --git a/crates/rome_js_formatter/src/js/statements/switch_statement.rs b/crates/rome_js_formatter/src/js/statements/switch_statement.rs index d18d25c28a92..24fcc556bccd 100644 --- a/crates/rome_js_formatter/src/js/statements/switch_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/switch_statement.rs @@ -1,9 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsSwitchStatement, JsSwitchStatementFields}; use rome_rowan::{AstNode, AstNodeList}; -impl FormatNode for JsSwitchStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsSwitchStatement, + formatter: &Formatter, + ) -> FormatResult { let JsSwitchStatementFields { switch_token, l_paren_token, @@ -12,32 +16,34 @@ impl FormatNode for JsSwitchStatement { l_curly_token, cases, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - switch_token.format(formatter)?, - space_token(), - formatter.format_delimited_soft_block_indent( - &l_paren_token?, - discriminant.format(formatter)?, - &r_paren_token?, - )?, - space_token(), - formatter.format_delimited_block_indent( - &l_curly_token?, - if cases.is_empty() { - hard_line_break() - } else { - join_elements_hard_line( - cases - .iter() - .map(|node| node.syntax().clone()) - .zip(formatter.format_all(cases)?), - ) - }, - &r_curly_token? - )? + [ + switch_token.format(), + space_token(), + formatter.format_delimited_soft_block_indent( + &l_paren_token?, + formatted![formatter, [discriminant.format()]]?, + &r_paren_token?, + )?, + space_token(), + formatter.format_delimited_block_indent( + &l_curly_token?, + if cases.is_empty() { + hard_line_break() + } else { + join_elements_hard_line( + cases + .iter() + .map(|node| node.syntax().clone()) + .zip(formatter.format_all(cases.iter().formatted())?), + ) + }, + &r_curly_token? + )? + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/statements/throw_statement.rs b/crates/rome_js_formatter/src/js/statements/throw_statement.rs index ba87593f7b03..a4c83e5eb9db 100644 --- a/crates/rome_js_formatter/src/js/statements/throw_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/throw_statement.rs @@ -1,23 +1,27 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsThrowStatement; use rome_js_syntax::JsThrowStatementFields; -impl FormatNode for JsThrowStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsThrowStatement, + formatter: &Formatter, + ) -> FormatResult { let JsThrowStatementFields { throw_token, argument, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - let throw_token = throw_token.format(formatter)?; - let exception = argument.format(formatter)?; + let throw_token = throw_token.format(); + let exception = argument.format(); format_with_semicolon( formatter, - formatted![formatter, throw_token, space_token(), exception]?, + formatted![formatter, [throw_token, space_token(), exception]]?, semicolon_token, ) } diff --git a/crates/rome_js_formatter/src/js/statements/try_finally_statement.rs b/crates/rome_js_formatter/src/js/statements/try_finally_statement.rs index 341d2b68c9c4..a9f4ea4a3dba 100644 --- a/crates/rome_js_formatter/src/js/statements/try_finally_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/try_finally_statement.rs @@ -1,28 +1,36 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsTryFinallyStatement; use rome_js_syntax::JsTryFinallyStatementFields; -impl FormatNode for JsTryFinallyStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsTryFinallyStatement, + formatter: &Formatter, + ) -> FormatResult { let JsTryFinallyStatementFields { try_token, body, catch_clause, finally_clause, - } = self.as_fields(); - - let formatted_catch_clause = catch_clause - .with_or_empty(|catch_clause| formatted![formatter, space_token(), catch_clause]); + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - try_token.format(formatter)?, - space_token(), - body.format(formatter)?, - formatted_catch_clause, - space_token(), - finally_clause.format(formatter)? + [ + try_token.format(), + space_token(), + body.format(), + catch_clause + .format() + .with_or_empty(|catch_clause| formatted![ + formatter, + [space_token(), catch_clause] + ]), + space_token(), + finally_clause.format() + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/statements/try_statement.rs b/crates/rome_js_formatter/src/js/statements/try_statement.rs index 4f4a70cc04e7..f448be7e054a 100644 --- a/crates/rome_js_formatter/src/js/statements/try_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/try_statement.rs @@ -1,23 +1,26 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsTryStatement; use rome_js_syntax::JsTryStatementFields; -impl FormatNode for JsTryStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsTryStatement, formatter: &Formatter) -> FormatResult { let JsTryStatementFields { try_token, body, catch_clause, - } = self.as_fields(); + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - try_token.format(formatter)?, - space_token(), - body.format(formatter)?, - space_token(), - catch_clause.format(formatter)?, + [ + try_token.format(), + space_token(), + body.format(), + space_token(), + catch_clause.format(), + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/js/statements/variable_statement.rs b/crates/rome_js_formatter/src/js/statements/variable_statement.rs index 14848e8a6009..77b96bda3ee6 100644 --- a/crates/rome_js_formatter/src/js/statements/variable_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/variable_statement.rs @@ -1,16 +1,24 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::JsVariableStatement; use rome_js_syntax::JsVariableStatementFields; -impl FormatNode for JsVariableStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsVariableStatement, + formatter: &Formatter, + ) -> FormatResult { let JsVariableStatementFields { declaration, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - format_with_semicolon(formatter, declaration.format(formatter)?, semicolon_token) + format_with_semicolon( + formatter, + formatted![formatter, [declaration.format()]]?, + semicolon_token, + ) } } diff --git a/crates/rome_js_formatter/src/js/statements/while_statement.rs b/crates/rome_js_formatter/src/js/statements/while_statement.rs index 2aa4e58f3bee..3c27a140e464 100644 --- a/crates/rome_js_formatter/src/js/statements/while_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/while_statement.rs @@ -1,30 +1,36 @@ use crate::prelude::*; use crate::utils::format_head_body_statement; +use crate::FormatNodeFields; use rome_js_syntax::JsWhileStatement; use rome_js_syntax::JsWhileStatementFields; -impl FormatNode for JsWhileStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsWhileStatement, + formatter: &Formatter, + ) -> FormatResult { let JsWhileStatementFields { while_token, l_paren_token, test, r_paren_token, body, - } = self.as_fields(); + } = node.as_fields(); format_head_body_statement( formatter, formatted![ formatter, - while_token.format(formatter)?, - space_token(), - formatter.format_delimited_soft_block_indent( - &l_paren_token?, - test.format(formatter)?, - &r_paren_token?, - )?, + [ + while_token.format(), + space_token(), + formatter.format_delimited_soft_block_indent( + &l_paren_token?, + formatted![formatter, [test.format()]]?, + &r_paren_token?, + )?, + ] ]?, body?, ) diff --git a/crates/rome_js_formatter/src/js/statements/with_statement.rs b/crates/rome_js_formatter/src/js/statements/with_statement.rs index 15aebf10cbc1..ef5578ffcd0d 100644 --- a/crates/rome_js_formatter/src/js/statements/with_statement.rs +++ b/crates/rome_js_formatter/src/js/statements/with_statement.rs @@ -1,30 +1,33 @@ use crate::prelude::*; use crate::utils::format_head_body_statement; +use crate::FormatNodeFields; use rome_js_syntax::JsWithStatement; use rome_js_syntax::JsWithStatementFields; -impl FormatNode for JsWithStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsWithStatement, formatter: &Formatter) -> FormatResult { let JsWithStatementFields { with_token, l_paren_token, object, r_paren_token, body, - } = self.as_fields(); + } = node.as_fields(); format_head_body_statement( formatter, formatted![ formatter, - with_token.format(formatter)?, - space_token(), - formatter.format_delimited_soft_block_indent( - &l_paren_token?, - object.format(formatter)?, - &r_paren_token?, - )?, + [ + with_token.format(), + space_token(), + formatter.format_delimited_soft_block_indent( + &l_paren_token?, + formatted![formatter, [object.format()]]?, + &r_paren_token?, + )?, + ] ]?, body?, ) diff --git a/crates/rome_js_formatter/src/js/unknown/unknown.rs b/crates/rome_js_formatter/src/js/unknown/unknown.rs index 26716b2426f3..43770307461e 100644 --- a/crates/rome_js_formatter/src/js/unknown/unknown.rs +++ b/crates/rome_js_formatter/src/js/unknown/unknown.rs @@ -1,11 +1,11 @@ use crate::formatter::unknown_node; -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsUnknown; use rome_rowan::AstNode; -impl FormatNode for JsUnknown { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - unknown_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsUnknown, formatter: &Formatter) -> FormatResult { + unknown_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/js/unknown/unknown_assignment.rs b/crates/rome_js_formatter/src/js/unknown/unknown_assignment.rs index 35f5019f925b..9bb7387e36e0 100644 --- a/crates/rome_js_formatter/src/js/unknown/unknown_assignment.rs +++ b/crates/rome_js_formatter/src/js/unknown/unknown_assignment.rs @@ -1,11 +1,14 @@ use crate::formatter::verbatim_node; -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsUnknownAssignment; use rome_rowan::AstNode; -impl FormatNode for JsUnknownAssignment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - verbatim_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsUnknownAssignment, + formatter: &Formatter, + ) -> FormatResult { + verbatim_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/js/unknown/unknown_binding.rs b/crates/rome_js_formatter/src/js/unknown/unknown_binding.rs index f09be16a8e0b..7ea185128301 100644 --- a/crates/rome_js_formatter/src/js/unknown/unknown_binding.rs +++ b/crates/rome_js_formatter/src/js/unknown/unknown_binding.rs @@ -1,12 +1,15 @@ -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; use crate::formatter::unknown_node; +use crate::FormatNodeFields; use rome_js_syntax::JsUnknownBinding; use rome_rowan::AstNode; -impl FormatNode for JsUnknownBinding { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - unknown_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsUnknownBinding, + formatter: &Formatter, + ) -> FormatResult { + unknown_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/js/unknown/unknown_expression.rs b/crates/rome_js_formatter/src/js/unknown/unknown_expression.rs index add713a84f44..a1a7bd2463b6 100644 --- a/crates/rome_js_formatter/src/js/unknown/unknown_expression.rs +++ b/crates/rome_js_formatter/src/js/unknown/unknown_expression.rs @@ -1,12 +1,15 @@ -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; use crate::formatter::unknown_node; +use crate::FormatNodeFields; use rome_js_syntax::JsUnknownExpression; use rome_rowan::AstNode; -impl FormatNode for JsUnknownExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - unknown_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsUnknownExpression, + formatter: &Formatter, + ) -> FormatResult { + unknown_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/js/unknown/unknown_import_assertion_entry.rs b/crates/rome_js_formatter/src/js/unknown/unknown_import_assertion_entry.rs index b184ea50ddc1..809baf444c14 100644 --- a/crates/rome_js_formatter/src/js/unknown/unknown_import_assertion_entry.rs +++ b/crates/rome_js_formatter/src/js/unknown/unknown_import_assertion_entry.rs @@ -1,12 +1,17 @@ -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; use crate::formatter::unknown_node; +use crate::FormatNodeFields; use rome_js_syntax::JsUnknownImportAssertionEntry; use rome_rowan::AstNode; -impl FormatNode for JsUnknownImportAssertionEntry { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - unknown_node(self.syntax()).format(formatter) +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsUnknownImportAssertionEntry, + formatter: &Formatter, + ) -> FormatResult { + unknown_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/js/unknown/unknown_member.rs b/crates/rome_js_formatter/src/js/unknown/unknown_member.rs index 65dfe76f74e0..5570968b96c6 100644 --- a/crates/rome_js_formatter/src/js/unknown/unknown_member.rs +++ b/crates/rome_js_formatter/src/js/unknown/unknown_member.rs @@ -1,12 +1,12 @@ -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; use crate::formatter::unknown_node; +use crate::FormatNodeFields; use rome_js_syntax::JsUnknownMember; use rome_rowan::AstNode; -impl FormatNode for JsUnknownMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - unknown_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsUnknownMember, formatter: &Formatter) -> FormatResult { + unknown_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/js/unknown/unknown_named_import_specifier.rs b/crates/rome_js_formatter/src/js/unknown/unknown_named_import_specifier.rs index 829b5935997c..9ab2eeebddb8 100644 --- a/crates/rome_js_formatter/src/js/unknown/unknown_named_import_specifier.rs +++ b/crates/rome_js_formatter/src/js/unknown/unknown_named_import_specifier.rs @@ -1,12 +1,17 @@ -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; use crate::formatter::unknown_node; +use crate::FormatNodeFields; use rome_js_syntax::JsUnknownNamedImportSpecifier; use rome_rowan::AstNode; -impl FormatNode for JsUnknownNamedImportSpecifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - unknown_node(self.syntax()).format(formatter) +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsUnknownNamedImportSpecifier, + formatter: &Formatter, + ) -> FormatResult { + unknown_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/js/unknown/unknown_parameter.rs b/crates/rome_js_formatter/src/js/unknown/unknown_parameter.rs index 4ba4b5ababbc..04aa7d9019d7 100644 --- a/crates/rome_js_formatter/src/js/unknown/unknown_parameter.rs +++ b/crates/rome_js_formatter/src/js/unknown/unknown_parameter.rs @@ -1,12 +1,15 @@ -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; use crate::formatter::unknown_node; +use crate::FormatNodeFields; use rome_js_syntax::JsUnknownParameter; use rome_rowan::AstNode; -impl FormatNode for JsUnknownParameter { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - unknown_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsUnknownParameter, + formatter: &Formatter, + ) -> FormatResult { + unknown_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/js/unknown/unknown_statement.rs b/crates/rome_js_formatter/src/js/unknown/unknown_statement.rs index a957b074c74d..63590ac66e0a 100644 --- a/crates/rome_js_formatter/src/js/unknown/unknown_statement.rs +++ b/crates/rome_js_formatter/src/js/unknown/unknown_statement.rs @@ -1,12 +1,15 @@ -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; use crate::formatter::unknown_node; +use crate::FormatNodeFields; use rome_js_syntax::JsUnknownStatement; use rome_rowan::AstNode; -impl FormatNode for JsUnknownStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - unknown_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsUnknownStatement, + formatter: &Formatter, + ) -> FormatResult { + unknown_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/jsx/any/attribute.rs b/crates/rome_js_formatter/src/jsx/any/attribute.rs index fb1718c57891..c57f7e1ef807 100644 --- a/crates/rome_js_formatter/src/jsx/any/attribute.rs +++ b/crates/rome_js_formatter/src/jsx/any/attribute.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsxAnyAttribute; use crate::prelude::*; use rome_js_syntax::JsxAnyAttribute; -impl Format for JsxAnyAttribute { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsxAttribute(node) => node.format(formatter), - Self::JsxSpreadAttribute(node) => node.format(formatter), +impl FormatRule for FormatJsxAnyAttribute { + fn format(node: &JsxAnyAttribute, formatter: &Formatter) -> FormatResult { + match node { + JsxAnyAttribute::JsxAttribute(node) => formatted![formatter, [node.format()]], + JsxAnyAttribute::JsxSpreadAttribute(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/jsx/any/attribute_name.rs b/crates/rome_js_formatter/src/jsx/any/attribute_name.rs index e4cd58ce1204..6646f7baf986 100644 --- a/crates/rome_js_formatter/src/jsx/any/attribute_name.rs +++ b/crates/rome_js_formatter/src/jsx/any/attribute_name.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsxAnyAttributeName; use crate::prelude::*; use rome_js_syntax::JsxAnyAttributeName; -impl Format for JsxAnyAttributeName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsxName(node) => node.format(formatter), - Self::JsxNamespaceName(node) => node.format(formatter), +impl FormatRule for FormatJsxAnyAttributeName { + fn format(node: &JsxAnyAttributeName, formatter: &Formatter) -> FormatResult { + match node { + JsxAnyAttributeName::JsxName(node) => formatted![formatter, [node.format()]], + JsxAnyAttributeName::JsxNamespaceName(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/jsx/any/attribute_value.rs b/crates/rome_js_formatter/src/jsx/any/attribute_value.rs index 5bdad4bbe722..616feb5da057 100644 --- a/crates/rome_js_formatter/src/jsx/any/attribute_value.rs +++ b/crates/rome_js_formatter/src/jsx/any/attribute_value.rs @@ -1,13 +1,16 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsxAnyAttributeValue; use crate::prelude::*; use rome_js_syntax::JsxAnyAttributeValue; -impl Format for JsxAnyAttributeValue { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsxAnyTag(node) => node.format(formatter), - Self::JsxString(node) => node.format(formatter), - Self::JsxExpressionAttributeValue(node) => node.format(formatter), +impl FormatRule for FormatJsxAnyAttributeValue { + fn format(node: &JsxAnyAttributeValue, formatter: &Formatter) -> FormatResult { + match node { + JsxAnyAttributeValue::JsxAnyTag(node) => formatted![formatter, [node.format()]], + JsxAnyAttributeValue::JsxString(node) => formatted![formatter, [node.format()]], + JsxAnyAttributeValue::JsxExpressionAttributeValue(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/jsx/any/child.rs b/crates/rome_js_formatter/src/jsx/any/child.rs index d39c4ec797ec..4a6ea72d82d5 100644 --- a/crates/rome_js_formatter/src/jsx/any/child.rs +++ b/crates/rome_js_formatter/src/jsx/any/child.rs @@ -1,16 +1,17 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsxAnyChild; use crate::prelude::*; use rome_js_syntax::JsxAnyChild; -impl Format for JsxAnyChild { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsxElement(node) => node.format(formatter), - Self::JsxSelfClosingElement(node) => node.format(formatter), - Self::JsxText(node) => node.format(formatter), - Self::JsxExpressionChild(node) => node.format(formatter), - Self::JsxSpreadChild(node) => node.format(formatter), - Self::JsxFragment(node) => node.format(formatter), +impl FormatRule for FormatJsxAnyChild { + fn format(node: &JsxAnyChild, formatter: &Formatter) -> FormatResult { + match node { + JsxAnyChild::JsxElement(node) => formatted![formatter, [node.format()]], + JsxAnyChild::JsxSelfClosingElement(node) => formatted![formatter, [node.format()]], + JsxAnyChild::JsxText(node) => formatted![formatter, [node.format()]], + JsxAnyChild::JsxExpressionChild(node) => formatted![formatter, [node.format()]], + JsxAnyChild::JsxSpreadChild(node) => formatted![formatter, [node.format()]], + JsxAnyChild::JsxFragment(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/jsx/any/element_name.rs b/crates/rome_js_formatter/src/jsx/any/element_name.rs index 82aefa8574ec..837e616f6c86 100644 --- a/crates/rome_js_formatter/src/jsx/any/element_name.rs +++ b/crates/rome_js_formatter/src/jsx/any/element_name.rs @@ -1,14 +1,17 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsxAnyElementName; use crate::prelude::*; use rome_js_syntax::JsxAnyElementName; -impl Format for JsxAnyElementName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsxName(node) => node.format(formatter), - Self::JsxReferenceIdentifier(node) => node.format(formatter), - Self::JsxMemberName(node) => node.format(formatter), - Self::JsxNamespaceName(node) => node.format(formatter), +impl FormatRule for FormatJsxAnyElementName { + fn format(node: &JsxAnyElementName, formatter: &Formatter) -> FormatResult { + match node { + JsxAnyElementName::JsxName(node) => formatted![formatter, [node.format()]], + JsxAnyElementName::JsxReferenceIdentifier(node) => { + formatted![formatter, [node.format()]] + } + JsxAnyElementName::JsxMemberName(node) => formatted![formatter, [node.format()]], + JsxAnyElementName::JsxNamespaceName(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/jsx/any/name.rs b/crates/rome_js_formatter/src/jsx/any/name.rs index 6d038a83c678..8a700af19fc9 100644 --- a/crates/rome_js_formatter/src/jsx/any/name.rs +++ b/crates/rome_js_formatter/src/jsx/any/name.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsxAnyName; use crate::prelude::*; use rome_js_syntax::JsxAnyName; -impl Format for JsxAnyName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsxName(node) => node.format(formatter), - Self::JsxNamespaceName(node) => node.format(formatter), +impl FormatRule for FormatJsxAnyName { + fn format(node: &JsxAnyName, formatter: &Formatter) -> FormatResult { + match node { + JsxAnyName::JsxName(node) => formatted![formatter, [node.format()]], + JsxAnyName::JsxNamespaceName(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/jsx/any/object_name.rs b/crates/rome_js_formatter/src/jsx/any/object_name.rs index 04d8042f0f98..1c8ee1c66b90 100644 --- a/crates/rome_js_formatter/src/jsx/any/object_name.rs +++ b/crates/rome_js_formatter/src/jsx/any/object_name.rs @@ -1,13 +1,16 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsxAnyObjectName; use crate::prelude::*; use rome_js_syntax::JsxAnyObjectName; -impl Format for JsxAnyObjectName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsxReferenceIdentifier(node) => node.format(formatter), - Self::JsxMemberName(node) => node.format(formatter), - Self::JsxNamespaceName(node) => node.format(formatter), +impl FormatRule for FormatJsxAnyObjectName { + fn format(node: &JsxAnyObjectName, formatter: &Formatter) -> FormatResult { + match node { + JsxAnyObjectName::JsxReferenceIdentifier(node) => { + formatted![formatter, [node.format()]] + } + JsxAnyObjectName::JsxMemberName(node) => formatted![formatter, [node.format()]], + JsxAnyObjectName::JsxNamespaceName(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/jsx/any/tag.rs b/crates/rome_js_formatter/src/jsx/any/tag.rs index 12fe0cd1de90..93b737bdee5d 100644 --- a/crates/rome_js_formatter/src/jsx/any/tag.rs +++ b/crates/rome_js_formatter/src/jsx/any/tag.rs @@ -1,13 +1,14 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatJsxAnyTag; use crate::prelude::*; use rome_js_syntax::JsxAnyTag; -impl Format for JsxAnyTag { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsxElement(node) => node.format(formatter), - Self::JsxSelfClosingElement(node) => node.format(formatter), - Self::JsxFragment(node) => node.format(formatter), +impl FormatRule for FormatJsxAnyTag { + fn format(node: &JsxAnyTag, formatter: &Formatter) -> FormatResult { + match node { + JsxAnyTag::JsxElement(node) => formatted![formatter, [node.format()]], + JsxAnyTag::JsxSelfClosingElement(node) => formatted![formatter, [node.format()]], + JsxAnyTag::JsxFragment(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/jsx/attribute/attribute.rs b/crates/rome_js_formatter/src/jsx/attribute/attribute.rs index 1469f6652d61..e1c640894796 100644 --- a/crates/rome_js_formatter/src/jsx/attribute/attribute.rs +++ b/crates/rome_js_formatter/src/jsx/attribute/attribute.rs @@ -1,10 +1,11 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxAttribute, JsxAttributeFields}; -impl FormatNode for JsxAttribute { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsxAttributeFields { name, initializer } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsxAttribute, formatter: &Formatter) -> FormatResult { + let JsxAttributeFields { name, initializer } = node.as_fields(); - formatted![formatter, name.format(formatter)?, initializer] + formatted![formatter, [name.format(), initializer.format()]] } } diff --git a/crates/rome_js_formatter/src/jsx/attribute/attribute_initializer_clause.rs b/crates/rome_js_formatter/src/jsx/attribute/attribute_initializer_clause.rs index a598b7d0fef8..e67e8a290cdd 100644 --- a/crates/rome_js_formatter/src/jsx/attribute/attribute_initializer_clause.rs +++ b/crates/rome_js_formatter/src/jsx/attribute/attribute_initializer_clause.rs @@ -1,14 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxAttributeInitializerClause, JsxAttributeInitializerClauseFields}; -impl FormatNode for JsxAttributeInitializerClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsxAttributeInitializerClauseFields { eq_token, value } = self.as_fields(); +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &JsxAttributeInitializerClause, + formatter: &Formatter, + ) -> FormatResult { + let JsxAttributeInitializerClauseFields { eq_token, value } = node.as_fields(); - formatted![ - formatter, - eq_token.format(formatter)?, - value.format(formatter)? - ] + formatted![formatter, [eq_token.format(), value.format()]] } } diff --git a/crates/rome_js_formatter/src/jsx/attribute/expression_attribute_value.rs b/crates/rome_js_formatter/src/jsx/attribute/expression_attribute_value.rs index f37ac8b03ee3..e15ba54cc264 100644 --- a/crates/rome_js_formatter/src/jsx/attribute/expression_attribute_value.rs +++ b/crates/rome_js_formatter/src/jsx/attribute/expression_attribute_value.rs @@ -1,15 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{ JsAnyExpression, JsxExpressionAttributeValue, JsxExpressionAttributeValueFields, }; -impl FormatNode for JsxExpressionAttributeValue { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxExpressionAttributeValue, + formatter: &Formatter, + ) -> FormatResult { let JsxExpressionAttributeValueFields { l_curly_token, expression, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); let expression = expression?; @@ -50,16 +54,18 @@ impl FormatNode for JsxExpressionAttributeValue { | JsAnyExpression::JsArrayExpression(_) | JsAnyExpression::JsCallExpression(_) ) { - expression.format(formatter)? + formatted![formatter, [expression.format()]]? } else { - soft_block_indent(expression.format(formatter)?) + soft_block_indent(formatted![formatter, [expression.format()]]?) }; Ok(group_elements(formatted![ formatter, - l_curly_token.format(formatter)?, - formatted_expression, - r_curly_token.format(formatter)?, + [ + l_curly_token.format(), + formatted_expression, + r_curly_token.format(), + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/jsx/attribute/spread_attribute.rs b/crates/rome_js_formatter/src/jsx/attribute/spread_attribute.rs index 3858f58a5d8b..ee892278276f 100644 --- a/crates/rome_js_formatter/src/jsx/attribute/spread_attribute.rs +++ b/crates/rome_js_formatter/src/jsx/attribute/spread_attribute.rs @@ -1,21 +1,27 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxSpreadAttribute, JsxSpreadAttributeFields}; -impl FormatNode for JsxSpreadAttribute { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxSpreadAttribute, + formatter: &Formatter, + ) -> FormatResult { let JsxSpreadAttributeFields { l_curly_token, dotdotdot_token, argument, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - l_curly_token.format(formatter)?, - dotdotdot_token.format(formatter)?, - argument.format(formatter)?, - r_curly_token.format(formatter)?, + [ + l_curly_token.format(), + dotdotdot_token.format(), + argument.format(), + r_curly_token.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/jsx/auxiliary/expression_child.rs b/crates/rome_js_formatter/src/jsx/auxiliary/expression_child.rs index 7ac923739d71..6ee36d043abe 100644 --- a/crates/rome_js_formatter/src/jsx/auxiliary/expression_child.rs +++ b/crates/rome_js_formatter/src/jsx/auxiliary/expression_child.rs @@ -1,10 +1,14 @@ use crate::formatter::verbatim_node; use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsxExpressionChild; use rome_rowan::AstNode; -impl FormatNode for JsxExpressionChild { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - verbatim_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxExpressionChild, + formatter: &Formatter, + ) -> FormatResult { + verbatim_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/jsx/auxiliary/name.rs b/crates/rome_js_formatter/src/jsx/auxiliary/name.rs index 0d3155e691f2..6f2eb23dec43 100644 --- a/crates/rome_js_formatter/src/jsx/auxiliary/name.rs +++ b/crates/rome_js_formatter/src/jsx/auxiliary/name.rs @@ -1,11 +1,11 @@ -use crate::{Format, FormatElement, FormatNode, Formatter}; -use rome_formatter::FormatResult; +use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxName, JsxNameFields}; -impl FormatNode for JsxName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsxNameFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsxName, formatter: &Formatter) -> FormatResult { + let JsxNameFields { value_token } = node.as_fields(); - value_token.format(formatter) + formatted![formatter, [value_token.format()]] } } diff --git a/crates/rome_js_formatter/src/jsx/auxiliary/namespace_name.rs b/crates/rome_js_formatter/src/jsx/auxiliary/namespace_name.rs index 15e8d8670616..c4fb45acbb97 100644 --- a/crates/rome_js_formatter/src/jsx/auxiliary/namespace_name.rs +++ b/crates/rome_js_formatter/src/jsx/auxiliary/namespace_name.rs @@ -1,19 +1,21 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxNamespaceName, JsxNamespaceNameFields}; -impl FormatNode for JsxNamespaceName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxNamespaceName, + formatter: &Formatter, + ) -> FormatResult { let JsxNamespaceNameFields { namespace, colon_token, name, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - namespace.format(formatter)?, - colon_token.format(formatter)?, - name.format(formatter)? + [namespace.format(), colon_token.format(), name.format()] ] } } diff --git a/crates/rome_js_formatter/src/jsx/auxiliary/reference_identifier.rs b/crates/rome_js_formatter/src/jsx/auxiliary/reference_identifier.rs index 0de894a2e8b2..a1ea77ea8d49 100644 --- a/crates/rome_js_formatter/src/jsx/auxiliary/reference_identifier.rs +++ b/crates/rome_js_formatter/src/jsx/auxiliary/reference_identifier.rs @@ -1,8 +1,12 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsxReferenceIdentifier; -impl FormatNode for JsxReferenceIdentifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.value_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxReferenceIdentifier, + formatter: &Formatter, + ) -> FormatResult { + formatted![formatter, [node.value_token().format()]] } } diff --git a/crates/rome_js_formatter/src/jsx/auxiliary/spread_child.rs b/crates/rome_js_formatter/src/jsx/auxiliary/spread_child.rs index 64093f2b83d4..32d9dbd4485a 100644 --- a/crates/rome_js_formatter/src/jsx/auxiliary/spread_child.rs +++ b/crates/rome_js_formatter/src/jsx/auxiliary/spread_child.rs @@ -1,10 +1,11 @@ use crate::formatter::verbatim_node; use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsxSpreadChild; use rome_rowan::AstNode; -impl FormatNode for JsxSpreadChild { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - verbatim_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsxSpreadChild, formatter: &Formatter) -> FormatResult { + verbatim_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/jsx/auxiliary/string.rs b/crates/rome_js_formatter/src/jsx/auxiliary/string.rs index 68d68ccc1f85..b15cb203e940 100644 --- a/crates/rome_js_formatter/src/jsx/auxiliary/string.rs +++ b/crates/rome_js_formatter/src/jsx/auxiliary/string.rs @@ -1,8 +1,9 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsxString; -impl FormatNode for JsxString { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.value_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsxString, formatter: &Formatter) -> FormatResult { + formatted![formatter, [node.value_token().format()]] } } diff --git a/crates/rome_js_formatter/src/jsx/auxiliary/text.rs b/crates/rome_js_formatter/src/jsx/auxiliary/text.rs index 1383e7a8dc69..dee32a7eca81 100644 --- a/crates/rome_js_formatter/src/jsx/auxiliary/text.rs +++ b/crates/rome_js_formatter/src/jsx/auxiliary/text.rs @@ -1,12 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxText, JsxTextFields}; use std::borrow::Cow; use std::ops::Range; use std::str::CharIndices; -impl FormatNode for JsxText { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let JsxTextFields { value_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsxText, formatter: &Formatter) -> FormatResult { + let JsxTextFields { value_token } = node.as_fields(); let token = value_token?; let new_text = clean_jsx_text(token.text()); let start = token.text_range().start(); diff --git a/crates/rome_js_formatter/src/jsx/expressions/tag_expression.rs b/crates/rome_js_formatter/src/jsx/expressions/tag_expression.rs index 6f576304a3cd..8bbb8f53fd14 100644 --- a/crates/rome_js_formatter/src/jsx/expressions/tag_expression.rs +++ b/crates/rome_js_formatter/src/jsx/expressions/tag_expression.rs @@ -1,8 +1,12 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsxTagExpression; -impl FormatNode for JsxTagExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.tag().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxTagExpression, + formatter: &Formatter, + ) -> FormatResult { + formatted![formatter, [node.tag().format()]] } } diff --git a/crates/rome_js_formatter/src/jsx/lists/attribute_list.rs b/crates/rome_js_formatter/src/jsx/lists/attribute_list.rs index f0f9fae81bc9..f9501d7aa88c 100644 --- a/crates/rome_js_formatter/src/jsx/lists/attribute_list.rs +++ b/crates/rome_js_formatter/src/jsx/lists/attribute_list.rs @@ -1,8 +1,13 @@ +use crate::generated::FormatJsxAttributeList; use crate::prelude::*; use rome_js_syntax::JsxAttributeList; -impl Format for JsxAttributeList { - fn format(&self, formatter: &Formatter) -> FormatResult { - let attributes = join_elements(soft_line_break_or_space(), formatter.format_all(self)?); + +impl FormatRule for FormatJsxAttributeList { + fn format(node: &JsxAttributeList, formatter: &Formatter) -> FormatResult { + let attributes = join_elements( + soft_line_break_or_space(), + formatter.format_all(node.iter().formatted())?, + ); Ok(group_elements(soft_block_indent(attributes))) } diff --git a/crates/rome_js_formatter/src/jsx/lists/child_list.rs b/crates/rome_js_formatter/src/jsx/lists/child_list.rs index f3443bc64249..c3ddf9f3a956 100644 --- a/crates/rome_js_formatter/src/jsx/lists/child_list.rs +++ b/crates/rome_js_formatter/src/jsx/lists/child_list.rs @@ -1,10 +1,11 @@ use crate::formatter::verbatim_node; +use crate::generated::FormatJsxChildList; use crate::prelude::*; use rome_js_syntax::JsxChildList; use rome_rowan::AstNode; -impl Format for JsxChildList { - fn format(&self, formatter: &Formatter) -> FormatResult { - verbatim_node(self.syntax()).format(formatter) +impl FormatRule for FormatJsxChildList { + fn format(node: &JsxChildList, formatter: &Formatter) -> FormatResult { + verbatim_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/jsx/objects/member_name.rs b/crates/rome_js_formatter/src/jsx/objects/member_name.rs index ac581808ccf5..f782916f929c 100644 --- a/crates/rome_js_formatter/src/jsx/objects/member_name.rs +++ b/crates/rome_js_formatter/src/jsx/objects/member_name.rs @@ -1,19 +1,18 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxMemberName, JsxMemberNameFields}; -impl FormatNode for JsxMemberName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsxMemberName, formatter: &Formatter) -> FormatResult { let JsxMemberNameFields { object, dot_token, member, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - object.format(formatter)?, - dot_token.format(formatter)?, - member.format(formatter)?, + [object.format(), dot_token.format(), member.format(),] ] } } diff --git a/crates/rome_js_formatter/src/jsx/tag/closing_element.rs b/crates/rome_js_formatter/src/jsx/tag/closing_element.rs index 89686276aa46..27acba10382b 100644 --- a/crates/rome_js_formatter/src/jsx/tag/closing_element.rs +++ b/crates/rome_js_formatter/src/jsx/tag/closing_element.rs @@ -1,10 +1,14 @@ use crate::formatter::verbatim_node; use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsxClosingElement; use rome_rowan::AstNode; -impl FormatNode for JsxClosingElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - verbatim_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxClosingElement, + formatter: &Formatter, + ) -> FormatResult { + verbatim_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/jsx/tag/closing_fragment.rs b/crates/rome_js_formatter/src/jsx/tag/closing_fragment.rs index a5c179d6dbd3..9df529728a91 100644 --- a/crates/rome_js_formatter/src/jsx/tag/closing_fragment.rs +++ b/crates/rome_js_formatter/src/jsx/tag/closing_fragment.rs @@ -1,19 +1,25 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxClosingFragment, JsxClosingFragmentFields}; -impl FormatNode for JsxClosingFragment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxClosingFragment, + formatter: &Formatter, + ) -> FormatResult { let JsxClosingFragmentFields { r_angle_token, slash_token, l_angle_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - l_angle_token.format(formatter)?, - slash_token.format(formatter)?, - r_angle_token.format(formatter)? + [ + l_angle_token.format(), + slash_token.format(), + r_angle_token.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/jsx/tag/element.rs b/crates/rome_js_formatter/src/jsx/tag/element.rs index 311f170fc0ef..288c5d61ae5d 100644 --- a/crates/rome_js_formatter/src/jsx/tag/element.rs +++ b/crates/rome_js_formatter/src/jsx/tag/element.rs @@ -1,10 +1,11 @@ use crate::formatter::verbatim_node; use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsxElement; use rome_rowan::AstNode; -impl FormatNode for JsxElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - verbatim_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsxElement, formatter: &Formatter) -> FormatResult { + verbatim_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/jsx/tag/fragment.rs b/crates/rome_js_formatter/src/jsx/tag/fragment.rs index 4504183a15cb..1ba7ed678ca9 100644 --- a/crates/rome_js_formatter/src/jsx/tag/fragment.rs +++ b/crates/rome_js_formatter/src/jsx/tag/fragment.rs @@ -1,19 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxFragment, JsxFragmentFields}; -impl FormatNode for JsxFragment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &JsxFragment, formatter: &Formatter) -> FormatResult { let JsxFragmentFields { opening_fragment, children, closing_fragment, - } = self.as_fields(); + } = node.as_fields(); - let children = children.format(formatter)?; - Ok(format_elements![ - opening_fragment.format(formatter)?, - children, - closing_fragment.format(formatter)? - ]) + formatted![ + formatter, + [ + opening_fragment.format(), + children.format(), + closing_fragment.format() + ] + ] } } diff --git a/crates/rome_js_formatter/src/jsx/tag/opening_element.rs b/crates/rome_js_formatter/src/jsx/tag/opening_element.rs index d217a0b2f34f..1d33e5971a68 100644 --- a/crates/rome_js_formatter/src/jsx/tag/opening_element.rs +++ b/crates/rome_js_formatter/src/jsx/tag/opening_element.rs @@ -1,10 +1,14 @@ use crate::formatter::verbatim_node; use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::JsxOpeningElement; use rome_rowan::AstNode; -impl FormatNode for JsxOpeningElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - verbatim_node(self.syntax()).format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxOpeningElement, + formatter: &Formatter, + ) -> FormatResult { + verbatim_node(node.syntax()).format(formatter) } } diff --git a/crates/rome_js_formatter/src/jsx/tag/opening_fragment.rs b/crates/rome_js_formatter/src/jsx/tag/opening_fragment.rs index 2227936eb8c1..561f4cdf3153 100644 --- a/crates/rome_js_formatter/src/jsx/tag/opening_fragment.rs +++ b/crates/rome_js_formatter/src/jsx/tag/opening_fragment.rs @@ -1,16 +1,17 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{JsxOpeningFragment, JsxOpeningFragmentFields}; -impl FormatNode for JsxOpeningFragment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxOpeningFragment, + formatter: &Formatter, + ) -> FormatResult { let JsxOpeningFragmentFields { r_angle_token, l_angle_token, - } = self.as_fields(); + } = node.as_fields(); - Ok(format_elements![ - l_angle_token.format(formatter)?, - r_angle_token.format(formatter)? - ]) + formatted![formatter, [l_angle_token.format(), r_angle_token.format()]] } } diff --git a/crates/rome_js_formatter/src/jsx/tag/self_closing_element.rs b/crates/rome_js_formatter/src/jsx/tag/self_closing_element.rs index 4967232ba66f..b6b33058645a 100644 --- a/crates/rome_js_formatter/src/jsx/tag/self_closing_element.rs +++ b/crates/rome_js_formatter/src/jsx/tag/self_closing_element.rs @@ -1,18 +1,33 @@ use crate::prelude::*; -use rome_js_syntax::JsxSelfClosingElement; +use crate::FormatNodeFields; +use rome_js_syntax::{JsxSelfClosingElement, JsxSelfClosingElementFields}; + +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &JsxSelfClosingElement, + formatter: &Formatter, + ) -> FormatResult { + let JsxSelfClosingElementFields { + l_angle_token, + name, + type_arguments, + attributes, + slash_token, + r_angle_token, + } = node.as_fields(); -impl FormatNode for JsxSelfClosingElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { formatted![ formatter, - self.l_angle_token().format(formatter)?, - self.name().format(formatter)?, - self.type_arguments(), - space_token(), - self.attributes().format(formatter)?, - space_token(), - self.slash_token().format(formatter)?, - self.r_angle_token().format(formatter)? + [ + l_angle_token.format(), + name.format(), + type_arguments.format(), + space_token(), + attributes.format(), + space_token(), + slash_token.format(), + r_angle_token.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/lib.rs b/crates/rome_js_formatter/src/lib.rs index 7efdbba902ba..9766db9f7d53 100644 --- a/crates/rome_js_formatter/src/lib.rs +++ b/crates/rome_js_formatter/src/lib.rs @@ -1,193 +1,222 @@ //! Rome's official JavaScript formatter. mod cst; -mod format_extensions; -mod formatter; +pub mod formatter; mod js; mod jsx; -#[macro_use] -pub mod macros; pub mod prelude; mod ts; pub mod utils; use crate::formatter::suppressed_node; use crate::utils::has_formatter_suppressions; -pub use formatter::Formatter; pub(crate) use formatter::{format_leading_trivia, format_trailing_trivia, JsFormatter}; -pub use rome_formatter::{ - block_indent, comment, concat_elements, empty_element, empty_line, fill_elements, - format_element, format_elements, group_elements, hard_group_elements, hard_line_break, - if_group_breaks, if_group_fits_on_single_line, indent, join_elements, join_elements_hard_line, - join_elements_soft_line, join_elements_with, line_suffix, soft_block_indent, soft_line_break, - soft_line_break_or_space, soft_line_indent_or_space, space_token, token, FormatElement, - FormatOptions, FormatResult, Formatted, IndentStyle, Printed, QuoteStyle, Token, Verbatim, - LINE_TERMINATORS, -}; +use rome_formatter::prelude::*; +use rome_formatter::{FormatOptions, FormatOwnedWithRule, FormatRefWithRule, Formatted, Printed}; use rome_js_syntax::{JsLanguage, JsSyntaxNode, JsSyntaxToken}; +use rome_rowan::AstNode; +use rome_rowan::SyntaxResult; use rome_rowan::TextRange; -use rome_rowan::{AstNode, TextSize}; -use rome_rowan::{SyntaxResult, TokenAtOffset}; -/// Formatting trait for types that can create a formatted representation. The `rome_formatter` equivalent -/// to [std::fmt::Display]. -/// -/// ## Example -/// Implementing `Format` for a custom struct -/// -/// ``` -/// use rome_formatter::{format_elements, FormatElement, FormatOptions, hard_line_break, Token, FormatResult}; -/// use rome_js_formatter::{Format, format, formatted, Formatter}; -/// use rome_rowan::TextSize; -/// -/// struct Paragraph(String); -/// -/// impl Format for Paragraph {fn format(&self, formatter: &Formatter) -> FormatResult { -/// formatted![ -/// formatter, -/// hard_line_break(), -/// FormatElement::from(Token::new_dynamic(self.0.clone(), TextSize::from(0))), -/// hard_line_break(), -/// ] -/// } -/// } -/// -/// let paragraph = Paragraph(String::from("test")); -/// let printed = format(FormatOptions::default(), ¶graph) -/// .unwrap() -/// .print(); -/// -/// assert_eq!("test\n", printed.as_code()) -/// ``` -pub trait Format { - fn format(&self, formatter: &Formatter) -> FormatResult; +use crate::cst::FormatJsSyntaxNode; +use std::iter::FusedIterator; +use std::marker::PhantomData; + +// Per Crate + +/// Used to get an object that knows how to format this object. +pub trait AsFormat<'a> { + type Format: Format; + + /// Returns an object that is able to format this object. + fn format(&'a self) -> Self::Format; } -impl Format for &T +/// Implement [AsFormat] for all types that have an associated [FormatRule]. +impl<'a, T> AsFormat<'a> for &'a T where - T: ?Sized + Format, + T: AsFormat<'a>, { - fn format(&self, formatter: &Formatter) -> FormatResult { - Format::format(&**self, formatter) + type Format = T::Format; + + fn format(&'a self) -> Self::Format { + AsFormat::format(&**self) } } -impl Format for &mut T +/// Implement [AsFormat] for [SyntaxResult] where `T` implements [AsFormat]. +/// +/// Useful to format mandatory AST fields without having to unwrap the value first. +impl<'a, T> AsFormat<'a> for SyntaxResult where - T: ?Sized + Format, + T: AsFormat<'a>, { - fn format(&self, formatter: &Formatter) -> FormatResult { - Format::format(&**self, formatter) + type Format = SyntaxResult; + + fn format(&'a self) -> Self::Format { + match self { + Ok(value) => Ok(value.format()), + Err(err) => Err(*err), + } } } -impl Format for Option +/// Implement [AsFormat] for [Option] when `T` implements [AsFormat] +/// +/// Allows to call format on optional AST fields without having to unwrap the field first. +impl<'a, T> AsFormat<'a> for Option where - T: Format, + T: AsFormat<'a>, { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Some(value) => value.format(formatter), - None => Ok(empty_element()), - } + type Format = Option; + + fn format(&'a self) -> Self::Format { + self.as_ref().map(|value| value.format()) } } -impl Format for SyntaxResult +/// Used to convert this object into an object that can be formatted. +/// +/// The difference to [AsFormat] is that this trait takes ownership of `self`. +pub trait IntoFormat { + type Format: Format; + + fn into_format(self) -> Self::Format; +} + +impl IntoFormat for SyntaxResult where - T: Format, + T: IntoFormat, { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Ok(value) => value.format(formatter), - Err(err) => Err(err.into()), - } + type Format = SyntaxResult; + + fn into_format(self) -> Self::Format { + self.map(IntoFormat::into_format) } } -/// Implemented by traits that can be converted to a `FormatElement`. +/// Implement [AsFormat] for [Option] when `T` implements [AsFormat] /// -/// This is similar to [Format] but with the difference that it consumes `self`, allowing it to also -/// be implemented on [FormatElement].format_elements.rs -pub trait IntoFormatElement { - fn into_format_element(self, formatter: &Formatter) -> FormatResult; +/// Allows to call format on optional AST fields without having to unwrap the field first. +impl IntoFormat for Option +where + T: IntoFormat, +{ + type Format = Option; + + fn into_format(self) -> Self::Format { + self.map(IntoFormat::into_format) + } } -impl IntoFormatElement for FormatElement { - fn into_format_element(self, _: &Formatter) -> FormatResult { - Ok(self) +/// Formatting specific [Iterator] extensions +pub trait FormattedIterExt { + /// Converts every item to an object that knows how to format it. + fn formatted(self) -> FormattedIter + where + Self: Iterator + Sized, + Self::Item: IntoFormat, + { + FormattedIter { inner: self } } } -impl IntoFormatElement for T +impl FormattedIterExt for I where I: Iterator {} + +pub struct FormattedIter where - T: Format, + Iter: Iterator, { - fn into_format_element(self, formatter: &Formatter) -> FormatResult { - self.format(formatter) + inner: Iter, +} + +impl Iterator for FormattedIter +where + Iter: Iterator, + Item: IntoFormat, +{ + type Item = Item::Format; + + fn next(&mut self) -> Option { + Some(self.inner.next()?.into_format()) } } -// Per Crate +impl FusedIterator for FormattedIter +where + Iter: FusedIterator, + Item: IntoFormat, +{ +} -/// Formatting trait for JS AST Nodes. -/// -/// The code-gen generates a [Format] implementation for each `FormatNode` into the `format.rs` file. -pub trait FormatNode: AstNode { - /// Formats the node by calling into [FormatNode::format_fields] if the first token has no leading `rome-ignore` suppression comment. - /// - /// Formats the node "as is" if the node has a suppression comment. - fn format_node(&self, formatter: &Formatter) -> FormatResult { - let node = self.syntax(); - let element = if has_formatter_suppressions(node) { - suppressed_node(node).format(formatter)? +impl ExactSizeIterator for FormattedIter +where + Iter: Iterator + ExactSizeIterator, + Item: IntoFormat, +{ +} + +pub struct FormatNodeRule +where + T: AstNode, +{ + node: PhantomData, +} + +impl FormatRule for FormatNodeRule +where + N: AstNode, + FormatNodeRule: FormatNodeFields, +{ + fn format(node: &N, formatter: &Formatter) -> FormatResult { + let syntax = node.syntax(); + let element = if has_formatter_suppressions(syntax) { + suppressed_node(syntax).format(formatter)? } else { - self.format_fields(formatter)? + Self::format_fields(node, formatter)? }; Ok(element) } +} +pub trait FormatNodeFields +where + T: AstNode, +{ /// Formats the node's fields. - fn format_fields(&self, formatter: &Formatter) -> FormatResult; + fn format_fields(item: &T, formatter: &Formatter) -> FormatResult; } /// Format implementation specific to JavaScript tokens. -impl Format for JsSyntaxToken { - fn format(&self, formatter: &Formatter) -> FormatResult { - formatter.track_token(self); +pub struct FormatJsSyntaxToken; + +impl FormatRule for FormatJsSyntaxToken { + fn format(token: &JsSyntaxToken, formatter: &Formatter) -> FormatResult { + formatter.track_token(token); Ok(format_elements![ - format_leading_trivia(self, formatter::TriviaPrintMode::Full), - Token::from(self), - format_trailing_trivia(self), + format_leading_trivia(token, formatter::TriviaPrintMode::Full), + Token::from(token), + format_trailing_trivia(token), ]) } } -/// Formats any value that implements [Format]. -/// -/// Please note that [format_node] is preferred to format a [JsSyntaxNode] -pub fn format(options: FormatOptions, root: &dyn Format) -> FormatResult { - tracing::trace_span!("format").in_scope(move || { - let formatter = Formatter::new(options); - let element = root.format(&formatter)?; - Ok(Formatted::new(element, options)) - }) -} +impl<'a> AsFormat<'a> for JsSyntaxToken { + type Format = FormatRefWithRule<'a, JsSyntaxToken, FormatJsSyntaxToken>; -/// Formats a JavaScript (and its super languages) file based on its features. -/// -/// It returns a [Formatted] result, which the user can use to override a file. -pub fn format_node(options: FormatOptions, root: &JsSyntaxNode) -> FormatResult { - tracing::trace_span!("format_node").in_scope(move || { - let formatter = Formatter::new(options); - let element = root.format(&formatter)?; + fn format(&'a self) -> Self::Format { + FormatRefWithRule::new(self) + } +} - formatter.assert_formatted_all_tokens(root); +impl IntoFormat for JsSyntaxToken { + type Format = FormatOwnedWithRule; - Ok(Formatted::new(element, options)) - }) + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new(self) + } } /// Formats a range within a file, supported by Rome @@ -206,124 +235,14 @@ pub fn format_range( root: &JsSyntaxNode, range: TextRange, ) -> FormatResult { - // Find the tokens corresponding to the start and end of the range - let start_token = root.token_at_offset(range.start()); - let end_token = root.token_at_offset(range.end()); - - // If these tokens were not found this means either: - // 1. The input [SyntaxNode] was empty - // 2. The input node was not the root [SyntaxNode] of the file - // In the first case we can return an empty result immediately, - // otherwise default to the first and last tokens in the root node - let start_token = match start_token { - // If the start of the range lies between two tokens, - // start at the rightmost one - TokenAtOffset::Between(_, token) => token, - TokenAtOffset::Single(token) => token, - TokenAtOffset::None => match root.first_token() { - Some(token) => token, - // root node is empty - None => return Ok(Printed::new_empty()), - }, - }; - let end_token = match end_token { - // If the end of the range lies between two tokens, - // end at the leftmost one - TokenAtOffset::Between(token, _) => token, - TokenAtOffset::Single(token) => token, - TokenAtOffset::None => match root.last_token() { - Some(token) => token, - // root node is empty - None => return Ok(Printed::new_empty()), - }, - }; - - // Find the lowest common ancestor node for the start and end token - // by building the path to the root node from both tokens and - // iterating along the two paths at once to find the first divergence - #[allow(clippy::needless_collect)] - let start_to_root: Vec<_> = start_token.ancestors().collect(); - #[allow(clippy::needless_collect)] - let end_to_root: Vec<_> = end_token.ancestors().collect(); - - let common_root = start_to_root - .into_iter() - .rev() - .zip(end_to_root.into_iter().rev()) - .map_while(|(lhs, rhs)| if lhs == rhs { Some(lhs) } else { None }) - .last(); - - // Logically this should always return at least the root node, - // fallback to said node just in case - let common_root = common_root.as_ref().unwrap_or(root); - - // Perform the actual formatting of the root node with - // an appropriate indentation level - let formatted = format_sub_tree(options, common_root)?; - - // This finds the closest marker to the beginning of the source - // starting before or at said starting point, and the closest - // marker to the end of the source range starting after or at - // said ending point respectively - let mut range_start = None; - let mut range_end = None; - - let sourcemap = Vec::from(formatted.sourcemap()); - for marker in &sourcemap { - if let Some(start_dist) = marker.source.checked_sub(range.start()) { - range_start = match range_start { - Some((prev_marker, prev_dist)) => { - if start_dist < prev_dist { - Some((marker, start_dist)) - } else { - Some((prev_marker, prev_dist)) - } - } - None => Some((marker, start_dist)), - } - } - - if let Some(end_dist) = range.end().checked_sub(marker.source) { - range_end = match range_end { - Some((prev_marker, prev_dist)) => { - if end_dist < prev_dist { - Some((marker, end_dist)) - } else { - Some((prev_marker, prev_dist)) - } - } - None => Some((marker, end_dist)), - } - } - } + rome_formatter::format_range::<_, FormatJsSyntaxNode>(options, root, range) +} - // If no start or end were found, this means that the edge of the formatting - // range was near the edge of the input, and no marker were emitted before - // the start (or after the end) of the formatting range: in this case - // the start/end marker default to the start/end of the input - let (start_source, start_dest) = match range_start { - Some((start_marker, _)) => (start_marker.source, start_marker.dest), - None => (common_root.text_range().start(), TextSize::from(0)), - }; - let (end_source, end_dest) = match range_end { - Some((end_marker, _)) => (end_marker.source, end_marker.dest), - None => ( - common_root.text_range().end(), - TextSize::try_from(formatted.as_code().len()).expect("code length out of bounds"), - ), - }; - - let input_range = TextRange::new(start_source, end_source); - let output_range = TextRange::new(start_dest, end_dest); - let sourcemap = Vec::from(formatted.sourcemap()); - let verbatim_ranges = Vec::from(formatted.verbatim_ranges()); - let code = &formatted.into_code()[output_range]; - Ok(Printed::new( - code.into(), - Some(input_range), - sourcemap, - verbatim_ranges, - )) +/// Formats a JavaScript (and its super languages) file based on its features. +/// +/// It returns a [Formatted] result, which the user can use to override a file. +pub fn format_node(options: FormatOptions, root: &JsSyntaxNode) -> FormatResult { + rome_formatter::format_node(options, &root.format()) } /// Formats a single node within a file, supported by Rome. @@ -337,71 +256,15 @@ pub fn format_range( /// /// It returns a [Formatted] result pub fn format_sub_tree(options: FormatOptions, root: &JsSyntaxNode) -> FormatResult { - // Determine the initial indentation level for the printer by inspecting the trivia pieces - // of each token from the first token of the common root towards the start of the file - let mut tokens = std::iter::successors(root.first_token(), |token| token.prev_token()); - - // From the iterator of tokens, build an iterator of trivia pieces (once again the iterator is - // reversed, starting from the last trailing trivia towards the first leading trivia). - // The first token is handled specially as we only wan to consider its leading trivia pieces - let first_token = tokens.next(); - let first_token_trivias = first_token - .into_iter() - .flat_map(|token| token.leading_trivia().pieces().rev()); - - let next_tokens_trivias = tokens.flat_map(|token| { - token - .trailing_trivia() - .pieces() - .rev() - .chain(token.leading_trivia().pieces().rev()) - }); - - let trivias = first_token_trivias - .chain(next_tokens_trivias) - .filter(|piece| { - // We're only interested in newline and whitespace trivias, skip over comments - let is_newline = piece.is_newline(); - let is_whitespace = piece.is_whitespace(); - is_newline || is_whitespace - }); - - // Finally run the iterator until a newline trivia is found, and get the last whitespace trivia before it - let last_whitespace = trivias.map_while(|piece| piece.as_whitespace()).last(); - let initial_indent = match last_whitespace { - Some(trivia) => { - // This logic is based on the formatting options passed in - // the be user (or the editor) as we do not have any kind - // of indentation type detection yet. Unfortunately this - // may not actually match the current content of the file - let length = trivia.text().len() as u16; - match options.indent_style { - IndentStyle::Tab => length, - IndentStyle::Space(width) => length / u16::from(width), - } - } - // No whitespace was found between the start of the range - // and the start of the file - None => 0, - }; - - let formatted = format_node(options, root)?; - let printed = formatted.print_with_indent(initial_indent); - let sourcemap = Vec::from(printed.sourcemap()); - let verbatim_ranges = Vec::from(printed.verbatim_ranges()); - Ok(Printed::new( - printed.into_code(), - Some(root.text_range()), - sourcemap, - verbatim_ranges, - )) + rome_formatter::format_sub_tree(options, &root.format()) } #[cfg(test)] mod tests { - use super::{format_range, FormatOptions}; - use crate::IndentStyle; + use super::format_range; + + use rome_formatter::{FormatOptions, IndentStyle}; use rome_js_parser::parse_script; use rome_rowan::{TextRange, TextSize}; @@ -490,13 +353,14 @@ function() { #[cfg(test)] mod check_reformat; +#[rustfmt::skip] mod generated; #[cfg(test)] mod test { use crate::check_reformat::{check_reformat, CheckReformatParams}; use crate::format_node; - use crate::FormatOptions; + use rome_formatter::FormatOptions; use rome_js_parser::{parse, SourceType}; #[test] diff --git a/crates/rome_js_formatter/src/prelude.rs b/crates/rome_js_formatter/src/prelude.rs index 4cee939437eb..9dd092def6d6 100644 --- a/crates/rome_js_formatter/src/prelude.rs +++ b/crates/rome_js_formatter/src/prelude.rs @@ -1,6 +1,6 @@ //! This module provides important and useful traits to help to format tokens and nodes //! when implementing the [crate::FormatNode] trait. -pub use crate::format_extensions::{FormatOptional as _, FormatWith as _}; -pub(crate) use crate::{formatted, Format, FormatNode, Formatter, JsFormatter as _}; +pub(crate) use crate::{AsFormat as _, FormatNodeRule, FormattedIterExt, JsFormatter as _}; pub use rome_formatter::prelude::*; +pub use rome_rowan::{AstNode as _, AstNodeList as _, AstSeparatedList as _}; diff --git a/crates/rome_js_formatter/src/ts/any/external_module_declaration_body.rs b/crates/rome_js_formatter/src/ts/any/external_module_declaration_body.rs index d8c54cc531c6..865aeed58cbb 100644 --- a/crates/rome_js_formatter/src/ts/any/external_module_declaration_body.rs +++ b/crates/rome_js_formatter/src/ts/any/external_module_declaration_body.rs @@ -1,12 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyExternalModuleDeclarationBody; use crate::prelude::*; use rome_js_syntax::TsAnyExternalModuleDeclarationBody; -impl Format for TsAnyExternalModuleDeclarationBody { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsEmptyExternalModuleDeclarationBody(node) => node.format(formatter), - Self::TsModuleBlock(node) => node.format(formatter), +impl FormatRule for FormatTsAnyExternalModuleDeclarationBody { + fn format( + node: &TsAnyExternalModuleDeclarationBody, + formatter: &Formatter, + ) -> FormatResult { + match node { + TsAnyExternalModuleDeclarationBody::TsEmptyExternalModuleDeclarationBody(node) => { + formatted![formatter, [node.format()]] + } + TsAnyExternalModuleDeclarationBody::TsModuleBlock(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/index_signature_modifier.rs b/crates/rome_js_formatter/src/ts/any/index_signature_modifier.rs index b567436563b2..02dac5a9adec 100644 --- a/crates/rome_js_formatter/src/ts/any/index_signature_modifier.rs +++ b/crates/rome_js_formatter/src/ts/any/index_signature_modifier.rs @@ -1,12 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyIndexSignatureModifier; use crate::prelude::*; use rome_js_syntax::TsAnyIndexSignatureModifier; -impl Format for TsAnyIndexSignatureModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsStaticModifier(node) => node.format(formatter), - Self::TsReadonlyModifier(node) => node.format(formatter), +impl FormatRule for FormatTsAnyIndexSignatureModifier { + fn format( + node: &TsAnyIndexSignatureModifier, + formatter: &Formatter, + ) -> FormatResult { + match node { + TsAnyIndexSignatureModifier::JsStaticModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyIndexSignatureModifier::TsReadonlyModifier(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/method_signature_modifier.rs b/crates/rome_js_formatter/src/ts/any/method_signature_modifier.rs index 37cdba03094c..8488f300efc0 100644 --- a/crates/rome_js_formatter/src/ts/any/method_signature_modifier.rs +++ b/crates/rome_js_formatter/src/ts/any/method_signature_modifier.rs @@ -1,14 +1,26 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyMethodSignatureModifier; use crate::prelude::*; use rome_js_syntax::TsAnyMethodSignatureModifier; -impl Format for TsAnyMethodSignatureModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsAccessibilityModifier(node) => node.format(formatter), - Self::JsStaticModifier(node) => node.format(formatter), - Self::TsOverrideModifier(node) => node.format(formatter), - Self::TsAbstractModifier(node) => node.format(formatter), +impl FormatRule for FormatTsAnyMethodSignatureModifier { + fn format( + node: &TsAnyMethodSignatureModifier, + formatter: &Formatter, + ) -> FormatResult { + match node { + TsAnyMethodSignatureModifier::TsAccessibilityModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyMethodSignatureModifier::JsStaticModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyMethodSignatureModifier::TsOverrideModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyMethodSignatureModifier::TsAbstractModifier(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/module_name.rs b/crates/rome_js_formatter/src/ts/any/module_name.rs index b7d90cc45f73..0316ebc33866 100644 --- a/crates/rome_js_formatter/src/ts/any/module_name.rs +++ b/crates/rome_js_formatter/src/ts/any/module_name.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyModuleName; use crate::prelude::*; use rome_js_syntax::TsAnyModuleName; -impl Format for TsAnyModuleName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsIdentifierBinding(node) => node.format(formatter), - Self::TsQualifiedModuleName(node) => node.format(formatter), +impl FormatRule for FormatTsAnyModuleName { + fn format(node: &TsAnyModuleName, formatter: &Formatter) -> FormatResult { + match node { + TsAnyModuleName::TsIdentifierBinding(node) => formatted![formatter, [node.format()]], + TsAnyModuleName::TsQualifiedModuleName(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/ts/any/module_reference.rs b/crates/rome_js_formatter/src/ts/any/module_reference.rs index fd7985dfe0bc..4db49975bb9d 100644 --- a/crates/rome_js_formatter/src/ts/any/module_reference.rs +++ b/crates/rome_js_formatter/src/ts/any/module_reference.rs @@ -1,12 +1,15 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyModuleReference; use crate::prelude::*; use rome_js_syntax::TsAnyModuleReference; -impl Format for TsAnyModuleReference { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsAnyName(node) => node.format(formatter), - Self::TsExternalModuleReference(node) => node.format(formatter), +impl FormatRule for FormatTsAnyModuleReference { + fn format(node: &TsAnyModuleReference, formatter: &Formatter) -> FormatResult { + match node { + TsAnyModuleReference::TsAnyName(node) => formatted![formatter, [node.format()]], + TsAnyModuleReference::TsExternalModuleReference(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/name.rs b/crates/rome_js_formatter/src/ts/any/name.rs index 8c63a62e8a1a..6b59109230e3 100644 --- a/crates/rome_js_formatter/src/ts/any/name.rs +++ b/crates/rome_js_formatter/src/ts/any/name.rs @@ -1,12 +1,13 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyName; use crate::prelude::*; use rome_js_syntax::TsAnyName; -impl Format for TsAnyName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsReferenceIdentifier(node) => node.format(formatter), - Self::TsQualifiedName(node) => node.format(formatter), +impl FormatRule for FormatTsAnyName { + fn format(node: &TsAnyName, formatter: &Formatter) -> FormatResult { + match node { + TsAnyName::JsReferenceIdentifier(node) => formatted![formatter, [node.format()]], + TsAnyName::TsQualifiedName(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/ts/any/property_annotation.rs b/crates/rome_js_formatter/src/ts/any/property_annotation.rs index 99c678432c6f..0b444dd8948a 100644 --- a/crates/rome_js_formatter/src/ts/any/property_annotation.rs +++ b/crates/rome_js_formatter/src/ts/any/property_annotation.rs @@ -1,13 +1,23 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyPropertyAnnotation; use crate::prelude::*; use rome_js_syntax::TsAnyPropertyAnnotation; -impl Format for TsAnyPropertyAnnotation { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsTypeAnnotation(node) => node.format(formatter), - Self::TsOptionalPropertyAnnotation(node) => node.format(formatter), - Self::TsDefinitePropertyAnnotation(node) => node.format(formatter), +impl FormatRule for FormatTsAnyPropertyAnnotation { + fn format( + node: &TsAnyPropertyAnnotation, + formatter: &Formatter, + ) -> FormatResult { + match node { + TsAnyPropertyAnnotation::TsTypeAnnotation(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertyAnnotation::TsOptionalPropertyAnnotation(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertyAnnotation::TsDefinitePropertyAnnotation(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/property_parameter_modifier.rs b/crates/rome_js_formatter/src/ts/any/property_parameter_modifier.rs index 7e19f80e3d09..bda72d20d3cc 100644 --- a/crates/rome_js_formatter/src/ts/any/property_parameter_modifier.rs +++ b/crates/rome_js_formatter/src/ts/any/property_parameter_modifier.rs @@ -1,13 +1,23 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyPropertyParameterModifier; use crate::prelude::*; use rome_js_syntax::TsAnyPropertyParameterModifier; -impl Format for TsAnyPropertyParameterModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsAccessibilityModifier(node) => node.format(formatter), - Self::TsReadonlyModifier(node) => node.format(formatter), - Self::TsOverrideModifier(node) => node.format(formatter), +impl FormatRule for FormatTsAnyPropertyParameterModifier { + fn format( + node: &TsAnyPropertyParameterModifier, + formatter: &Formatter, + ) -> FormatResult { + match node { + TsAnyPropertyParameterModifier::TsAccessibilityModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertyParameterModifier::TsReadonlyModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertyParameterModifier::TsOverrideModifier(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/property_signature_annotation.rs b/crates/rome_js_formatter/src/ts/any/property_signature_annotation.rs index e5cb0d10887e..5d39f85e48b2 100644 --- a/crates/rome_js_formatter/src/ts/any/property_signature_annotation.rs +++ b/crates/rome_js_formatter/src/ts/any/property_signature_annotation.rs @@ -1,12 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyPropertySignatureAnnotation; use crate::prelude::*; use rome_js_syntax::TsAnyPropertySignatureAnnotation; -impl Format for TsAnyPropertySignatureAnnotation { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsTypeAnnotation(node) => node.format(formatter), - Self::TsOptionalPropertyAnnotation(node) => node.format(formatter), +impl FormatRule for FormatTsAnyPropertySignatureAnnotation { + fn format( + node: &TsAnyPropertySignatureAnnotation, + formatter: &Formatter, + ) -> FormatResult { + match node { + TsAnyPropertySignatureAnnotation::TsTypeAnnotation(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertySignatureAnnotation::TsOptionalPropertyAnnotation(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/property_signature_modifier.rs b/crates/rome_js_formatter/src/ts/any/property_signature_modifier.rs index ecf1b4be4b80..5e25837ceaea 100644 --- a/crates/rome_js_formatter/src/ts/any/property_signature_modifier.rs +++ b/crates/rome_js_formatter/src/ts/any/property_signature_modifier.rs @@ -1,16 +1,32 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyPropertySignatureModifier; use crate::prelude::*; use rome_js_syntax::TsAnyPropertySignatureModifier; -impl Format for TsAnyPropertySignatureModifier { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsDeclareModifier(node) => node.format(formatter), - Self::TsAccessibilityModifier(node) => node.format(formatter), - Self::JsStaticModifier(node) => node.format(formatter), - Self::TsReadonlyModifier(node) => node.format(formatter), - Self::TsOverrideModifier(node) => node.format(formatter), - Self::TsAbstractModifier(node) => node.format(formatter), +impl FormatRule for FormatTsAnyPropertySignatureModifier { + fn format( + node: &TsAnyPropertySignatureModifier, + formatter: &Formatter, + ) -> FormatResult { + match node { + TsAnyPropertySignatureModifier::TsDeclareModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertySignatureModifier::TsAccessibilityModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertySignatureModifier::JsStaticModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertySignatureModifier::TsReadonlyModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertySignatureModifier::TsOverrideModifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyPropertySignatureModifier::TsAbstractModifier(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/return_type.rs b/crates/rome_js_formatter/src/ts/any/return_type.rs index caa715f63608..12bd97562015 100644 --- a/crates/rome_js_formatter/src/ts/any/return_type.rs +++ b/crates/rome_js_formatter/src/ts/any/return_type.rs @@ -1,13 +1,14 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyReturnType; use crate::prelude::*; use rome_js_syntax::TsAnyReturnType; -impl Format for TsAnyReturnType { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsType(node) => node.format(formatter), - Self::TsPredicateReturnType(node) => node.format(formatter), - Self::TsAssertsReturnType(node) => node.format(formatter), +impl FormatRule for FormatTsAnyReturnType { + fn format(node: &TsAnyReturnType, formatter: &Formatter) -> FormatResult { + match node { + TsAnyReturnType::TsType(node) => formatted![formatter, [node.format()]], + TsAnyReturnType::TsPredicateReturnType(node) => formatted![formatter, [node.format()]], + TsAnyReturnType::TsAssertsReturnType(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/ts/any/template_element.rs b/crates/rome_js_formatter/src/ts/any/template_element.rs index 28c364fa9f98..9d2fa9adc5b7 100644 --- a/crates/rome_js_formatter/src/ts/any/template_element.rs +++ b/crates/rome_js_formatter/src/ts/any/template_element.rs @@ -1,12 +1,15 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyTemplateElement; use crate::prelude::*; use rome_js_syntax::TsAnyTemplateElement; -impl Format for TsAnyTemplateElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsTemplateChunkElement(node) => node.format(formatter), - Self::TsTemplateElement(node) => node.format(formatter), +impl FormatRule for FormatTsAnyTemplateElement { + fn format(node: &TsAnyTemplateElement, formatter: &Formatter) -> FormatResult { + match node { + TsAnyTemplateElement::TsTemplateChunkElement(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTemplateElement::TsTemplateElement(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/ts/any/ts_type.rs b/crates/rome_js_formatter/src/ts/any/ts_type.rs index ae0661a601a8..0771459c14f4 100644 --- a/crates/rome_js_formatter/src/ts/any/ts_type.rs +++ b/crates/rome_js_formatter/src/ts/any/ts_type.rs @@ -1,44 +1,45 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsType; use crate::prelude::*; use rome_js_syntax::TsType; -impl Format for TsType { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsAnyType(node) => node.format(formatter), - Self::TsUnknownType(node) => node.format(formatter), - Self::TsNumberType(node) => node.format(formatter), - Self::TsBooleanType(node) => node.format(formatter), - Self::TsBigintType(node) => node.format(formatter), - Self::TsStringType(node) => node.format(formatter), - Self::TsSymbolType(node) => node.format(formatter), - Self::TsVoidType(node) => node.format(formatter), - Self::TsUndefinedType(node) => node.format(formatter), - Self::TsNeverType(node) => node.format(formatter), - Self::TsParenthesizedType(node) => node.format(formatter), - Self::TsReferenceType(node) => node.format(formatter), - Self::TsArrayType(node) => node.format(formatter), - Self::TsTupleType(node) => node.format(formatter), - Self::TsTypeofType(node) => node.format(formatter), - Self::TsImportType(node) => node.format(formatter), - Self::TsTypeOperatorType(node) => node.format(formatter), - Self::TsIndexedAccessType(node) => node.format(formatter), - Self::TsMappedType(node) => node.format(formatter), - Self::TsObjectType(node) => node.format(formatter), - Self::TsNonPrimitiveType(node) => node.format(formatter), - Self::TsThisType(node) => node.format(formatter), - Self::TsNumberLiteralType(node) => node.format(formatter), - Self::TsBigIntLiteralType(node) => node.format(formatter), - Self::TsStringLiteralType(node) => node.format(formatter), - Self::TsNullLiteralType(node) => node.format(formatter), - Self::TsBooleanLiteralType(node) => node.format(formatter), - Self::TsTemplateLiteralType(node) => node.format(formatter), - Self::TsInferType(node) => node.format(formatter), - Self::TsIntersectionType(node) => node.format(formatter), - Self::TsUnionType(node) => node.format(formatter), - Self::TsFunctionType(node) => node.format(formatter), - Self::TsConstructorType(node) => node.format(formatter), - Self::TsConditionalType(node) => node.format(formatter), +impl FormatRule for FormatTsType { + fn format(node: &TsType, formatter: &Formatter) -> FormatResult { + match node { + TsType::TsAnyType(node) => formatted![formatter, [node.format()]], + TsType::TsUnknownType(node) => formatted![formatter, [node.format()]], + TsType::TsNumberType(node) => formatted![formatter, [node.format()]], + TsType::TsBooleanType(node) => formatted![formatter, [node.format()]], + TsType::TsBigintType(node) => formatted![formatter, [node.format()]], + TsType::TsStringType(node) => formatted![formatter, [node.format()]], + TsType::TsSymbolType(node) => formatted![formatter, [node.format()]], + TsType::TsVoidType(node) => formatted![formatter, [node.format()]], + TsType::TsUndefinedType(node) => formatted![formatter, [node.format()]], + TsType::TsNeverType(node) => formatted![formatter, [node.format()]], + TsType::TsParenthesizedType(node) => formatted![formatter, [node.format()]], + TsType::TsReferenceType(node) => formatted![formatter, [node.format()]], + TsType::TsArrayType(node) => formatted![formatter, [node.format()]], + TsType::TsTupleType(node) => formatted![formatter, [node.format()]], + TsType::TsTypeofType(node) => formatted![formatter, [node.format()]], + TsType::TsImportType(node) => formatted![formatter, [node.format()]], + TsType::TsTypeOperatorType(node) => formatted![formatter, [node.format()]], + TsType::TsIndexedAccessType(node) => formatted![formatter, [node.format()]], + TsType::TsMappedType(node) => formatted![formatter, [node.format()]], + TsType::TsObjectType(node) => formatted![formatter, [node.format()]], + TsType::TsNonPrimitiveType(node) => formatted![formatter, [node.format()]], + TsType::TsThisType(node) => formatted![formatter, [node.format()]], + TsType::TsNumberLiteralType(node) => formatted![formatter, [node.format()]], + TsType::TsBigIntLiteralType(node) => formatted![formatter, [node.format()]], + TsType::TsStringLiteralType(node) => formatted![formatter, [node.format()]], + TsType::TsNullLiteralType(node) => formatted![formatter, [node.format()]], + TsType::TsBooleanLiteralType(node) => formatted![formatter, [node.format()]], + TsType::TsTemplateLiteralType(node) => formatted![formatter, [node.format()]], + TsType::TsInferType(node) => formatted![formatter, [node.format()]], + TsType::TsIntersectionType(node) => formatted![formatter, [node.format()]], + TsType::TsUnionType(node) => formatted![formatter, [node.format()]], + TsType::TsFunctionType(node) => formatted![formatter, [node.format()]], + TsType::TsConstructorType(node) => formatted![formatter, [node.format()]], + TsType::TsConditionalType(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/ts/any/tuple_type_element.rs b/crates/rome_js_formatter/src/ts/any/tuple_type_element.rs index e2e3442e914d..c4b4caa7b1fd 100644 --- a/crates/rome_js_formatter/src/ts/any/tuple_type_element.rs +++ b/crates/rome_js_formatter/src/ts/any/tuple_type_element.rs @@ -1,14 +1,21 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyTupleTypeElement; use crate::prelude::*; use rome_js_syntax::TsAnyTupleTypeElement; -impl Format for TsAnyTupleTypeElement { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsNamedTupleTypeElement(node) => node.format(formatter), - Self::TsType(node) => node.format(formatter), - Self::TsRestTupleTypeElement(node) => node.format(formatter), - Self::TsOptionalTupleTypeElement(node) => node.format(formatter), +impl FormatRule for FormatTsAnyTupleTypeElement { + fn format(node: &TsAnyTupleTypeElement, formatter: &Formatter) -> FormatResult { + match node { + TsAnyTupleTypeElement::TsNamedTupleTypeElement(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTupleTypeElement::TsType(node) => formatted![formatter, [node.format()]], + TsAnyTupleTypeElement::TsRestTupleTypeElement(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTupleTypeElement::TsOptionalTupleTypeElement(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/type_member.rs b/crates/rome_js_formatter/src/ts/any/type_member.rs index b9e09ab8933c..2e6704095efb 100644 --- a/crates/rome_js_formatter/src/ts/any/type_member.rs +++ b/crates/rome_js_formatter/src/ts/any/type_member.rs @@ -1,18 +1,33 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyTypeMember; use crate::prelude::*; use rome_js_syntax::TsAnyTypeMember; -impl Format for TsAnyTypeMember { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsCallSignatureTypeMember(node) => node.format(formatter), - Self::TsPropertySignatureTypeMember(node) => node.format(formatter), - Self::TsConstructSignatureTypeMember(node) => node.format(formatter), - Self::TsMethodSignatureTypeMember(node) => node.format(formatter), - Self::TsGetterSignatureTypeMember(node) => node.format(formatter), - Self::TsSetterSignatureTypeMember(node) => node.format(formatter), - Self::TsIndexSignatureTypeMember(node) => node.format(formatter), - Self::JsUnknownMember(node) => node.format(formatter), +impl FormatRule for FormatTsAnyTypeMember { + fn format(node: &TsAnyTypeMember, formatter: &Formatter) -> FormatResult { + match node { + TsAnyTypeMember::TsCallSignatureTypeMember(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTypeMember::TsPropertySignatureTypeMember(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTypeMember::TsConstructSignatureTypeMember(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTypeMember::TsMethodSignatureTypeMember(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTypeMember::TsGetterSignatureTypeMember(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTypeMember::TsSetterSignatureTypeMember(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTypeMember::TsIndexSignatureTypeMember(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTypeMember::JsUnknownMember(node) => formatted![formatter, [node.format()]], } } } diff --git a/crates/rome_js_formatter/src/ts/any/type_predicate_parameter_name.rs b/crates/rome_js_formatter/src/ts/any/type_predicate_parameter_name.rs index e6cbd781509c..e1ddfc10849e 100644 --- a/crates/rome_js_formatter/src/ts/any/type_predicate_parameter_name.rs +++ b/crates/rome_js_formatter/src/ts/any/type_predicate_parameter_name.rs @@ -1,12 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyTypePredicateParameterName; use crate::prelude::*; use rome_js_syntax::TsAnyTypePredicateParameterName; -impl Format for TsAnyTypePredicateParameterName { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::JsReferenceIdentifier(node) => node.format(formatter), - Self::TsThisType(node) => node.format(formatter), +impl FormatRule for FormatTsAnyTypePredicateParameterName { + fn format( + node: &TsAnyTypePredicateParameterName, + formatter: &Formatter, + ) -> FormatResult { + match node { + TsAnyTypePredicateParameterName::JsReferenceIdentifier(node) => { + formatted![formatter, [node.format()]] + } + TsAnyTypePredicateParameterName::TsThisType(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/any/variable_annotation.rs b/crates/rome_js_formatter/src/ts/any/variable_annotation.rs index 5531828065c7..ec8f6a72334d 100644 --- a/crates/rome_js_formatter/src/ts/any/variable_annotation.rs +++ b/crates/rome_js_formatter/src/ts/any/variable_annotation.rs @@ -1,12 +1,20 @@ //! Generated file, do not edit by hand, see `xtask/codegen` +use crate::generated::FormatTsAnyVariableAnnotation; use crate::prelude::*; use rome_js_syntax::TsAnyVariableAnnotation; -impl Format for TsAnyVariableAnnotation { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { - Self::TsTypeAnnotation(node) => node.format(formatter), - Self::TsDefiniteVariableAnnotation(node) => node.format(formatter), +impl FormatRule for FormatTsAnyVariableAnnotation { + fn format( + node: &TsAnyVariableAnnotation, + formatter: &Formatter, + ) -> FormatResult { + match node { + TsAnyVariableAnnotation::TsTypeAnnotation(node) => { + formatted![formatter, [node.format()]] + } + TsAnyVariableAnnotation::TsDefiniteVariableAnnotation(node) => { + formatted![formatter, [node.format()]] + } } } } diff --git a/crates/rome_js_formatter/src/ts/assignments/as_assignment.rs b/crates/rome_js_formatter/src/ts/assignments/as_assignment.rs index 236ebe0057b6..8192e199533e 100644 --- a/crates/rome_js_formatter/src/ts/assignments/as_assignment.rs +++ b/crates/rome_js_formatter/src/ts/assignments/as_assignment.rs @@ -1,22 +1,25 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsAsAssignment; use rome_js_syntax::TsAsAssignmentFields; -impl FormatNode for TsAsAssignment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsAsAssignment, formatter: &Formatter) -> FormatResult { let TsAsAssignmentFields { assignment, as_token, ty, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - assignment.format(formatter)?, - space_token(), - as_token.format(formatter)?, - space_token(), - ty.format(formatter)?, + [ + assignment.format(), + space_token(), + as_token.format(), + space_token(), + ty.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/assignments/non_null_assertion_assignment.rs b/crates/rome_js_formatter/src/ts/assignments/non_null_assertion_assignment.rs index 72f3647dea91..6a5d84506fb2 100644 --- a/crates/rome_js_formatter/src/ts/assignments/non_null_assertion_assignment.rs +++ b/crates/rome_js_formatter/src/ts/assignments/non_null_assertion_assignment.rs @@ -1,17 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsNonNullAssertionAssignment; use rome_js_syntax::TsNonNullAssertionAssignmentFields; -impl FormatNode for TsNonNullAssertionAssignment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsNonNullAssertionAssignment, + formatter: &Formatter, + ) -> FormatResult { let TsNonNullAssertionAssignmentFields { assignment, excl_token, - } = self.as_fields(); - formatted![ - formatter, - assignment.format(formatter)?, - excl_token.format(formatter)? - ] + } = node.as_fields(); + formatted![formatter, [assignment.format(), excl_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/assignments/type_assertion_assignment.rs b/crates/rome_js_formatter/src/ts/assignments/type_assertion_assignment.rs index 9d20d19282c9..2f0da90ca35a 100644 --- a/crates/rome_js_formatter/src/ts/assignments/type_assertion_assignment.rs +++ b/crates/rome_js_formatter/src/ts/assignments/type_assertion_assignment.rs @@ -1,25 +1,31 @@ use crate::prelude::*; use rome_js_syntax::TsTypeAssertionAssignmentFields; +use crate::FormatNodeFields; use rome_js_syntax::TsTypeAssertionAssignment; -impl FormatNode for TsTypeAssertionAssignment { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTypeAssertionAssignment, + formatter: &Formatter, + ) -> FormatResult { let TsTypeAssertionAssignmentFields { l_angle_token, ty, r_angle_token, assignment, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - formatter.format_delimited_soft_block_indent( - &l_angle_token?, - ty.format(formatter)?, - &r_angle_token?, - )?, - assignment.format(formatter)? + [ + formatter.format_delimited_soft_block_indent( + &l_angle_token?, + formatted![formatter, [ty.format()]]?, + &r_angle_token?, + )?, + assignment.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/abstract_modifier.rs b/crates/rome_js_formatter/src/ts/auxiliary/abstract_modifier.rs index b39ca8ba4043..ecfff02691af 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/abstract_modifier.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/abstract_modifier.rs @@ -1,11 +1,15 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsAbstractModifier; use rome_js_syntax::TsAbstractModifierFields; -impl FormatNode for TsAbstractModifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsAbstractModifierFields { modifier_token } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsAbstractModifier, + formatter: &Formatter, + ) -> FormatResult { + let TsAbstractModifierFields { modifier_token } = node.as_fields(); - modifier_token.format(formatter) + formatted![formatter, [modifier_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/accessibility_modifier.rs b/crates/rome_js_formatter/src/ts/auxiliary/accessibility_modifier.rs index 3b7199666159..abfa0113e53f 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/accessibility_modifier.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/accessibility_modifier.rs @@ -1,10 +1,15 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsAccessibilityModifier; use rome_js_syntax::TsAccessibilityModifierFields; -impl FormatNode for TsAccessibilityModifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsAccessibilityModifierFields { modifier_token } = self.as_fields(); - modifier_token.format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsAccessibilityModifier, + formatter: &Formatter, + ) -> FormatResult { + let TsAccessibilityModifierFields { modifier_token } = node.as_fields(); + + formatted![formatter, [modifier_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/asserts_condition.rs b/crates/rome_js_formatter/src/ts/auxiliary/asserts_condition.rs index 972bd9f457d3..0f1c5c6e40a8 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/asserts_condition.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/asserts_condition.rs @@ -1,15 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsAssertsCondition; use rome_js_syntax::TsAssertsConditionFields; -impl FormatNode for TsAssertsCondition { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsAssertsConditionFields { is_token, ty } = self.as_fields(); - formatted![ - formatter, - is_token.format(formatter)?, - space_token(), - ty.format(formatter)? - ] +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsAssertsCondition, + formatter: &Formatter, + ) -> FormatResult { + let TsAssertsConditionFields { is_token, ty } = node.as_fields(); + formatted![formatter, [is_token.format(), space_token(), ty.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/call_signature_type_member.rs b/crates/rome_js_formatter/src/ts/auxiliary/call_signature_type_member.rs index c53cabc9098e..230eac49e0ab 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/call_signature_type_member.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/call_signature_type_member.rs @@ -1,20 +1,30 @@ use crate::prelude::*; use crate::utils::format_type_member_separator; -use rome_js_syntax::TsCallSignatureTypeMember; +use crate::FormatNodeFields; +use rome_js_syntax::{TsCallSignatureTypeMember, TsCallSignatureTypeMemberFields}; -impl FormatNode for TsCallSignatureTypeMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let type_parameters = self.type_parameters(); - let parameters = self.parameters().format(formatter)?; - let return_type_annotation = self.return_type_annotation(); - let separator = format_type_member_separator(self.separator_token(), formatter); - - formatted![ - formatter, +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsCallSignatureTypeMember, + formatter: &Formatter, + ) -> FormatResult { + let TsCallSignatureTypeMemberFields { type_parameters, parameters, return_type_annotation, - separator + separator_token, + } = node.as_fields(); + + let separator = format_type_member_separator(separator_token, formatter); + + formatted![ + formatter, + [ + type_parameters.format(), + parameters.format(), + return_type_annotation.format(), + separator + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/construct_signature_type_member.rs b/crates/rome_js_formatter/src/ts/auxiliary/construct_signature_type_member.rs index 838abd736b4f..6422e689da69 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/construct_signature_type_member.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/construct_signature_type_member.rs @@ -1,31 +1,35 @@ use crate::prelude::*; use crate::utils::format_type_member_separator; +use crate::FormatNodeFields; use rome_js_syntax::{TsConstructSignatureTypeMember, TsConstructSignatureTypeMemberFields}; -impl FormatNode for TsConstructSignatureTypeMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsConstructSignatureTypeMember, + formatter: &Formatter, + ) -> FormatResult { let TsConstructSignatureTypeMemberFields { new_token, type_parameters, parameters, type_annotation, separator_token, - } = self.as_fields(); + } = node.as_fields(); - let new = new_token.format(formatter)?; - let type_parameters = type_parameters; - let parameters = parameters.format(formatter)?; - let type_annotation = type_annotation; let separator_token = format_type_member_separator(separator_token, formatter); formatted![ formatter, - new, - space_token(), - type_parameters, - parameters, - type_annotation, - separator_token, + [ + new_token.format(), + space_token(), + type_parameters.format(), + parameters.format(), + type_annotation.format(), + separator_token, + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/declare_modifier.rs b/crates/rome_js_formatter/src/ts/auxiliary/declare_modifier.rs index 8a1fc1617cd1..4e81318b7941 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/declare_modifier.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/declare_modifier.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsDeclareModifier; use rome_js_syntax::TsDeclareModifierFields; -impl FormatNode for TsDeclareModifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsDeclareModifierFields { modifier_token } = self.as_fields(); - modifier_token.format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsDeclareModifier, + formatter: &Formatter, + ) -> FormatResult { + let TsDeclareModifierFields { modifier_token } = node.as_fields(); + formatted![formatter, [modifier_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/default_type_clause.rs b/crates/rome_js_formatter/src/ts/auxiliary/default_type_clause.rs index 43cb36ca583d..d9767b50e6d1 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/default_type_clause.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/default_type_clause.rs @@ -1,10 +1,13 @@ use crate::prelude::*; -use rome_js_syntax::TsDefaultTypeClause; +use crate::FormatNodeFields; +use rome_js_syntax::{TsDefaultTypeClause, TsDefaultTypeClauseFields}; -impl FormatNode for TsDefaultTypeClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let equals = self.eq_token().format(formatter)?; - let ty = self.ty().format(formatter)?; - formatted![formatter, equals, space_token(), ty] +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsDefaultTypeClause, + formatter: &Formatter, + ) -> FormatResult { + let TsDefaultTypeClauseFields { eq_token, ty } = node.as_fields(); + formatted![formatter, [eq_token.format(), space_token(), ty.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/definite_property_annotation.rs b/crates/rome_js_formatter/src/ts/auxiliary/definite_property_annotation.rs index dee715ebfbc6..76a892928707 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/definite_property_annotation.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/definite_property_annotation.rs @@ -1,17 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsDefinitePropertyAnnotation; use rome_js_syntax::TsDefinitePropertyAnnotationFields; -impl FormatNode for TsDefinitePropertyAnnotation { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsDefinitePropertyAnnotation, + formatter: &Formatter, + ) -> FormatResult { let TsDefinitePropertyAnnotationFields { excl_token, type_annotation, - } = self.as_fields(); - formatted![ - formatter, - excl_token.format(formatter)?, - type_annotation.format(formatter)? - ] + } = node.as_fields(); + formatted![formatter, [excl_token.format(), type_annotation.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/definite_variable_annotation.rs b/crates/rome_js_formatter/src/ts/auxiliary/definite_variable_annotation.rs index 1a67399cbe2f..7b44f3d11b50 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/definite_variable_annotation.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/definite_variable_annotation.rs @@ -1,18 +1,20 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsDefiniteVariableAnnotation; use rome_js_syntax::TsDefiniteVariableAnnotationFields; -impl FormatNode for TsDefiniteVariableAnnotation { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsDefiniteVariableAnnotation, + formatter: &Formatter, + ) -> FormatResult { let TsDefiniteVariableAnnotationFields { excl_token, type_annotation, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - excl_token.format(formatter)?, - type_annotation.format(formatter)?, - ] + formatted![formatter, [excl_token.format(), type_annotation.format(),]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/empty_external_module_declaration_body.rs b/crates/rome_js_formatter/src/ts/auxiliary/empty_external_module_declaration_body.rs index 8c51b021a670..607780216f28 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/empty_external_module_declaration_body.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/empty_external_module_declaration_body.rs @@ -1,10 +1,16 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsEmptyExternalModuleDeclarationBody; use rome_js_syntax::TsEmptyExternalModuleDeclarationBodyFields; -impl FormatNode for TsEmptyExternalModuleDeclarationBody { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsEmptyExternalModuleDeclarationBodyFields { semicolon_token } = self.as_fields(); - semicolon_token.format(formatter) +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsEmptyExternalModuleDeclarationBody, + formatter: &Formatter, + ) -> FormatResult { + let TsEmptyExternalModuleDeclarationBodyFields { semicolon_token } = node.as_fields(); + formatted![formatter, [semicolon_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/enum_member.rs b/crates/rome_js_formatter/src/ts/auxiliary/enum_member.rs index 47eee14f698e..86a9ec30ef65 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/enum_member.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/enum_member.rs @@ -1,12 +1,15 @@ use crate::prelude::*; use crate::utils::format_initializer_clause; -use rome_js_syntax::TsEnumMember; +use crate::FormatNodeFields; +use rome_js_syntax::{TsEnumMember, TsEnumMemberFields}; -impl FormatNode for TsEnumMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let name = self.name().format(formatter)?; - let initializer = format_initializer_clause(formatter, self.initializer())?; +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsEnumMember, formatter: &Formatter) -> FormatResult { + let TsEnumMemberFields { name, initializer } = node.as_fields(); - formatted![formatter, name, initializer] + let name = name.format(); + let initializer = format_initializer_clause(formatter, initializer)?; + + formatted![formatter, [name, initializer]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/external_module_reference.rs b/crates/rome_js_formatter/src/ts/auxiliary/external_module_reference.rs index 5b5943b34afb..7e5914bce575 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/external_module_reference.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/external_module_reference.rs @@ -1,22 +1,28 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsExternalModuleReference; use rome_js_syntax::TsExternalModuleReferenceFields; -impl FormatNode for TsExternalModuleReference { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsExternalModuleReference, + formatter: &Formatter, + ) -> FormatResult { let TsExternalModuleReferenceFields { require_token, l_paren_token, source, r_paren_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - require_token.format(formatter)?, - l_paren_token.format(formatter)?, - source.format(formatter)?, - r_paren_token.format(formatter)?, + [ + require_token.format(), + l_paren_token.format(), + source.format(), + r_paren_token.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/getter_signature_type_member.rs b/crates/rome_js_formatter/src/ts/auxiliary/getter_signature_type_member.rs index 082615b0ac66..4941b2f34327 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/getter_signature_type_member.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/getter_signature_type_member.rs @@ -1,25 +1,35 @@ use crate::prelude::*; use crate::utils::format_type_member_separator; -use rome_js_syntax::TsGetterSignatureTypeMember; +use crate::FormatNodeFields; +use rome_js_syntax::{TsGetterSignatureTypeMember, TsGetterSignatureTypeMemberFields}; -impl FormatNode for TsGetterSignatureTypeMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let get = self.get_token().format(formatter)?; - let name = self.name().format(formatter)?; - let l_paren = self.l_paren_token().format(formatter)?; - let r_paren = self.r_paren_token().format(formatter)?; - let type_annotation = self.type_annotation(); - let separator = format_type_member_separator(self.separator_token(), formatter); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsGetterSignatureTypeMember, + formatter: &Formatter, + ) -> FormatResult { + let TsGetterSignatureTypeMemberFields { + get_token, + name, + l_paren_token, + r_paren_token, + type_annotation, + separator_token, + } = node.as_fields(); + + let separator = format_type_member_separator(separator_token, formatter); formatted![ formatter, - get, - space_token(), - name, - l_paren, - r_paren, - type_annotation, - separator + [ + get_token.format(), + space_token(), + name.format(), + l_paren_token.format(), + r_paren_token.format(), + type_annotation.format(), + separator + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/implements_clause.rs b/crates/rome_js_formatter/src/ts/auxiliary/implements_clause.rs index 98cf97ad1d43..d05458bdf45f 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/implements_clause.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/implements_clause.rs @@ -1,31 +1,37 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsImplementsClause; use rome_js_syntax::TsImplementsClauseFields; -impl FormatNode for TsImplementsClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsImplementsClause, + formatter: &Formatter, + ) -> FormatResult { let TsImplementsClauseFields { implements_token, types, - } = self.as_fields(); + } = node.as_fields(); - let implements_token = implements_token.format(formatter)?; - let types = types.format(formatter)?; + let implements_token = implements_token.format().memoized(); + let types = types.format().memoized(); Ok(group_elements(formatted![ formatter, - if_group_breaks(block_indent(formatted![ - formatter, - implements_token.clone(), - space_token(), - soft_block_indent(types.clone()) - ]?)), - if_group_fits_on_single_line(formatted![ - formatter, - implements_token, - space_token(), - types - ]?), + [ + if_group_breaks(block_indent(formatted![ + formatter, + [ + &implements_token, + space_token(), + soft_block_indent(formatted![formatter, [&types]]?) + ] + ]?)), + if_group_fits_on_single_line(formatted![ + formatter, + [&implements_token, space_token(), &types] + ]?), + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/index_signature_type_member.rs b/crates/rome_js_formatter/src/ts/auxiliary/index_signature_type_member.rs index ca76cbb62d94..f148d3ea70df 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/index_signature_type_member.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/index_signature_type_member.rs @@ -1,9 +1,13 @@ use crate::prelude::*; use crate::utils::format_type_member_separator; +use crate::FormatNodeFields; use rome_js_syntax::{TsIndexSignatureTypeMember, TsIndexSignatureTypeMemberFields}; -impl FormatNode for TsIndexSignatureTypeMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsIndexSignatureTypeMember, + formatter: &Formatter, + ) -> FormatResult { let TsIndexSignatureTypeMemberFields { readonly_token, l_brack_token, @@ -11,26 +15,23 @@ impl FormatNode for TsIndexSignatureTypeMember { r_brack_token, type_annotation, separator_token, - } = self.as_fields(); - - let readonly = readonly_token - .with_or_empty(|readonly_token| formatted![formatter, readonly_token, space_token()]); - - let l_bracket = l_brack_token.format(formatter)?; - let parameter = parameter.format(formatter)?; - let r_bracket = r_brack_token.format(formatter)?; - - let type_annotation = type_annotation.format(formatter)?; - let separator = format_type_member_separator(separator_token, formatter); + } = node.as_fields(); formatted![ formatter, - readonly, - l_bracket, - parameter, - r_bracket, - type_annotation, - separator, + [ + readonly_token + .format() + .with_or_empty(|readonly_token| formatted![ + formatter, + [readonly_token, space_token()] + ]), + l_brack_token.format(), + parameter.format(), + r_brack_token.format(), + type_annotation.format(), + format_type_member_separator(separator_token, formatter), + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_as_clause.rs b/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_as_clause.rs index 42910d1a483d..c2f0010741bf 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_as_clause.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_as_clause.rs @@ -1,13 +1,22 @@ use crate::prelude::*; -use rome_js_syntax::TsMappedTypeAsClause; +use crate::FormatNodeFields; +use rome_js_syntax::{TsMappedTypeAsClause, TsMappedTypeAsClauseFields}; + +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsMappedTypeAsClause, + formatter: &Formatter, + ) -> FormatResult { + let TsMappedTypeAsClauseFields { as_token, ty } = node.as_fields(); -impl FormatNode for TsMappedTypeAsClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { formatted![ formatter, - self.as_token() - .with(|as_token| { formatted![formatter, as_token, space_token()] }), - self.ty().format(formatter)? + [ + as_token + .format() + .with(|as_token| { formatted![formatter, [as_token, space_token()]] }), + ty.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_optional_modifier_clause.rs b/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_optional_modifier_clause.rs index 72b090d8d920..dcdc65361554 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_optional_modifier_clause.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_optional_modifier_clause.rs @@ -1,18 +1,23 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsMappedTypeOptionalModifierClause; use rome_js_syntax::TsMappedTypeOptionalModifierClauseFields; -impl FormatNode for TsMappedTypeOptionalModifierClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsMappedTypeOptionalModifierClause, + formatter: &Formatter, + ) -> FormatResult { let TsMappedTypeOptionalModifierClauseFields { operator_token, question_mark_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - operator_token.format(formatter)?, - question_mark_token.format(formatter)? + [operator_token.format(), question_mark_token.format()] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_readonly_modifier_clause.rs b/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_readonly_modifier_clause.rs index d12cca1b08fc..e74cb7381981 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_readonly_modifier_clause.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/mapped_type_readonly_modifier_clause.rs @@ -1,17 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsMappedTypeReadonlyModifierClause; use rome_js_syntax::TsMappedTypeReadonlyModifierClauseFields; -impl FormatNode for TsMappedTypeReadonlyModifierClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsMappedTypeReadonlyModifierClause, + formatter: &Formatter, + ) -> FormatResult { let TsMappedTypeReadonlyModifierClauseFields { operator_token, readonly_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - operator_token.format(formatter)?, - readonly_token.format(formatter)? + [operator_token.format(), readonly_token.format()] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/method_signature_type_member.rs b/crates/rome_js_formatter/src/ts/auxiliary/method_signature_type_member.rs index 39e4811f0b02..5c4cfa12d91e 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/method_signature_type_member.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/method_signature_type_member.rs @@ -1,23 +1,33 @@ use crate::prelude::*; use crate::utils::format_type_member_separator; -use rome_js_syntax::TsMethodSignatureTypeMember; +use crate::FormatNodeFields; +use rome_js_syntax::{TsMethodSignatureTypeMember, TsMethodSignatureTypeMemberFields}; -impl FormatNode for TsMethodSignatureTypeMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let name = self.name().format(formatter)?; - let optional_token = self.optional_token(); - let type_arguments = self.type_parameters(); - let parameters = self.parameters().format(formatter)?; - let return_type_annotation = self.return_type_annotation(); - let separator = format_type_member_separator(self.separator_token(), formatter); - formatted![ - formatter, +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsMethodSignatureTypeMember, + formatter: &Formatter, + ) -> FormatResult { + let TsMethodSignatureTypeMemberFields { name, optional_token, - type_arguments, + type_parameters, parameters, return_type_annotation, - separator + separator_token, + } = node.as_fields(); + + let separator = format_type_member_separator(separator_token, formatter); + formatted![ + formatter, + [ + name.format(), + optional_token.format(), + type_parameters.format(), + parameters.format(), + return_type_annotation.format(), + separator + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/module_block.rs b/crates/rome_js_formatter/src/ts/auxiliary/module_block.rs index 17bc75a8aff4..74e13520a747 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/module_block.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/module_block.rs @@ -1,18 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsModuleBlock; use rome_js_syntax::TsModuleBlockFields; -impl FormatNode for TsModuleBlock { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsModuleBlock, formatter: &Formatter) -> FormatResult { let TsModuleBlockFields { l_curly_token, items, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_block_indent( &l_curly_token?, - items.format(formatter)?, + formatted![formatter, [items.format()]]?, &r_curly_token?, ) } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/named_tuple_type_element.rs b/crates/rome_js_formatter/src/ts/auxiliary/named_tuple_type_element.rs index 710d740e697f..23af5d02dfda 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/named_tuple_type_element.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/named_tuple_type_element.rs @@ -1,26 +1,29 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsNamedTupleTypeElement, TsNamedTupleTypeElementFields}; -impl FormatNode for TsNamedTupleTypeElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsNamedTupleTypeElement, + formatter: &Formatter, + ) -> FormatResult { let TsNamedTupleTypeElementFields { ty, question_mark_token, colon_token, name, dotdotdot_token, - } = self.as_fields(); - let name = name.format(formatter)?; - let colon = colon_token.format(formatter)?; - let ty = ty.format(formatter)?; + } = node.as_fields(); formatted![ formatter, - dotdotdot_token, - name, - question_mark_token, - colon, - space_token(), - ty, + [ + dotdotdot_token.format(), + name.format(), + question_mark_token.format(), + colon_token.format(), + space_token(), + ty.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/optional_property_annotation.rs b/crates/rome_js_formatter/src/ts/auxiliary/optional_property_annotation.rs index 0fc6678dbae2..68c4614b005e 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/optional_property_annotation.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/optional_property_annotation.rs @@ -1,18 +1,23 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsOptionalPropertyAnnotation; use rome_js_syntax::TsOptionalPropertyAnnotationFields; -impl FormatNode for TsOptionalPropertyAnnotation { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsOptionalPropertyAnnotation, + formatter: &Formatter, + ) -> FormatResult { let TsOptionalPropertyAnnotationFields { question_mark_token, type_annotation, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - question_mark_token.format(formatter)?, - type_annotation + [question_mark_token.format(), type_annotation.format()] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/optional_tuple_type_element.rs b/crates/rome_js_formatter/src/ts/auxiliary/optional_tuple_type_element.rs index 943944790514..7c965edb4b34 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/optional_tuple_type_element.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/optional_tuple_type_element.rs @@ -1,14 +1,18 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsOptionalTupleTypeElement, TsOptionalTupleTypeElementFields}; -impl FormatNode for TsOptionalTupleTypeElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsOptionalTupleTypeElement, + formatter: &Formatter, + ) -> FormatResult { let TsOptionalTupleTypeElementFields { ty, question_mark_token, - } = self.as_fields(); - let ty = ty.format(formatter)?; - let question_mark = question_mark_token.format(formatter)?; - formatted![formatter, ty, question_mark] + } = node.as_fields(); + let ty = ty.format(); + let question_mark = question_mark_token.format(); + formatted![formatter, [ty, question_mark]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/override_modifier.rs b/crates/rome_js_formatter/src/ts/auxiliary/override_modifier.rs index 2b38fdc1691d..7e1842bb290e 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/override_modifier.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/override_modifier.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsOverrideModifier; use rome_js_syntax::TsOverrideModifierFields; -impl FormatNode for TsOverrideModifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsOverrideModifierFields { modifier_token } = self.as_fields(); - modifier_token.format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsOverrideModifier, + formatter: &Formatter, + ) -> FormatResult { + let TsOverrideModifierFields { modifier_token } = node.as_fields(); + formatted![formatter, [modifier_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/property_signature_type_member.rs b/crates/rome_js_formatter/src/ts/auxiliary/property_signature_type_member.rs index df5761957000..93151058743c 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/property_signature_type_member.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/property_signature_type_member.rs @@ -1,20 +1,35 @@ use crate::prelude::*; use crate::utils::format_type_member_separator; -use rome_js_syntax::TsPropertySignatureTypeMember; +use crate::FormatNodeFields; +use rome_js_syntax::{TsPropertySignatureTypeMember, TsPropertySignatureTypeMemberFields}; -impl FormatNode for TsPropertySignatureTypeMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let name = self.name().format(formatter)?; - let separator = format_type_member_separator(self.separator_token(), formatter); +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsPropertySignatureTypeMember, + formatter: &Formatter, + ) -> FormatResult { + let TsPropertySignatureTypeMemberFields { + readonly_token, + name, + optional_token, + type_annotation, + separator_token, + } = node.as_fields(); + + let separator = format_type_member_separator(separator_token, formatter); formatted![ formatter, - self.readonly_token(), - space_token(), - name, - self.optional_token(), - self.type_annotation(), - separator + [ + readonly_token.format(), + space_token(), + name.format(), + optional_token.format(), + type_annotation.format(), + separator + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/qualified_module_name.rs b/crates/rome_js_formatter/src/ts/auxiliary/qualified_module_name.rs index 6a240aee2713..3c62fb0477fd 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/qualified_module_name.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/qualified_module_name.rs @@ -1,20 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsQualifiedModuleName; use rome_js_syntax::TsQualifiedModuleNameFields; -impl FormatNode for TsQualifiedModuleName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsQualifiedModuleName, + formatter: &Formatter, + ) -> FormatResult { let TsQualifiedModuleNameFields { left, dot_token, right, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - left.format(formatter)?, - dot_token.format(formatter)?, - right.format(formatter)?, + [left.format(), dot_token.format(), right.format(),] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/qualified_name.rs b/crates/rome_js_formatter/src/ts/auxiliary/qualified_name.rs index 8eeece3ebd36..b518e7cd811c 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/qualified_name.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/qualified_name.rs @@ -1,20 +1,19 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsQualifiedName; use rome_js_syntax::TsQualifiedNameFields; -impl FormatNode for TsQualifiedName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsQualifiedName, formatter: &Formatter) -> FormatResult { let TsQualifiedNameFields { left, dot_token, right, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - left.format(formatter)?, - dot_token.format(formatter)?, - right.format(formatter)?, + [left.format(), dot_token.format(), right.format(),] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/readonly_modifier.rs b/crates/rome_js_formatter/src/ts/auxiliary/readonly_modifier.rs index 6e3b4ec65ac4..98f6bdd7bbc8 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/readonly_modifier.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/readonly_modifier.rs @@ -1,10 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsReadonlyModifier; use rome_js_syntax::TsReadonlyModifierFields; -impl FormatNode for TsReadonlyModifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsReadonlyModifierFields { modifier_token } = self.as_fields(); - modifier_token.format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsReadonlyModifier, + formatter: &Formatter, + ) -> FormatResult { + let TsReadonlyModifierFields { modifier_token } = node.as_fields(); + formatted![formatter, [modifier_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/rest_tuple_type_element.rs b/crates/rome_js_formatter/src/ts/auxiliary/rest_tuple_type_element.rs index 79beb285ed80..448751ce2a5e 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/rest_tuple_type_element.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/rest_tuple_type_element.rs @@ -1,14 +1,18 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsRestTupleTypeElement, TsRestTupleTypeElementFields}; -impl FormatNode for TsRestTupleTypeElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsRestTupleTypeElement, + formatter: &Formatter, + ) -> FormatResult { let TsRestTupleTypeElementFields { dotdotdot_token, ty, - } = self.as_fields(); - let dotdotdot = dotdotdot_token.format(formatter)?; - let ty = ty.format(formatter)?; - formatted![formatter, dotdotdot, ty] + } = node.as_fields(); + let dotdotdot = dotdotdot_token.format(); + let ty = ty.format(); + formatted![formatter, [dotdotdot, ty]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/return_type_annotation.rs b/crates/rome_js_formatter/src/ts/auxiliary/return_type_annotation.rs index f73ffb6cd52f..f05c6e9fa4c9 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/return_type_annotation.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/return_type_annotation.rs @@ -1,15 +1,17 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsReturnTypeAnnotation; use rome_js_syntax::TsReturnTypeAnnotationFields; -impl FormatNode for TsReturnTypeAnnotation { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsReturnTypeAnnotationFields { colon_token, ty } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsReturnTypeAnnotation, + formatter: &Formatter, + ) -> FormatResult { + let TsReturnTypeAnnotationFields { colon_token, ty } = node.as_fields(); formatted![ formatter, - colon_token.format(formatter)?, - space_token(), - ty.format(formatter)? + [colon_token.format(), space_token(), ty.format()] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/setter_signature_type_member.rs b/crates/rome_js_formatter/src/ts/auxiliary/setter_signature_type_member.rs index c3fd07a8b939..2deac63b9405 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/setter_signature_type_member.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/setter_signature_type_member.rs @@ -1,25 +1,40 @@ use crate::prelude::*; use crate::utils::format_type_member_separator; -use rome_js_syntax::TsSetterSignatureTypeMember; +use crate::FormatNodeFields; +use rome_js_syntax::{TsSetterSignatureTypeMember, TsSetterSignatureTypeMemberFields}; -impl FormatNode for TsSetterSignatureTypeMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let set = self.set_token().format(formatter)?; - let name = self.name().format(formatter)?; - let l_paren = self.l_paren_token().format(formatter)?; - let parameter = self.parameter().format(formatter)?; - let r_paren = self.r_paren_token().format(formatter)?; - let separator = format_type_member_separator(self.separator_token(), formatter); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsSetterSignatureTypeMember, + formatter: &Formatter, + ) -> FormatResult { + let TsSetterSignatureTypeMemberFields { + set_token, + name, + l_paren_token, + parameter, + r_paren_token, + separator_token, + } = node.as_fields(); + + let set = set_token.format(); + let name = name.format(); + let l_paren = l_paren_token.format(); + let parameter = parameter.format(); + let r_paren = r_paren_token.format(); + let separator = format_type_member_separator(separator_token, formatter); formatted![ formatter, - set, - space_token(), - name, - l_paren, - parameter, - r_paren, - separator + [ + set, + space_token(), + name, + l_paren, + parameter, + r_paren, + separator + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/type_annotation.rs b/crates/rome_js_formatter/src/ts/auxiliary/type_annotation.rs index 02f13d0147c0..f8e440f286a4 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/type_annotation.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/type_annotation.rs @@ -1,11 +1,16 @@ use crate::prelude::*; -use rome_js_syntax::TsTypeAnnotation; +use crate::FormatNodeFields; +use rome_js_syntax::{TsTypeAnnotation, TsTypeAnnotationFields}; -impl FormatNode for TsTypeAnnotation { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let colon = self.colon_token().format(formatter)?; - let ty = self.ty().format(formatter)?; +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTypeAnnotation, + formatter: &Formatter, + ) -> FormatResult { + let TsTypeAnnotationFields { colon_token, ty } = node.as_fields(); + let colon = colon_token.format(); + let ty = ty.format(); - formatted![formatter, colon, space_token(), ty] + formatted![formatter, [colon, space_token(), ty]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/type_constraint_clause.rs b/crates/rome_js_formatter/src/ts/auxiliary/type_constraint_clause.rs index ef60ef94a462..235d188c826b 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/type_constraint_clause.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/type_constraint_clause.rs @@ -1,10 +1,16 @@ use crate::prelude::*; -use rome_js_syntax::TsTypeConstraintClause; +use crate::FormatNodeFields; +use rome_js_syntax::{TsTypeConstraintClause, TsTypeConstraintClauseFields}; -impl FormatNode for TsTypeConstraintClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let extends = self.extends_token().format(formatter)?; - let ty = self.ty().format(formatter)?; - formatted![formatter, extends, space_token(), ty] +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTypeConstraintClause, + formatter: &Formatter, + ) -> FormatResult { + let TsTypeConstraintClauseFields { extends_token, ty } = node.as_fields(); + + let extends = extends_token.format(); + let ty = ty.format(); + formatted![formatter, [extends, space_token(), ty]] } } diff --git a/crates/rome_js_formatter/src/ts/auxiliary/type_parameter_name.rs b/crates/rome_js_formatter/src/ts/auxiliary/type_parameter_name.rs index 1d305d78a227..564a40e0a3fa 100644 --- a/crates/rome_js_formatter/src/ts/auxiliary/type_parameter_name.rs +++ b/crates/rome_js_formatter/src/ts/auxiliary/type_parameter_name.rs @@ -1,8 +1,14 @@ use crate::prelude::*; -use rome_js_syntax::TsTypeParameterName; +use crate::FormatNodeFields; +use rome_js_syntax::{TsTypeParameterName, TsTypeParameterNameFields}; -impl FormatNode for TsTypeParameterName { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.ident_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTypeParameterName, + formatter: &Formatter, + ) -> FormatResult { + let TsTypeParameterNameFields { ident_token } = node.as_fields(); + + formatted![formatter, [ident_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/bindings/identifier_binding.rs b/crates/rome_js_formatter/src/ts/bindings/identifier_binding.rs index 470e586e8d51..30cac0a126d9 100644 --- a/crates/rome_js_formatter/src/ts/bindings/identifier_binding.rs +++ b/crates/rome_js_formatter/src/ts/bindings/identifier_binding.rs @@ -1,8 +1,14 @@ use crate::prelude::*; -use rome_js_syntax::TsIdentifierBinding; +use crate::FormatNodeFields; +use rome_js_syntax::{TsIdentifierBinding, TsIdentifierBindingFields}; -impl FormatNode for TsIdentifierBinding { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.name_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsIdentifierBinding, + formatter: &Formatter, + ) -> FormatResult { + let TsIdentifierBindingFields { name_token } = node.as_fields(); + + formatted![formatter, [name_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/bindings/index_signature_parameter.rs b/crates/rome_js_formatter/src/ts/bindings/index_signature_parameter.rs index f6f16ab92c28..6dca2141d979 100644 --- a/crates/rome_js_formatter/src/ts/bindings/index_signature_parameter.rs +++ b/crates/rome_js_formatter/src/ts/bindings/index_signature_parameter.rs @@ -1,11 +1,19 @@ use crate::prelude::*; -use rome_js_syntax::TsIndexSignatureParameter; +use crate::FormatNodeFields; +use rome_js_syntax::{TsIndexSignatureParameter, TsIndexSignatureParameterFields}; -impl FormatNode for TsIndexSignatureParameter { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let binding = self.binding().format(formatter)?; - let type_annotation = self.type_annotation().format(formatter)?; +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsIndexSignatureParameter, + formatter: &Formatter, + ) -> FormatResult { + let TsIndexSignatureParameterFields { + binding, + type_annotation, + } = node.as_fields(); + let binding = binding.format(); + let type_annotation = type_annotation.format(); - formatted![formatter, binding, type_annotation] + formatted![formatter, [binding, type_annotation]] } } diff --git a/crates/rome_js_formatter/src/ts/bindings/property_parameter.rs b/crates/rome_js_formatter/src/ts/bindings/property_parameter.rs index dfc7f2986615..945df4005ead 100644 --- a/crates/rome_js_formatter/src/ts/bindings/property_parameter.rs +++ b/crates/rome_js_formatter/src/ts/bindings/property_parameter.rs @@ -1,18 +1,20 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsPropertyParameter, TsPropertyParameterFields}; -impl FormatNode for TsPropertyParameter { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsPropertyParameter, + formatter: &Formatter, + ) -> FormatResult { let TsPropertyParameterFields { modifiers, formal_parameter, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - formal_parameter.format(formatter)? + [modifiers.format(), space_token(), formal_parameter.format()] ] } } diff --git a/crates/rome_js_formatter/src/ts/bindings/this_parameter.rs b/crates/rome_js_formatter/src/ts/bindings/this_parameter.rs index ae05375727d6..ffc56731d32b 100644 --- a/crates/rome_js_formatter/src/ts/bindings/this_parameter.rs +++ b/crates/rome_js_formatter/src/ts/bindings/this_parameter.rs @@ -1,9 +1,14 @@ use crate::prelude::*; -use rome_js_syntax::TsThisParameter; +use crate::FormatNodeFields; +use rome_js_syntax::{TsThisParameter, TsThisParameterFields}; -impl FormatNode for TsThisParameter { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let this = self.this_token().format(formatter)?; - formatted![formatter, this, self.type_annotation()] +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsThisParameter, formatter: &Formatter) -> FormatResult { + let TsThisParameterFields { + this_token, + type_annotation, + } = node.as_fields(); + + formatted![formatter, [this_token.format(), type_annotation.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/bindings/type_parameter.rs b/crates/rome_js_formatter/src/ts/bindings/type_parameter.rs index 1e6ac346908c..cd4eaf552a8e 100644 --- a/crates/rome_js_formatter/src/ts/bindings/type_parameter.rs +++ b/crates/rome_js_formatter/src/ts/bindings/type_parameter.rs @@ -1,19 +1,26 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsTypeParameter, TsTypeParameterFields}; -impl FormatNode for TsTypeParameter { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsTypeParameter, formatter: &Formatter) -> FormatResult { let TsTypeParameterFields { name, constraint, default, - } = self.as_fields(); + } = node.as_fields(); - let name = name.format(formatter)?; - let constraint = - constraint.with_or_empty(|constraint| formatted![formatter, space_token(), constraint]); - let default = - default.with_or_empty(|default| formatted![formatter, space_token(), default]); - formatted![formatter, name, constraint, default] + formatted![ + formatter, + [ + name.format(), + constraint + .format() + .with_or_empty(|constraint| formatted![formatter, [space_token(), constraint]]), + default + .format() + .with_or_empty(|default| formatted![formatter, [space_token(), default]]) + ] + ] } } diff --git a/crates/rome_js_formatter/src/ts/bindings/type_parameters.rs b/crates/rome_js_formatter/src/ts/bindings/type_parameters.rs index 98db58e01f40..07d35aa4755c 100644 --- a/crates/rome_js_formatter/src/ts/bindings/type_parameters.rs +++ b/crates/rome_js_formatter/src/ts/bindings/type_parameters.rs @@ -1,15 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsTypeParameters, TsTypeParametersFields}; -impl FormatNode for TsTypeParameters { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTypeParameters, + formatter: &Formatter, + ) -> FormatResult { let TsTypeParametersFields { items, r_angle_token, l_angle_token, - } = self.as_fields(); - let items = items.format(formatter)?; + } = node.as_fields(); - formatter.format_delimited_soft_block_indent(&l_angle_token?, items, &r_angle_token?) + formatter.format_delimited_soft_block_indent( + &l_angle_token?, + formatted![formatter, [items.format()]]?, + &r_angle_token?, + ) } } diff --git a/crates/rome_js_formatter/src/ts/classes/constructor_signature_class_member.rs b/crates/rome_js_formatter/src/ts/classes/constructor_signature_class_member.rs index e83f6d54c6aa..e031a09c60ea 100644 --- a/crates/rome_js_formatter/src/ts/classes/constructor_signature_class_member.rs +++ b/crates/rome_js_formatter/src/ts/classes/constructor_signature_class_member.rs @@ -1,25 +1,33 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::TsConstructorSignatureClassMember; use rome_js_syntax::TsConstructorSignatureClassMemberFields; -impl FormatNode for TsConstructorSignatureClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsConstructorSignatureClassMember, + formatter: &Formatter, + ) -> FormatResult { let TsConstructorSignatureClassMemberFields { modifiers, name, parameters, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); Ok(hard_group_elements(format_with_semicolon( formatter, formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - name.format(formatter)?, - parameters.format(formatter)?, + [ + modifiers.format(), + space_token(), + name.format(), + parameters.format(), + ] ]?, semicolon_token, )?)) diff --git a/crates/rome_js_formatter/src/ts/classes/extends_clause.rs b/crates/rome_js_formatter/src/ts/classes/extends_clause.rs index 787e97cddad2..63b3f4f4598a 100644 --- a/crates/rome_js_formatter/src/ts/classes/extends_clause.rs +++ b/crates/rome_js_formatter/src/ts/classes/extends_clause.rs @@ -1,24 +1,33 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsExtendsClause, TsExtendsClauseFields}; -impl FormatNode for TsExtendsClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsExtendsClause, formatter: &Formatter) -> FormatResult { let TsExtendsClauseFields { extends_token, types, - } = self.as_fields(); - let extends = extends_token.format(formatter)?; - let types = types.format(formatter)?; + } = node.as_fields(); + + let extends_token = extends_token.format().memoized(); + let types = types.format().memoized(); Ok(group_elements(formatted![ formatter, - if_group_breaks(block_indent(formatted![ - formatter, - extends.clone(), - space_token(), - soft_block_indent(types.clone()) - ]?)), - if_group_fits_on_single_line(formatted![formatter, extends, space_token(), types]?), + [ + if_group_breaks(block_indent(formatted![ + formatter, + [ + &extends_token, + space_token(), + soft_block_indent(formatted![formatter, [&types]]?) + ] + ]?)), + if_group_fits_on_single_line(formatted![ + formatter, + [&extends_token, space_token(), &types] + ]?), + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/ts/classes/getter_signature_class_member.rs b/crates/rome_js_formatter/src/ts/classes/getter_signature_class_member.rs index 52317eb26ca5..cc0ea18ee438 100644 --- a/crates/rome_js_formatter/src/ts/classes/getter_signature_class_member.rs +++ b/crates/rome_js_formatter/src/ts/classes/getter_signature_class_member.rs @@ -1,9 +1,15 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::{TsGetterSignatureClassMember, TsGetterSignatureClassMemberFields}; -impl FormatNode for TsGetterSignatureClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsGetterSignatureClassMember, + formatter: &Formatter, + ) -> FormatResult { let TsGetterSignatureClassMemberFields { modifiers, get_token, @@ -12,25 +18,22 @@ impl FormatNode for TsGetterSignatureClassMember { r_paren_token, return_type, semicolon_token, - } = self.as_fields(); - - let get_token = get_token.format(formatter)?; - let name = name.format(formatter)?; - let l_paren_token = l_paren_token.format(formatter)?; - let r_paren_token = r_paren_token.format(formatter)?; + } = node.as_fields(); Ok(hard_group_elements(format_with_semicolon( formatter, formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - get_token, - space_token(), - name, - l_paren_token, - r_paren_token, - return_type, + [ + modifiers.format(), + space_token(), + get_token.format(), + space_token(), + name.format(), + l_paren_token.format(), + r_paren_token.format(), + return_type.format(), + ] ]?, semicolon_token, )?)) diff --git a/crates/rome_js_formatter/src/ts/classes/index_signature_class_member.rs b/crates/rome_js_formatter/src/ts/classes/index_signature_class_member.rs index ab9fdaa53651..f57caa07cba5 100644 --- a/crates/rome_js_formatter/src/ts/classes/index_signature_class_member.rs +++ b/crates/rome_js_formatter/src/ts/classes/index_signature_class_member.rs @@ -1,10 +1,14 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::TsIndexSignatureClassMember; use rome_js_syntax::TsIndexSignatureClassMemberFields; -impl FormatNode for TsIndexSignatureClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsIndexSignatureClassMember, + formatter: &Formatter, + ) -> FormatResult { let TsIndexSignatureClassMemberFields { modifiers, l_brack_token, @@ -12,18 +16,20 @@ impl FormatNode for TsIndexSignatureClassMember { r_brack_token, type_annotation, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); format_with_semicolon( formatter, formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - l_brack_token.format(formatter)?, - parameter.format(formatter)?, - r_brack_token.format(formatter)?, - type_annotation.format(formatter)?, + [ + modifiers.format(), + space_token(), + l_brack_token.format(), + parameter.format(), + r_brack_token.format(), + type_annotation.format(), + ] ]?, semicolon_token, ) diff --git a/crates/rome_js_formatter/src/ts/classes/method_signature_class_member.rs b/crates/rome_js_formatter/src/ts/classes/method_signature_class_member.rs index 0bc864907120..c51c5674ad60 100644 --- a/crates/rome_js_formatter/src/ts/classes/method_signature_class_member.rs +++ b/crates/rome_js_formatter/src/ts/classes/method_signature_class_member.rs @@ -1,9 +1,15 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::{TsMethodSignatureClassMember, TsMethodSignatureClassMemberFields}; -impl FormatNode for TsMethodSignatureClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsMethodSignatureClassMember, + formatter: &Formatter, + ) -> FormatResult { let TsMethodSignatureClassMemberFields { modifiers, async_token, @@ -13,25 +19,24 @@ impl FormatNode for TsMethodSignatureClassMember { parameters, return_type_annotation, semicolon_token, - } = self.as_fields(); - - let async_token = - async_token.with_or_empty(|token| formatted![formatter, token, space_token()]); - let name = name.format(formatter)?; - let parameters = parameters.format(formatter)?; + } = node.as_fields(); Ok(hard_group_elements(format_with_semicolon( formatter, formatted![ formatter, - modifiers.format(formatter)?, - async_token, - space_token(), - name, - question_mark_token, - type_parameters, - parameters, - return_type_annotation, + [ + modifiers.format(), + async_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + space_token(), + name.format(), + question_mark_token.format(), + type_parameters.format(), + parameters.format(), + return_type_annotation.format(), + ] ]?, semicolon_token, )?)) diff --git a/crates/rome_js_formatter/src/ts/classes/property_signature_class_member.rs b/crates/rome_js_formatter/src/ts/classes/property_signature_class_member.rs index e3fb5db7c58e..33c94ef7514f 100644 --- a/crates/rome_js_formatter/src/ts/classes/property_signature_class_member.rs +++ b/crates/rome_js_formatter/src/ts/classes/property_signature_class_member.rs @@ -1,24 +1,32 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::{TsPropertySignatureClassMember, TsPropertySignatureClassMemberFields}; -impl FormatNode for TsPropertySignatureClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsPropertySignatureClassMember, + formatter: &Formatter, + ) -> FormatResult { let TsPropertySignatureClassMemberFields { modifiers, name, property_annotation, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); format_with_semicolon( formatter, formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - name.format(formatter)?, - property_annotation, + [ + modifiers.format(), + space_token(), + name.format(), + property_annotation.format(), + ] ]?, semicolon_token, ) diff --git a/crates/rome_js_formatter/src/ts/classes/setter_signature_class_member.rs b/crates/rome_js_formatter/src/ts/classes/setter_signature_class_member.rs index 095fbb751d91..ce4ed38a2e83 100644 --- a/crates/rome_js_formatter/src/ts/classes/setter_signature_class_member.rs +++ b/crates/rome_js_formatter/src/ts/classes/setter_signature_class_member.rs @@ -1,9 +1,15 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::{TsSetterSignatureClassMember, TsSetterSignatureClassMemberFields}; -impl FormatNode for TsSetterSignatureClassMember { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsSetterSignatureClassMember, + formatter: &Formatter, + ) -> FormatResult { let TsSetterSignatureClassMemberFields { modifiers, set_token, @@ -12,26 +18,28 @@ impl FormatNode for TsSetterSignatureClassMember { parameter, r_paren_token, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); - let set_token = set_token.format(formatter)?; - let name = name.format(formatter)?; - let l_paren_token = l_paren_token.format(formatter)?; - let parameters = parameter.format(formatter)?; - let r_paren_token = r_paren_token.format(formatter)?; + let set_token = set_token.format(); + let name = name.format(); + let l_paren_token = l_paren_token.format(); + let parameters = parameter.format(); + let r_paren_token = r_paren_token.format(); Ok(hard_group_elements(format_with_semicolon( formatter, formatted![ formatter, - modifiers.format(formatter)?, - space_token(), - set_token, - space_token(), - name, - l_paren_token, - parameters, - r_paren_token, + [ + modifiers.format(), + space_token(), + set_token, + space_token(), + name, + l_paren_token, + parameters, + r_paren_token, + ] ]?, semicolon_token, )?)) diff --git a/crates/rome_js_formatter/src/ts/declarations/declare_function_declaration.rs b/crates/rome_js_formatter/src/ts/declarations/declare_function_declaration.rs index d1600ab3c349..bcbcaa2ad1b1 100644 --- a/crates/rome_js_formatter/src/ts/declarations/declare_function_declaration.rs +++ b/crates/rome_js_formatter/src/ts/declarations/declare_function_declaration.rs @@ -1,11 +1,16 @@ -use crate::format_extensions::FormatOptional; use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::TsDeclareFunctionDeclaration; use rome_js_syntax::TsDeclareFunctionDeclarationFields; -impl FormatNode for TsDeclareFunctionDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsDeclareFunctionDeclaration, + formatter: &Formatter, + ) -> FormatResult { let TsDeclareFunctionDeclarationFields { async_token, function_token, @@ -14,26 +19,24 @@ impl FormatNode for TsDeclareFunctionDeclaration { parameters, return_type_annotation, semicolon_token, - } = self.as_fields(); - - let async_token = async_token - .with_or_empty(|async_token| formatted![formatter, async_token, space_token()]); - - let function_token = function_token.format(formatter)?; - let id = id.format(formatter)?; - let parameters = parameters.format(formatter)?; + } = node.as_fields(); Ok(hard_group_elements(format_with_semicolon( formatter, formatted![ formatter, - async_token, - function_token, - space_token(), - id, - type_parameters, - parameters, - return_type_annotation, + [ + async_token.format().with_or_empty(|async_token| formatted![ + formatter, + [async_token, space_token()] + ]), + function_token.format(), + space_token(), + id.format(), + type_parameters.format(), + parameters.format(), + return_type_annotation.format(), + ] ]?, semicolon_token, )?)) diff --git a/crates/rome_js_formatter/src/ts/declarations/enum_declaration.rs b/crates/rome_js_formatter/src/ts/declarations/enum_declaration.rs index 8bdeb91b87a3..c38b7f9d1cd8 100644 --- a/crates/rome_js_formatter/src/ts/declarations/enum_declaration.rs +++ b/crates/rome_js_formatter/src/ts/declarations/enum_declaration.rs @@ -1,9 +1,13 @@ use crate::formatter::TrailingSeparator; use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsEnumDeclaration, TsEnumDeclarationFields}; -impl FormatNode for TsEnumDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsEnumDeclaration, + formatter: &Formatter, + ) -> FormatResult { let TsEnumDeclarationFields { const_token, enum_token, @@ -11,22 +15,35 @@ impl FormatNode for TsEnumDeclaration { members, l_curly_token, r_curly_token, - } = self.as_fields(); + } = node.as_fields(); - let const_token = const_token - .with_or_empty(|const_token| formatted![formatter, const_token, space_token()]); - let enum_token = - enum_token.with(|enum_token| formatted![formatter, enum_token, space_token()]); - let id = id.with(|id| formatted![formatter, id, space_token()]); - - let members = - formatter.format_separated(&members, || token(","), TrailingSeparator::default())?; let list = formatter.format_delimited_soft_block_spaces( &l_curly_token?, - join_elements(soft_line_break_or_space(), members), + join_elements( + soft_line_break_or_space(), + formatter.format_separated( + &members, + || token(","), + TrailingSeparator::default(), + )?, + ), &r_curly_token?, )?; - formatted![formatter, const_token, enum_token, id, list] + formatted![ + formatter, + [ + const_token.format().with_or_empty(|const_token| formatted![ + formatter, + [const_token, space_token()] + ]), + enum_token + .format() + .with(|enum_token| formatted![formatter, [enum_token, space_token()]]), + id.format() + .with(|id| formatted![formatter, [id, space_token()]]), + list + ] + ] } } diff --git a/crates/rome_js_formatter/src/ts/declarations/external_module_declaration.rs b/crates/rome_js_formatter/src/ts/declarations/external_module_declaration.rs index a7254ce77d03..a4d2e8432be1 100644 --- a/crates/rome_js_formatter/src/ts/declarations/external_module_declaration.rs +++ b/crates/rome_js_formatter/src/ts/declarations/external_module_declaration.rs @@ -1,25 +1,28 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsExternalModuleDeclaration; use rome_js_syntax::TsExternalModuleDeclarationFields; -impl FormatNode for TsExternalModuleDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsExternalModuleDeclaration, + formatter: &Formatter, + ) -> FormatResult { let TsExternalModuleDeclarationFields { body, module_token, source, - } = self.as_fields(); - - let module_token = module_token.format(formatter)?; - let source = source.format(formatter)?; + } = node.as_fields(); formatted![ formatter, - module_token, - space_token(), - source, - space_token(), - body + [ + module_token.format(), + space_token(), + source.format(), + space_token(), + body.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/declarations/global_declaration.rs b/crates/rome_js_formatter/src/ts/declarations/global_declaration.rs index 85ba88a62bd2..30d97230ffcd 100644 --- a/crates/rome_js_formatter/src/ts/declarations/global_declaration.rs +++ b/crates/rome_js_formatter/src/ts/declarations/global_declaration.rs @@ -1,16 +1,18 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsGlobalDeclaration; use rome_js_syntax::TsGlobalDeclarationFields; -impl FormatNode for TsGlobalDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsGlobalDeclarationFields { global_token, body } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsGlobalDeclaration, + formatter: &Formatter, + ) -> FormatResult { + let TsGlobalDeclarationFields { global_token, body } = node.as_fields(); formatted![ formatter, - global_token.format(formatter)?, - space_token(), - body.format(formatter)? + [global_token.format(), space_token(), body.format()] ] } } diff --git a/crates/rome_js_formatter/src/ts/declarations/import_equals_declaration.rs b/crates/rome_js_formatter/src/ts/declarations/import_equals_declaration.rs index 6abd5622a0e3..21a06362c3ee 100644 --- a/crates/rome_js_formatter/src/ts/declarations/import_equals_declaration.rs +++ b/crates/rome_js_formatter/src/ts/declarations/import_equals_declaration.rs @@ -1,10 +1,14 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::TsImportEqualsDeclaration; use rome_js_syntax::TsImportEqualsDeclarationFields; -impl FormatNode for TsImportEqualsDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsImportEqualsDeclaration, + formatter: &Formatter, + ) -> FormatResult { let TsImportEqualsDeclarationFields { import_token, type_token, @@ -12,20 +16,24 @@ impl FormatNode for TsImportEqualsDeclaration { eq_token, module_reference, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); format_with_semicolon( formatter, formatted![ formatter, - import_token.format(formatter)?, - space_token(), - type_token.with_or_empty(|token| formatted![formatter, token, space_token(),]), - id.format(formatter)?, - space_token(), - eq_token.format(formatter)?, - space_token(), - module_reference.format(formatter)?, + [ + import_token.format(), + space_token(), + type_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token(),]]), + id.format(), + space_token(), + eq_token.format(), + space_token(), + module_reference.format(), + ] ]?, semicolon_token, ) diff --git a/crates/rome_js_formatter/src/ts/declarations/interface_declaration.rs b/crates/rome_js_formatter/src/ts/declarations/interface_declaration.rs index e0ba8f77a8b6..4c6f9b7ea7d2 100644 --- a/crates/rome_js_formatter/src/ts/declarations/interface_declaration.rs +++ b/crates/rome_js_formatter/src/ts/declarations/interface_declaration.rs @@ -1,8 +1,12 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsInterfaceDeclaration, TsInterfaceDeclarationFields}; -impl FormatNode for TsInterfaceDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsInterfaceDeclaration, + formatter: &Formatter, + ) -> FormatResult { let TsInterfaceDeclarationFields { interface_token, id, @@ -11,25 +15,25 @@ impl FormatNode for TsInterfaceDeclaration { members, l_curly_token, r_curly_token, - } = self.as_fields(); - let interface = interface_token.format(formatter)?; - let id = id.format(formatter)?; - let extends = - extends_clause.with_or_empty(|extends| formatted![formatter, extends, space_token()]); + } = node.as_fields(); let members = formatter.format_delimited_block_indent( &l_curly_token?, - members.format(formatter)?, + formatted![formatter, [members.format()]]?, &r_curly_token?, )?; Ok(hard_group_elements(formatted![ formatter, - interface, - space_token(), - id, - type_parameters, - space_token(), - extends, - members + [ + interface_token.format(), + space_token(), + id.format(), + type_parameters.format(), + space_token(), + extends_clause + .format() + .with_or_empty(|extends| formatted![formatter, [extends, space_token()]]), + members + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/ts/declarations/module_declaration.rs b/crates/rome_js_formatter/src/ts/declarations/module_declaration.rs index 4694659f537f..6421f04ddaf3 100644 --- a/crates/rome_js_formatter/src/ts/declarations/module_declaration.rs +++ b/crates/rome_js_formatter/src/ts/declarations/module_declaration.rs @@ -1,22 +1,28 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsModuleDeclaration; use rome_js_syntax::TsModuleDeclarationFields; -impl FormatNode for TsModuleDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsModuleDeclaration, + formatter: &Formatter, + ) -> FormatResult { let TsModuleDeclarationFields { module_or_namespace, name, body, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - module_or_namespace.format(formatter)?, - space_token(), - name.format(formatter)?, - space_token(), - body.format(formatter)?, + [ + module_or_namespace.format(), + space_token(), + name.format(), + space_token(), + body.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/declarations/type_alias_declaration.rs b/crates/rome_js_formatter/src/ts/declarations/type_alias_declaration.rs index d07086d0c3b1..7a19e8e49e5c 100644 --- a/crates/rome_js_formatter/src/ts/declarations/type_alias_declaration.rs +++ b/crates/rome_js_formatter/src/ts/declarations/type_alias_declaration.rs @@ -1,9 +1,13 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::{TsTypeAliasDeclaration, TsTypeAliasDeclarationFields}; -impl FormatNode for TsTypeAliasDeclaration { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTypeAliasDeclaration, + formatter: &Formatter, + ) -> FormatResult { let TsTypeAliasDeclarationFields { type_token, binding_identifier, @@ -11,25 +15,22 @@ impl FormatNode for TsTypeAliasDeclaration { eq_token, ty, semicolon_token, - } = self.as_fields(); - - let type_token = type_token.format(formatter)?; - let binding_identifier = binding_identifier.format(formatter)?; - let equal_token = eq_token.format(formatter)?; - let ty = ty.format(formatter)?; + } = node.as_fields(); Ok(hard_group_elements(format_with_semicolon( formatter, formatted![ formatter, - type_token, - space_token(), - binding_identifier, - type_parameters, - space_token(), - equal_token, - space_token(), - ty, + [ + type_token.format(), + space_token(), + binding_identifier.format(), + type_parameters.format(), + space_token(), + eq_token.format(), + space_token(), + ty.format(), + ] ]?, semicolon_token, )?)) diff --git a/crates/rome_js_formatter/src/ts/expressions/as_expression.rs b/crates/rome_js_formatter/src/ts/expressions/as_expression.rs index f5682bfe0e5a..c7628b48cafd 100644 --- a/crates/rome_js_formatter/src/ts/expressions/as_expression.rs +++ b/crates/rome_js_formatter/src/ts/expressions/as_expression.rs @@ -1,22 +1,25 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsAsExpression; use rome_js_syntax::TsAsExpressionFields; -impl FormatNode for TsAsExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsAsExpression, formatter: &Formatter) -> FormatResult { let TsAsExpressionFields { ty, as_token, expression, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - expression.format(formatter)?, - space_token(), - as_token.format(formatter)?, - space_token(), - ty.format(formatter)?, + [ + expression.format(), + space_token(), + as_token.format(), + space_token(), + ty.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/expressions/name_with_type_arguments.rs b/crates/rome_js_formatter/src/ts/expressions/name_with_type_arguments.rs index e84699506db8..80a5344f1191 100644 --- a/crates/rome_js_formatter/src/ts/expressions/name_with_type_arguments.rs +++ b/crates/rome_js_formatter/src/ts/expressions/name_with_type_arguments.rs @@ -1,14 +1,17 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsNameWithTypeArguments, TsNameWithTypeArgumentsFields}; -impl FormatNode for TsNameWithTypeArguments { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsNameWithTypeArguments, + formatter: &Formatter, + ) -> FormatResult { let TsNameWithTypeArgumentsFields { name, type_arguments, - } = self.as_fields(); + } = node.as_fields(); - let name = name.format(formatter)?; - formatted![formatter, name, type_arguments] + formatted![formatter, [name.format(), type_arguments.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/expressions/non_null_assertion_expression.rs b/crates/rome_js_formatter/src/ts/expressions/non_null_assertion_expression.rs index 6ebb2b252e87..b82496d1aa68 100644 --- a/crates/rome_js_formatter/src/ts/expressions/non_null_assertion_expression.rs +++ b/crates/rome_js_formatter/src/ts/expressions/non_null_assertion_expression.rs @@ -1,18 +1,20 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsNonNullAssertionExpression; use rome_js_syntax::TsNonNullAssertionExpressionFields; -impl FormatNode for TsNonNullAssertionExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields + for FormatNodeRule +{ + fn format_fields( + node: &TsNonNullAssertionExpression, + formatter: &Formatter, + ) -> FormatResult { let TsNonNullAssertionExpressionFields { expression, excl_token, - } = self.as_fields(); + } = node.as_fields(); - formatted![ - formatter, - expression.format(formatter)?, - excl_token.format(formatter)? - ] + formatted![formatter, [expression.format(), excl_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/expressions/template_chunk_element.rs b/crates/rome_js_formatter/src/ts/expressions/template_chunk_element.rs index 363de20f6d6e..ecdadecbe885 100644 --- a/crates/rome_js_formatter/src/ts/expressions/template_chunk_element.rs +++ b/crates/rome_js_formatter/src/ts/expressions/template_chunk_element.rs @@ -1,12 +1,16 @@ use crate::prelude::*; use crate::utils::format_template_chunk; +use crate::FormatNodeFields; use rome_js_syntax::{TsTemplateChunkElement, TsTemplateChunkElementFields}; -impl FormatNode for TsTemplateChunkElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTemplateChunkElement, + formatter: &Formatter, + ) -> FormatResult { let TsTemplateChunkElementFields { template_chunk_token, - } = self.as_fields(); + } = node.as_fields(); let chunk = template_chunk_token?; format_template_chunk(chunk, formatter) diff --git a/crates/rome_js_formatter/src/ts/expressions/template_element.rs b/crates/rome_js_formatter/src/ts/expressions/template_element.rs index 2f87a691c847..dd986113f9c2 100644 --- a/crates/rome_js_formatter/src/ts/expressions/template_element.rs +++ b/crates/rome_js_formatter/src/ts/expressions/template_element.rs @@ -1,9 +1,13 @@ use crate::prelude::*; use crate::utils::{format_template_literal, TemplateElement}; +use crate::FormatNodeFields; use rome_js_syntax::TsTemplateElement; -impl FormatNode for TsTemplateElement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - format_template_literal(TemplateElement::Ts(self.clone()), formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTemplateElement, + formatter: &Formatter, + ) -> FormatResult { + format_template_literal(TemplateElement::Ts(node.clone()), formatter) } } diff --git a/crates/rome_js_formatter/src/ts/expressions/template_literal_type.rs b/crates/rome_js_formatter/src/ts/expressions/template_literal_type.rs index e4f2a1360fbc..40e36c8cffa7 100644 --- a/crates/rome_js_formatter/src/ts/expressions/template_literal_type.rs +++ b/crates/rome_js_formatter/src/ts/expressions/template_literal_type.rs @@ -1,20 +1,26 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsTemplateLiteralType; use rome_js_syntax::TsTemplateLiteralTypeFields; -impl FormatNode for TsTemplateLiteralType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTemplateLiteralType, + formatter: &Formatter, + ) -> FormatResult { let TsTemplateLiteralTypeFields { l_tick_token, elements, r_tick_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - l_tick_token.format(formatter)?, - elements.format(formatter)?, - r_tick_token.format(formatter)?, + [ + l_tick_token.format(), + elements.format(), + r_tick_token.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/expressions/type_arguments.rs b/crates/rome_js_formatter/src/ts/expressions/type_arguments.rs index 15d838f5425e..cbe83b704479 100644 --- a/crates/rome_js_formatter/src/ts/expressions/type_arguments.rs +++ b/crates/rome_js_formatter/src/ts/expressions/type_arguments.rs @@ -1,17 +1,18 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsTypeArguments, TsTypeArgumentsFields}; -impl FormatNode for TsTypeArguments { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsTypeArguments, formatter: &Formatter) -> FormatResult { let TsTypeArgumentsFields { l_angle_token, ts_type_argument_list, r_angle_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_indent( &l_angle_token?, - ts_type_argument_list.format(formatter)?, + formatted![formatter, [ts_type_argument_list.format()]]?, &r_angle_token?, ) } diff --git a/crates/rome_js_formatter/src/ts/expressions/type_assertion_expression.rs b/crates/rome_js_formatter/src/ts/expressions/type_assertion_expression.rs index 6fd0a6053221..4ded27e528bd 100644 --- a/crates/rome_js_formatter/src/ts/expressions/type_assertion_expression.rs +++ b/crates/rome_js_formatter/src/ts/expressions/type_assertion_expression.rs @@ -1,24 +1,30 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsTypeAssertionExpression; use rome_js_syntax::TsTypeAssertionExpressionFields; -impl FormatNode for TsTypeAssertionExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTypeAssertionExpression, + formatter: &Formatter, + ) -> FormatResult { let TsTypeAssertionExpressionFields { l_angle_token, ty, r_angle_token, expression, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - formatter.format_delimited_soft_block_indent( - &l_angle_token?, - ty.format(formatter)?, - &r_angle_token?, - )?, - expression.format(formatter)? + [ + formatter.format_delimited_soft_block_indent( + &l_angle_token?, + formatted![formatter, [ty.format()]]?, + &r_angle_token?, + )?, + expression.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/lists/enum_member_list.rs b/crates/rome_js_formatter/src/ts/lists/enum_member_list.rs index f83352af42cd..9fb8aafaf999 100644 --- a/crates/rome_js_formatter/src/ts/lists/enum_member_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/enum_member_list.rs @@ -1,12 +1,13 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatTsEnumMemberList; use crate::prelude::*; use rome_js_syntax::TsEnumMemberList; -impl Format for TsEnumMemberList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatTsEnumMemberList { + fn format(node: &TsEnumMemberList, formatter: &Formatter) -> FormatResult { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::default())?, + formatter.format_separated(node, || token(","), TrailingSeparator::default())?, )) } } diff --git a/crates/rome_js_formatter/src/ts/lists/index_signature_modifier_list.rs b/crates/rome_js_formatter/src/ts/lists/index_signature_modifier_list.rs index 9bc2882aba72..f0a633bd036b 100644 --- a/crates/rome_js_formatter/src/ts/lists/index_signature_modifier_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/index_signature_modifier_list.rs @@ -1,12 +1,16 @@ +use crate::generated::FormatTsIndexSignatureModifierList; use crate::prelude::*; use crate::utils::sort_modifiers_by_precedence; use rome_js_syntax::TsIndexSignatureModifierList; -impl Format for TsIndexSignatureModifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatTsIndexSignatureModifierList { + fn format( + node: &TsIndexSignatureModifierList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( space_token(), - formatter.format_all(sort_modifiers_by_precedence(self))?, + formatter.format_all(sort_modifiers_by_precedence(node).into_iter().formatted())?, )) } } diff --git a/crates/rome_js_formatter/src/ts/lists/intersection_type_element_list.rs b/crates/rome_js_formatter/src/ts/lists/intersection_type_element_list.rs index e3cbe2059760..9cb36e6c57fa 100644 --- a/crates/rome_js_formatter/src/ts/lists/intersection_type_element_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/intersection_type_element_list.rs @@ -1,13 +1,17 @@ +use crate::generated::FormatTsIntersectionTypeElementList; use crate::prelude::*; use rome_js_syntax::TsIntersectionTypeElementList; use rome_rowan::AstSeparatedList; -impl Format for TsIntersectionTypeElementList { - fn format(&self, formatter: &Formatter) -> FormatResult { - let mut elements = Vec::with_capacity(self.len()); - let last_index = self.len().saturating_sub(1); +impl FormatRule for FormatTsIntersectionTypeElementList { + fn format( + node: &TsIntersectionTypeElementList, + formatter: &Formatter, + ) -> FormatResult { + let mut elements = Vec::with_capacity(node.len()); + let last_index = node.len().saturating_sub(1); - for (index, item) in self.elements().enumerate() { + for (index, item) in node.elements().enumerate() { let ty = item.node()?; let separator = item.trailing_separator()?; @@ -18,9 +22,7 @@ impl Format for TsIntersectionTypeElementList { } else { formatted![ formatter, - soft_line_break_or_space(), - token.format(formatter)?, - space_token() + [soft_line_break_or_space(), token.format(), space_token()] ]? } } @@ -30,15 +32,13 @@ impl Format for TsIntersectionTypeElementList { } else { formatted![ formatter, - soft_line_break_or_space(), - token("&"), - space_token() + [soft_line_break_or_space(), token("&"), space_token()] ]? } } }; - elements.push(formatted![formatter, ty.format(formatter)?, separator]?) + elements.push(formatted![formatter, [ty.format(), separator]]?) } Ok(concat_elements(elements)) 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 18225e24edcb..222ca1d433b2 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,12 +1,16 @@ +use crate::generated::FormatTsMethodSignatureModifierList; use crate::prelude::*; use crate::utils::sort_modifiers_by_precedence; use rome_js_syntax::TsMethodSignatureModifierList; -impl Format for TsMethodSignatureModifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatTsMethodSignatureModifierList { + fn format( + node: &TsMethodSignatureModifierList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( space_token(), - formatter.format_all(sort_modifiers_by_precedence(self))?, + formatter.format_all(sort_modifiers_by_precedence(node).into_iter().formatted())?, )) } } diff --git a/crates/rome_js_formatter/src/ts/lists/property_parameter_modifier_list.rs b/crates/rome_js_formatter/src/ts/lists/property_parameter_modifier_list.rs index f794e37c1a45..9942501809c8 100644 --- a/crates/rome_js_formatter/src/ts/lists/property_parameter_modifier_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/property_parameter_modifier_list.rs @@ -1,12 +1,16 @@ +use crate::generated::FormatTsPropertyParameterModifierList; use crate::prelude::*; use crate::utils::sort_modifiers_by_precedence; use rome_js_syntax::TsPropertyParameterModifierList; -impl Format for TsPropertyParameterModifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatTsPropertyParameterModifierList { + fn format( + node: &TsPropertyParameterModifierList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( space_token(), - formatter.format_all(sort_modifiers_by_precedence(self))?, + formatter.format_all(sort_modifiers_by_precedence(node).into_iter().formatted())?, )) } } 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 ddb1f81a763d..f7eae0f42da2 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,12 +1,16 @@ +use crate::generated::FormatTsPropertySignatureModifierList; use crate::prelude::*; use crate::utils::sort_modifiers_by_precedence; use rome_js_syntax::TsPropertySignatureModifierList; -impl Format for TsPropertySignatureModifierList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatTsPropertySignatureModifierList { + fn format( + node: &TsPropertySignatureModifierList, + formatter: &Formatter, + ) -> FormatResult { Ok(join_elements( space_token(), - formatter.format_all(sort_modifiers_by_precedence(self))?, + formatter.format_all(sort_modifiers_by_precedence(node).into_iter().formatted())?, )) } } diff --git a/crates/rome_js_formatter/src/ts/lists/template_element_list.rs b/crates/rome_js_formatter/src/ts/lists/template_element_list.rs index 5ea693414d48..25cba77d3c8a 100644 --- a/crates/rome_js_formatter/src/ts/lists/template_element_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/template_element_list.rs @@ -1,9 +1,12 @@ +use crate::generated::FormatTsTemplateElementList; use crate::prelude::*; use rome_js_syntax::TsTemplateElementList; use rome_rowan::AstNodeList; -impl Format for TsTemplateElementList { - fn format(&self, formatter: &Formatter) -> FormatResult { - Ok(concat_elements(formatter.format_all(self.iter())?)) +impl FormatRule for FormatTsTemplateElementList { + fn format(node: &TsTemplateElementList, formatter: &Formatter) -> FormatResult { + Ok(concat_elements( + formatter.format_all(node.iter().formatted())?, + )) } } diff --git a/crates/rome_js_formatter/src/ts/lists/tuple_type_element_list.rs b/crates/rome_js_formatter/src/ts/lists/tuple_type_element_list.rs index 4f53b2da549d..4140811fd024 100644 --- a/crates/rome_js_formatter/src/ts/lists/tuple_type_element_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/tuple_type_element_list.rs @@ -1,12 +1,13 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatTsTupleTypeElementList; use crate::prelude::*; use rome_js_syntax::TsTupleTypeElementList; -impl Format for TsTupleTypeElementList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatTsTupleTypeElementList { + fn format(node: &TsTupleTypeElementList, formatter: &Formatter) -> FormatResult { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::default())?, + formatter.format_separated(node, || token(","), TrailingSeparator::default())?, )) } } diff --git a/crates/rome_js_formatter/src/ts/lists/type_argument_list.rs b/crates/rome_js_formatter/src/ts/lists/type_argument_list.rs index 0cf97a4d2987..6faac836cab3 100644 --- a/crates/rome_js_formatter/src/ts/lists/type_argument_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/type_argument_list.rs @@ -1,12 +1,13 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatTsTypeArgumentList; use crate::prelude::*; use rome_js_syntax::TsTypeArgumentList; -impl Format for TsTypeArgumentList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatTsTypeArgumentList { + fn format(node: &TsTypeArgumentList, formatter: &Formatter) -> FormatResult { Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::Disallowed)?, + formatter.format_separated(node, || token(","), TrailingSeparator::Disallowed)?, )) } } diff --git a/crates/rome_js_formatter/src/ts/lists/type_list.rs b/crates/rome_js_formatter/src/ts/lists/type_list.rs index 8950cf5f6a8c..516ac35e7114 100644 --- a/crates/rome_js_formatter/src/ts/lists/type_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/type_list.rs @@ -1,13 +1,14 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatTsTypeList; use crate::prelude::*; use rome_js_syntax::TsTypeList; -impl Format for TsTypeList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatTsTypeList { + fn format(node: &TsTypeList, formatter: &Formatter) -> FormatResult { // the grouping will be applied by the parent Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), TrailingSeparator::Disallowed)?, + formatter.format_separated(node, || token(","), TrailingSeparator::Disallowed)?, )) } } diff --git a/crates/rome_js_formatter/src/ts/lists/type_member_list.rs b/crates/rome_js_formatter/src/ts/lists/type_member_list.rs index f51980c21434..d23854c520c2 100644 --- a/crates/rome_js_formatter/src/ts/lists/type_member_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/type_member_list.rs @@ -1,16 +1,17 @@ +use crate::generated::FormatTsTypeMemberList; use crate::prelude::*; use rome_js_syntax::TsTypeMemberList; use rome_rowan::AstNodeList; -impl Format for TsTypeMemberList { - fn format(&self, formatter: &Formatter) -> FormatResult { - let items = self.iter(); +impl FormatRule for FormatTsTypeMemberList { + fn format(node: &TsTypeMemberList, formatter: &Formatter) -> FormatResult { + let items = node.iter(); let last_index = items.len().saturating_sub(1); let items = items .enumerate() .map(|(index, element)| { - let formatted_element = element.format(formatter)?; + let formatted_element = formatted![formatter, [element.format()]]?; let is_verbatim = matches!( formatted_element.last_element(), @@ -29,7 +30,7 @@ impl Format for TsTypeMemberList { empty_element() }; - formatted![formatter, formatted_element, separator] + formatted![formatter, [formatted_element, separator]] }) .collect::>>()?; diff --git a/crates/rome_js_formatter/src/ts/lists/type_parameter_list.rs b/crates/rome_js_formatter/src/ts/lists/type_parameter_list.rs index 94d2d06622a2..7708e8b4c3c6 100644 --- a/crates/rome_js_formatter/src/ts/lists/type_parameter_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/type_parameter_list.rs @@ -1,24 +1,25 @@ use crate::formatter::TrailingSeparator; +use crate::generated::FormatTsTypeParameterList; use crate::prelude::*; use rome_js_syntax::TsTypeParameterList; use rome_rowan::AstSeparatedList; -impl Format for TsTypeParameterList { - fn format(&self, formatter: &Formatter) -> FormatResult { +impl FormatRule for FormatTsTypeParameterList { + fn format(node: &TsTypeParameterList, formatter: &Formatter) -> FormatResult { // nodes and formatter are not aware of the source type (TSX vs TS), which means we can't // exactly pin point the exact case. // // This is just an heuristic to avoid removing the trailing comma from a TSX grammar. // This means that, if we are in a TS context and we have a trailing comma, the formatter won't remove it. // It's an edge case, while waiting for a better solution, - let trailing_separator = if self.len() == 1 && self.trailing_separator().is_some() { + let trailing_separator = if node.len() == 1 && node.trailing_separator().is_some() { TrailingSeparator::Mandatory } else { TrailingSeparator::default() }; Ok(join_elements( soft_line_break_or_space(), - formatter.format_separated(self, || token(","), trailing_separator)?, + formatter.format_separated(node, || token(","), trailing_separator)?, )) } } diff --git a/crates/rome_js_formatter/src/ts/lists/union_type_variant_list.rs b/crates/rome_js_formatter/src/ts/lists/union_type_variant_list.rs index 6b0894dee94e..69bbc9dfc72a 100644 --- a/crates/rome_js_formatter/src/ts/lists/union_type_variant_list.rs +++ b/crates/rome_js_formatter/src/ts/lists/union_type_variant_list.rs @@ -1,13 +1,14 @@ +use crate::generated::FormatTsUnionTypeVariantList; use crate::prelude::*; use rome_js_syntax::TsUnionTypeVariantList; use rome_rowan::AstSeparatedList; -impl Format for TsUnionTypeVariantList { - fn format(&self, formatter: &Formatter) -> FormatResult { - let mut elements = Vec::with_capacity(self.len()); - let last_index = self.len().saturating_sub(1); +impl FormatRule for FormatTsUnionTypeVariantList { + fn format(node: &TsUnionTypeVariantList, formatter: &Formatter) -> FormatResult { + let mut elements = Vec::with_capacity(node.len()); + let last_index = node.len().saturating_sub(1); - for (index, item) in self.elements().enumerate() { + for (index, item) in node.elements().enumerate() { let ty = item.node()?; let separator = item.trailing_separator()?; @@ -18,9 +19,7 @@ impl Format for TsUnionTypeVariantList { } else { formatted![ formatter, - soft_line_break_or_space(), - token.format(formatter)?, - space_token() + [soft_line_break_or_space(), token.format(), space_token()] ]? } } @@ -30,15 +29,13 @@ impl Format for TsUnionTypeVariantList { } else { formatted![ formatter, - soft_line_break_or_space(), - token("|"), - space_token() + [soft_line_break_or_space(), token("|"), space_token()] ]? } } }; - elements.push(formatted![formatter, ty.format(formatter)?, separator]?) + elements.push(formatted![formatter, [ty.format(), separator]]?) } Ok(concat_elements(elements)) diff --git a/crates/rome_js_formatter/src/ts/module/export_as_namespace_clause.rs b/crates/rome_js_formatter/src/ts/module/export_as_namespace_clause.rs index d917af98598d..93769fa45a9f 100644 --- a/crates/rome_js_formatter/src/ts/module/export_as_namespace_clause.rs +++ b/crates/rome_js_formatter/src/ts/module/export_as_namespace_clause.rs @@ -1,26 +1,32 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::TsExportAsNamespaceClause; use rome_js_syntax::TsExportAsNamespaceClauseFields; -impl FormatNode for TsExportAsNamespaceClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsExportAsNamespaceClause, + formatter: &Formatter, + ) -> FormatResult { let TsExportAsNamespaceClauseFields { as_token, namespace_token, name, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); format_with_semicolon( formatter, formatted![ formatter, - as_token.format(formatter)?, - space_token(), - namespace_token.format(formatter)?, - space_token(), - name.format(formatter)?, + [ + as_token.format(), + space_token(), + namespace_token.format(), + space_token(), + name.format(), + ] ]?, semicolon_token, ) diff --git a/crates/rome_js_formatter/src/ts/module/export_assignment_clause.rs b/crates/rome_js_formatter/src/ts/module/export_assignment_clause.rs index aa70ae5ec71f..81a112c1a97d 100644 --- a/crates/rome_js_formatter/src/ts/module/export_assignment_clause.rs +++ b/crates/rome_js_formatter/src/ts/module/export_assignment_clause.rs @@ -1,23 +1,25 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::TsExportAssignmentClause; use rome_js_syntax::TsExportAssignmentClauseFields; -impl FormatNode for TsExportAssignmentClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsExportAssignmentClause, + formatter: &Formatter, + ) -> FormatResult { let TsExportAssignmentClauseFields { eq_token, expression, semicolon_token, - } = self.as_fields(); + } = node.as_fields(); format_with_semicolon( formatter, formatted![ formatter, - eq_token.format(formatter)?, - space_token(), - expression.format(formatter)?, + [eq_token.format(), space_token(), expression.format(),] ]?, semicolon_token, ) diff --git a/crates/rome_js_formatter/src/ts/module/export_declare_clause.rs b/crates/rome_js_formatter/src/ts/module/export_declare_clause.rs index 607d3557832d..11176ef7feba 100644 --- a/crates/rome_js_formatter/src/ts/module/export_declare_clause.rs +++ b/crates/rome_js_formatter/src/ts/module/export_declare_clause.rs @@ -1,19 +1,21 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsExportDeclareClause; use rome_js_syntax::TsExportDeclareClauseFields; -impl FormatNode for TsExportDeclareClause { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsExportDeclareClause, + formatter: &Formatter, + ) -> FormatResult { let TsExportDeclareClauseFields { declare_token, declaration, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - declare_token.format(formatter)?, - space_token(), - declaration.format(formatter)?, + [declare_token.format(), space_token(), declaration.format(),] ] } } diff --git a/crates/rome_js_formatter/src/ts/module/import_type.rs b/crates/rome_js_formatter/src/ts/module/import_type.rs index af502660f7f3..ceebe656d228 100644 --- a/crates/rome_js_formatter/src/ts/module/import_type.rs +++ b/crates/rome_js_formatter/src/ts/module/import_type.rs @@ -1,10 +1,11 @@ use crate::prelude::*; use crate::utils::format_string_literal_token; +use crate::FormatNodeFields; use rome_js_syntax::TsImportType; use rome_js_syntax::TsImportTypeFields; -impl FormatNode for TsImportType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsImportType, formatter: &Formatter) -> FormatResult { let TsImportTypeFields { typeof_token, import_token, @@ -13,17 +14,21 @@ impl FormatNode for TsImportType { r_paren_token, qualifier_clause, type_arguments, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - typeof_token.with_or_empty(|token| formatted![formatter, token, space_token()]), - import_token.format(formatter)?, - l_paren_token.format(formatter)?, - format_string_literal_token(argument_token?, formatter), - r_paren_token.format(formatter)?, - qualifier_clause, - type_arguments, + [ + typeof_token + .format() + .with_or_empty(|token| formatted![formatter, [token, space_token()]]), + import_token.format(), + l_paren_token.format(), + format_string_literal_token(argument_token?, formatter), + r_paren_token.format(), + qualifier_clause.format(), + type_arguments.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/module/import_type_qualifier.rs b/crates/rome_js_formatter/src/ts/module/import_type_qualifier.rs index 45e77086bb45..a17ee6709e69 100644 --- a/crates/rome_js_formatter/src/ts/module/import_type_qualifier.rs +++ b/crates/rome_js_formatter/src/ts/module/import_type_qualifier.rs @@ -1,15 +1,15 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsImportTypeQualifier; use rome_js_syntax::TsImportTypeQualifierFields; -impl FormatNode for TsImportTypeQualifier { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let TsImportTypeQualifierFields { dot_token, right } = self.as_fields(); +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsImportTypeQualifier, + formatter: &Formatter, + ) -> FormatResult { + let TsImportTypeQualifierFields { dot_token, right } = node.as_fields(); - formatted![ - formatter, - dot_token.format(formatter)?, - right.format(formatter)?, - ] + formatted![formatter, [dot_token.format(), right.format(),]] } } diff --git a/crates/rome_js_formatter/src/ts/statements/declare_statement.rs b/crates/rome_js_formatter/src/ts/statements/declare_statement.rs index f5c3c77d309e..25d028271f45 100644 --- a/crates/rome_js_formatter/src/ts/statements/declare_statement.rs +++ b/crates/rome_js_formatter/src/ts/statements/declare_statement.rs @@ -1,18 +1,20 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsDeclareStatement; use rome_js_syntax::TsDeclareStatementFields; -impl FormatNode for TsDeclareStatement { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsDeclareStatement, + formatter: &Formatter, + ) -> FormatResult { let TsDeclareStatementFields { declaration, declare_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - declare_token.format(formatter)?, - space_token(), - declaration.format(formatter)? + [declare_token.format(), space_token(), declaration.format()] ] } } diff --git a/crates/rome_js_formatter/src/ts/types/any_type.rs b/crates/rome_js_formatter/src/ts/types/any_type.rs index 33013a42b68b..1e20970278c8 100644 --- a/crates/rome_js_formatter/src/ts/types/any_type.rs +++ b/crates/rome_js_formatter/src/ts/types/any_type.rs @@ -1,8 +1,11 @@ use crate::prelude::*; -use rome_js_syntax::TsAnyType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsAnyType, TsAnyTypeFields}; -impl FormatNode for TsAnyType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.any_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsAnyType, formatter: &Formatter) -> FormatResult { + let TsAnyTypeFields { any_token } = node.as_fields(); + + formatted![formatter, [any_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/array_type.rs b/crates/rome_js_formatter/src/ts/types/array_type.rs index 48e7e194d7a5..b56e9422bfc9 100644 --- a/crates/rome_js_formatter/src/ts/types/array_type.rs +++ b/crates/rome_js_formatter/src/ts/types/array_type.rs @@ -1,18 +1,21 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::{TsArrayType, TsArrayTypeFields}; -impl FormatNode for TsArrayType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsArrayType, formatter: &Formatter) -> FormatResult { let TsArrayTypeFields { l_brack_token, element_type, r_brack_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - element_type.format(formatter)?, - l_brack_token.format(formatter)?, - r_brack_token.format(formatter)?, + [ + element_type.format(), + l_brack_token.format(), + r_brack_token.format(), + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/types/asserts_return_type.rs b/crates/rome_js_formatter/src/ts/types/asserts_return_type.rs index b4636a0ead7d..fdd4febba585 100644 --- a/crates/rome_js_formatter/src/ts/types/asserts_return_type.rs +++ b/crates/rome_js_formatter/src/ts/types/asserts_return_type.rs @@ -1,21 +1,27 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsAssertsReturnType; use rome_js_syntax::TsAssertsReturnTypeFields; -impl FormatNode for TsAssertsReturnType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsAssertsReturnType, + formatter: &Formatter, + ) -> FormatResult { let TsAssertsReturnTypeFields { parameter_name, asserts_token, predicate, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - asserts_token.format(formatter)?, - space_token(), - parameter_name.format(formatter)?, - space_token(), - predicate + [ + asserts_token.format(), + space_token(), + parameter_name.format(), + space_token(), + predicate.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/types/big_int_literal_type.rs b/crates/rome_js_formatter/src/ts/types/big_int_literal_type.rs index a170739a8e6c..884ec8bdc168 100644 --- a/crates/rome_js_formatter/src/ts/types/big_int_literal_type.rs +++ b/crates/rome_js_formatter/src/ts/types/big_int_literal_type.rs @@ -1,9 +1,17 @@ use crate::prelude::*; -use rome_js_syntax::TsBigIntLiteralType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsBigIntLiteralType, TsBigIntLiteralTypeFields}; -impl FormatNode for TsBigIntLiteralType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let literal = self.literal_token().format(formatter)?; - formatted![formatter, self.minus_token(), literal] +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsBigIntLiteralType, + formatter: &Formatter, + ) -> FormatResult { + let TsBigIntLiteralTypeFields { + minus_token, + literal_token, + } = node.as_fields(); + + formatted![formatter, [minus_token.format(), literal_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/bigint_type.rs b/crates/rome_js_formatter/src/ts/types/bigint_type.rs index a3e07f445010..0e5515ae4d5b 100644 --- a/crates/rome_js_formatter/src/ts/types/bigint_type.rs +++ b/crates/rome_js_formatter/src/ts/types/bigint_type.rs @@ -1,8 +1,11 @@ use crate::prelude::*; -use rome_js_syntax::TsBigintType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsBigintType, TsBigintTypeFields}; -impl FormatNode for TsBigintType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.bigint_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsBigintType, formatter: &Formatter) -> FormatResult { + let TsBigintTypeFields { bigint_token } = node.as_fields(); + + formatted![formatter, [bigint_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/boolean_literal_type.rs b/crates/rome_js_formatter/src/ts/types/boolean_literal_type.rs index 7c7340cf85bb..89e4e084f4c6 100644 --- a/crates/rome_js_formatter/src/ts/types/boolean_literal_type.rs +++ b/crates/rome_js_formatter/src/ts/types/boolean_literal_type.rs @@ -1,8 +1,13 @@ use crate::prelude::*; -use rome_js_syntax::TsBooleanLiteralType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsBooleanLiteralType, TsBooleanLiteralTypeFields}; -impl FormatNode for TsBooleanLiteralType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.literal().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsBooleanLiteralType, + formatter: &Formatter, + ) -> FormatResult { + let TsBooleanLiteralTypeFields { literal } = node.as_fields(); + formatted![formatter, [literal.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/boolean_type.rs b/crates/rome_js_formatter/src/ts/types/boolean_type.rs index fa015050f52e..f86e479a15a1 100644 --- a/crates/rome_js_formatter/src/ts/types/boolean_type.rs +++ b/crates/rome_js_formatter/src/ts/types/boolean_type.rs @@ -1,8 +1,11 @@ use crate::prelude::*; -use rome_js_syntax::TsBooleanType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsBooleanType, TsBooleanTypeFields}; -impl FormatNode for TsBooleanType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.boolean_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsBooleanType, formatter: &Formatter) -> FormatResult { + let TsBooleanTypeFields { boolean_token } = node.as_fields(); + + formatted![formatter, [boolean_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/conditional_type.rs b/crates/rome_js_formatter/src/ts/types/conditional_type.rs index 7d868922ca3e..c3f652b65850 100644 --- a/crates/rome_js_formatter/src/ts/types/conditional_type.rs +++ b/crates/rome_js_formatter/src/ts/types/conditional_type.rs @@ -1,9 +1,13 @@ use crate::prelude::*; use crate::utils::{format_conditional, Conditional}; +use crate::FormatNodeFields; use rome_js_syntax::TsConditionalType; -impl FormatNode for TsConditionalType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - format_conditional(Conditional::Type(self.clone()), formatter, false) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsConditionalType, + formatter: &Formatter, + ) -> FormatResult { + format_conditional(Conditional::Type(node.clone()), formatter, false) } } diff --git a/crates/rome_js_formatter/src/ts/types/constructor_type.rs b/crates/rome_js_formatter/src/ts/types/constructor_type.rs index 7d026c3e92ac..e84b2cadf6f7 100644 --- a/crates/rome_js_formatter/src/ts/types/constructor_type.rs +++ b/crates/rome_js_formatter/src/ts/types/constructor_type.rs @@ -1,9 +1,13 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsConstructorType; use rome_js_syntax::TsConstructorTypeFields; -impl FormatNode for TsConstructorType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsConstructorType, + formatter: &Formatter, + ) -> FormatResult { let TsConstructorTypeFields { abstract_token, new_token, @@ -11,20 +15,22 @@ impl FormatNode for TsConstructorType { parameters, fat_arrow_token, return_type, - } = self.as_fields(); - let abstract_token = - abstract_token.with_or_empty(|element| formatted![formatter, element, space_token()]); + } = node.as_fields(); formatted![ formatter, - abstract_token, - new_token.format(formatter)?, - type_parameters, - parameters.format(formatter)?, - space_token(), - fat_arrow_token.format(formatter)?, - space_token(), - return_type.format(formatter)? + [ + abstract_token + .format() + .with_or_empty(|element| formatted![formatter, [element, space_token()]]), + new_token.format(), + type_parameters.format(), + parameters.format(), + space_token(), + fat_arrow_token.format(), + space_token(), + return_type.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/types/function_type.rs b/crates/rome_js_formatter/src/ts/types/function_type.rs index 9102f6793bbc..1e9fc6bbde60 100644 --- a/crates/rome_js_formatter/src/ts/types/function_type.rs +++ b/crates/rome_js_formatter/src/ts/types/function_type.rs @@ -1,24 +1,27 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsFunctionType; use rome_js_syntax::TsFunctionTypeFields; -impl FormatNode for TsFunctionType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsFunctionType, formatter: &Formatter) -> FormatResult { let TsFunctionTypeFields { parameters, fat_arrow_token, type_parameters, return_type, - } = self.as_fields(); + } = node.as_fields(); Ok(hard_group_elements(formatted![ formatter, - type_parameters, - parameters.format(formatter)?, - space_token(), - fat_arrow_token.format(formatter)?, - space_token(), - return_type.format(formatter)? + [ + type_parameters.format(), + parameters.format(), + space_token(), + fat_arrow_token.format(), + space_token(), + return_type.format() + ] ]?)) } } diff --git a/crates/rome_js_formatter/src/ts/types/indexed_access_type.rs b/crates/rome_js_formatter/src/ts/types/indexed_access_type.rs index 23db7cd9d9bc..5d5197498882 100644 --- a/crates/rome_js_formatter/src/ts/types/indexed_access_type.rs +++ b/crates/rome_js_formatter/src/ts/types/indexed_access_type.rs @@ -1,21 +1,27 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsIndexedAccessType; use rome_js_syntax::TsIndexedAccessTypeFields; -impl FormatNode for TsIndexedAccessType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsIndexedAccessType, + formatter: &Formatter, + ) -> FormatResult { let TsIndexedAccessTypeFields { object_type, l_brack_token, index_type, r_brack_token, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - object_type.format(formatter)?, - l_brack_token.format(formatter)?, - index_type.format(formatter)?, - r_brack_token.format(formatter)? + [ + object_type.format(), + l_brack_token.format(), + index_type.format(), + r_brack_token.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/types/infer_type.rs b/crates/rome_js_formatter/src/ts/types/infer_type.rs index 617b7e31d08a..3764ea895f64 100644 --- a/crates/rome_js_formatter/src/ts/types/infer_type.rs +++ b/crates/rome_js_formatter/src/ts/types/infer_type.rs @@ -1,10 +1,15 @@ use crate::prelude::*; -use rome_js_syntax::TsInferType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsInferType, TsInferTypeFields}; -impl FormatNode for TsInferType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let infer = self.infer_token().format(formatter)?; - let type_parameter = self.type_parameter().format(formatter)?; - formatted![formatter, infer, space_token(), type_parameter] +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsInferType, formatter: &Formatter) -> FormatResult { + let TsInferTypeFields { + infer_token, + type_parameter, + } = node.as_fields(); + let infer = infer_token.format(); + let type_parameter = type_parameter.format(); + formatted![formatter, [infer, space_token(), type_parameter]] } } diff --git a/crates/rome_js_formatter/src/ts/types/intersection_type.rs b/crates/rome_js_formatter/src/ts/types/intersection_type.rs index 709613b1c242..e45cbb8c08df 100644 --- a/crates/rome_js_formatter/src/ts/types/intersection_type.rs +++ b/crates/rome_js_formatter/src/ts/types/intersection_type.rs @@ -1,13 +1,17 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsIntersectionType; use rome_js_syntax::TsIntersectionTypeFields; -impl FormatNode for TsIntersectionType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsIntersectionType, + formatter: &Formatter, + ) -> FormatResult { let TsIntersectionTypeFields { leading_separator_token, types, - } = self.as_fields(); + } = node.as_fields(); let leading_separator_token = match leading_separator_token { Some(token) => { @@ -25,9 +29,7 @@ impl FormatNode for TsIntersectionType { Ok(group_elements(indent(formatted![ formatter, - soft_line_break(), - leading_separator_token, - types.format(formatter)?, + [soft_line_break(), leading_separator_token, types.format(),] ]?))) } } diff --git a/crates/rome_js_formatter/src/ts/types/mapped_type.rs b/crates/rome_js_formatter/src/ts/types/mapped_type.rs index 34c4bb6a582c..38b9e474b9bc 100644 --- a/crates/rome_js_formatter/src/ts/types/mapped_type.rs +++ b/crates/rome_js_formatter/src/ts/types/mapped_type.rs @@ -1,9 +1,10 @@ use crate::prelude::*; use crate::utils::format_with_semicolon; +use crate::FormatNodeFields; use rome_js_syntax::{TsMappedType, TsMappedTypeFields}; -impl FormatNode for TsMappedType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsMappedType, formatter: &Formatter) -> FormatResult { let TsMappedTypeFields { l_curly_token, readonly_modifier, @@ -17,17 +18,7 @@ impl FormatNode for TsMappedType { mapped_type, semicolon_token, r_curly_token, - } = self.as_fields(); - - let readonly = readonly_modifier - .with_or_empty(|readonly| formatted![formatter, readonly, space_token()]); - let l_square = l_brack_token.format(formatter)?; - let property_name = property_name.format(formatter)?; - let in_token = in_token.format(formatter)?; - let keys = keys_type.format(formatter)?; - let as_clause = - as_clause.with_or_empty(|clause| formatted![formatter, space_token(), clause]); - let r_square = r_brack_token.format(formatter)?; + } = node.as_fields(); formatter.format_delimited_block_indent( &l_curly_token?, @@ -35,17 +26,26 @@ impl FormatNode for TsMappedType { formatter, formatted![ formatter, - readonly, - l_square, - property_name, - space_token(), - in_token, - space_token(), - keys, - as_clause, - r_square, - optional_modifier, - mapped_type, + [ + readonly_modifier + .format() + .with_or_empty(|readonly| formatted![ + formatter, + [readonly, space_token()] + ]), + l_brack_token.format(), + property_name.format(), + space_token(), + in_token.format(), + space_token(), + keys_type.format(), + as_clause + .format() + .with_or_empty(|clause| formatted![formatter, [space_token(), clause]]), + r_brack_token.format(), + optional_modifier.format(), + mapped_type.format(), + ] ]?, semicolon_token, )?, diff --git a/crates/rome_js_formatter/src/ts/types/never_type.rs b/crates/rome_js_formatter/src/ts/types/never_type.rs index a3a1142dfced..3e311577b906 100644 --- a/crates/rome_js_formatter/src/ts/types/never_type.rs +++ b/crates/rome_js_formatter/src/ts/types/never_type.rs @@ -1,8 +1,10 @@ use crate::prelude::*; -use rome_js_syntax::TsNeverType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsNeverType, TsNeverTypeFields}; -impl FormatNode for TsNeverType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.never_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsNeverType, formatter: &Formatter) -> FormatResult { + let TsNeverTypeFields { never_token } = node.as_fields(); + formatted![formatter, [never_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/non_primitive_type.rs b/crates/rome_js_formatter/src/ts/types/non_primitive_type.rs index 5356209c05c1..5cbdeca31633 100644 --- a/crates/rome_js_formatter/src/ts/types/non_primitive_type.rs +++ b/crates/rome_js_formatter/src/ts/types/non_primitive_type.rs @@ -1,8 +1,14 @@ use crate::prelude::*; -use rome_js_syntax::TsNonPrimitiveType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsNonPrimitiveType, TsNonPrimitiveTypeFields}; -impl FormatNode for TsNonPrimitiveType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.object_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsNonPrimitiveType, + formatter: &Formatter, + ) -> FormatResult { + let TsNonPrimitiveTypeFields { object_token } = node.as_fields(); + + formatted![formatter, [object_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/null_literal_type.rs b/crates/rome_js_formatter/src/ts/types/null_literal_type.rs index 470a50b01254..acec69535c10 100644 --- a/crates/rome_js_formatter/src/ts/types/null_literal_type.rs +++ b/crates/rome_js_formatter/src/ts/types/null_literal_type.rs @@ -1,8 +1,13 @@ use crate::prelude::*; -use rome_js_syntax::TsNullLiteralType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsNullLiteralType, TsNullLiteralTypeFields}; -impl FormatNode for TsNullLiteralType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.literal_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsNullLiteralType, + formatter: &Formatter, + ) -> FormatResult { + let TsNullLiteralTypeFields { literal_token } = node.as_fields(); + formatted![formatter, [literal_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/number_literal_type.rs b/crates/rome_js_formatter/src/ts/types/number_literal_type.rs index da86e58cde8f..30858daef058 100644 --- a/crates/rome_js_formatter/src/ts/types/number_literal_type.rs +++ b/crates/rome_js_formatter/src/ts/types/number_literal_type.rs @@ -1,10 +1,16 @@ use crate::prelude::*; -use rome_js_syntax::TsNumberLiteralType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsNumberLiteralType, TsNumberLiteralTypeFields}; -impl FormatNode for TsNumberLiteralType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let minus = self.minus_token(); - let literal = self.literal_token().format(formatter)?; - formatted![formatter, minus, literal] +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsNumberLiteralType, + formatter: &Formatter, + ) -> FormatResult { + let TsNumberLiteralTypeFields { + minus_token, + literal_token, + } = node.as_fields(); + formatted![formatter, [minus_token.format(), literal_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/number_type.rs b/crates/rome_js_formatter/src/ts/types/number_type.rs index 04c84c95caa0..f01cc0c09fae 100644 --- a/crates/rome_js_formatter/src/ts/types/number_type.rs +++ b/crates/rome_js_formatter/src/ts/types/number_type.rs @@ -1,8 +1,11 @@ use crate::prelude::*; -use rome_js_syntax::TsNumberType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsNumberType, TsNumberTypeFields}; -impl FormatNode for TsNumberType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.number_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsNumberType, formatter: &Formatter) -> FormatResult { + let TsNumberTypeFields { number_token } = node.as_fields(); + + formatted![formatter, [number_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/object_type.rs b/crates/rome_js_formatter/src/ts/types/object_type.rs index 75d45e513b93..397a1d29e848 100644 --- a/crates/rome_js_formatter/src/ts/types/object_type.rs +++ b/crates/rome_js_formatter/src/ts/types/object_type.rs @@ -1,12 +1,19 @@ use crate::prelude::*; -use rome_js_syntax::TsObjectType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsObjectType, TsObjectTypeFields}; + +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsObjectType, formatter: &Formatter) -> FormatResult { + let TsObjectTypeFields { + l_curly_token, + members, + r_curly_token, + } = node.as_fields(); -impl FormatNode for TsObjectType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { formatter.format_delimited_soft_block_spaces( - &self.l_curly_token()?, - self.members().format(formatter)?, - &self.r_curly_token()?, + &l_curly_token?, + formatted![formatter, [members.format()]]?, + &r_curly_token?, ) } } diff --git a/crates/rome_js_formatter/src/ts/types/parenthesized_type.rs b/crates/rome_js_formatter/src/ts/types/parenthesized_type.rs index c9ddffcf85be..63c71eb99162 100644 --- a/crates/rome_js_formatter/src/ts/types/parenthesized_type.rs +++ b/crates/rome_js_formatter/src/ts/types/parenthesized_type.rs @@ -1,18 +1,22 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsParenthesizedType; use rome_js_syntax::TsParenthesizedTypeFields; -impl FormatNode for TsParenthesizedType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsParenthesizedType, + formatter: &Formatter, + ) -> FormatResult { let TsParenthesizedTypeFields { l_paren_token, ty, r_paren_token, - } = self.as_fields(); + } = node.as_fields(); formatter.format_delimited_soft_block_indent( &l_paren_token?, - ty.format(formatter)?, + formatted![formatter, [ty.format()]]?, &r_paren_token?, ) } diff --git a/crates/rome_js_formatter/src/ts/types/predicate_return_type.rs b/crates/rome_js_formatter/src/ts/types/predicate_return_type.rs index bf6573ff6f6b..03f7ce15d5a1 100644 --- a/crates/rome_js_formatter/src/ts/types/predicate_return_type.rs +++ b/crates/rome_js_formatter/src/ts/types/predicate_return_type.rs @@ -1,21 +1,27 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsPredicateReturnType; use rome_js_syntax::TsPredicateReturnTypeFields; -impl FormatNode for TsPredicateReturnType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsPredicateReturnType, + formatter: &Formatter, + ) -> FormatResult { let TsPredicateReturnTypeFields { parameter_name, is_token, ty, - } = self.as_fields(); + } = node.as_fields(); formatted![ formatter, - parameter_name.format(formatter)?, - space_token(), - is_token.format(formatter)?, - space_token(), - ty.format(formatter)? + [ + parameter_name.format(), + space_token(), + is_token.format(), + space_token(), + ty.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/types/reference_type.rs b/crates/rome_js_formatter/src/ts/types/reference_type.rs index e8a5783ef069..3ef08e6348df 100644 --- a/crates/rome_js_formatter/src/ts/types/reference_type.rs +++ b/crates/rome_js_formatter/src/ts/types/reference_type.rs @@ -1,9 +1,14 @@ use crate::prelude::*; -use rome_js_syntax::TsReferenceType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsReferenceType, TsReferenceTypeFields}; -impl FormatNode for TsReferenceType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let name = self.name().format(formatter)?; - formatted![formatter, name, self.type_arguments()] +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsReferenceType, formatter: &Formatter) -> FormatResult { + let TsReferenceTypeFields { + name, + type_arguments, + } = node.as_fields(); + + formatted![formatter, [name.format(), type_arguments.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/string_literal_type.rs b/crates/rome_js_formatter/src/ts/types/string_literal_type.rs index 263fc84432ac..c848169094c4 100644 --- a/crates/rome_js_formatter/src/ts/types/string_literal_type.rs +++ b/crates/rome_js_formatter/src/ts/types/string_literal_type.rs @@ -1,12 +1,15 @@ use crate::prelude::*; use crate::utils::format_string_literal_token; -use rome_js_syntax::TsStringLiteralType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsStringLiteralType, TsStringLiteralTypeFields}; -impl FormatNode for TsStringLiteralType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - Ok(format_string_literal_token( - self.literal_token()?, - formatter, - )) +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsStringLiteralType, + formatter: &Formatter, + ) -> FormatResult { + let TsStringLiteralTypeFields { literal_token } = node.as_fields(); + + Ok(format_string_literal_token(literal_token?, formatter)) } } diff --git a/crates/rome_js_formatter/src/ts/types/string_type.rs b/crates/rome_js_formatter/src/ts/types/string_type.rs index 268e8e7d337f..ff3e2dc02312 100644 --- a/crates/rome_js_formatter/src/ts/types/string_type.rs +++ b/crates/rome_js_formatter/src/ts/types/string_type.rs @@ -1,8 +1,11 @@ use crate::prelude::*; -use rome_js_syntax::TsStringType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsStringType, TsStringTypeFields}; -impl FormatNode for TsStringType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.string_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsStringType, formatter: &Formatter) -> FormatResult { + let TsStringTypeFields { string_token } = node.as_fields(); + + formatted![formatter, [string_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/symbol_type.rs b/crates/rome_js_formatter/src/ts/types/symbol_type.rs index e816d0dc014a..01e9c2b9c0ad 100644 --- a/crates/rome_js_formatter/src/ts/types/symbol_type.rs +++ b/crates/rome_js_formatter/src/ts/types/symbol_type.rs @@ -1,8 +1,11 @@ use crate::prelude::*; -use rome_js_syntax::TsSymbolType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsSymbolType, TsSymbolTypeFields}; -impl FormatNode for TsSymbolType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.symbol_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsSymbolType, formatter: &Formatter) -> FormatResult { + let TsSymbolTypeFields { symbol_token } = node.as_fields(); + + formatted![formatter, [symbol_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/this_type.rs b/crates/rome_js_formatter/src/ts/types/this_type.rs index d5a424cc51e6..49a973701ae9 100644 --- a/crates/rome_js_formatter/src/ts/types/this_type.rs +++ b/crates/rome_js_formatter/src/ts/types/this_type.rs @@ -1,8 +1,11 @@ use crate::prelude::*; -use rome_js_syntax::TsThisType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsThisType, TsThisTypeFields}; -impl FormatNode for TsThisType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.this_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsThisType, formatter: &Formatter) -> FormatResult { + let TsThisTypeFields { this_token } = node.as_fields(); + + formatted![formatter, [this_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/tuple_type.rs b/crates/rome_js_formatter/src/ts/types/tuple_type.rs index c221913e371b..e66df0f1b9b4 100644 --- a/crates/rome_js_formatter/src/ts/types/tuple_type.rs +++ b/crates/rome_js_formatter/src/ts/types/tuple_type.rs @@ -1,12 +1,19 @@ use crate::prelude::*; -use rome_js_syntax::TsTupleType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsTupleType, TsTupleTypeFields}; + +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsTupleType, formatter: &Formatter) -> FormatResult { + let TsTupleTypeFields { + l_brack_token, + elements, + r_brack_token, + } = node.as_fields(); -impl FormatNode for TsTupleType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { formatter.format_delimited_soft_block_indent( - &self.l_brack_token()?, - self.elements().format(formatter)?, - &self.r_brack_token()?, + &l_brack_token?, + formatted![formatter, [elements.format()]]?, + &r_brack_token?, ) } } diff --git a/crates/rome_js_formatter/src/ts/types/type_operator_type.rs b/crates/rome_js_formatter/src/ts/types/type_operator_type.rs index bbf04695880a..f29ffd034382 100644 --- a/crates/rome_js_formatter/src/ts/types/type_operator_type.rs +++ b/crates/rome_js_formatter/src/ts/types/type_operator_type.rs @@ -1,13 +1,22 @@ use crate::prelude::*; -use rome_js_syntax::TsTypeOperatorType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsTypeOperatorType, TsTypeOperatorTypeFields}; + +impl FormatNodeFields for FormatNodeRule { + fn format_fields( + node: &TsTypeOperatorType, + formatter: &Formatter, + ) -> FormatResult { + let TsTypeOperatorTypeFields { operator_token, ty } = node.as_fields(); -impl FormatNode for TsTypeOperatorType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { formatted![ formatter, - self.operator_token() - .with(|operator| { formatted![formatter, operator, space_token()] }), - self.ty().format(formatter)? + [ + operator_token + .format() + .with(|operator| { formatted![formatter, [operator, space_token()]] }), + ty.format() + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/types/typeof_type.rs b/crates/rome_js_formatter/src/ts/types/typeof_type.rs index 76771eb3347e..c0e907234b5a 100644 --- a/crates/rome_js_formatter/src/ts/types/typeof_type.rs +++ b/crates/rome_js_formatter/src/ts/types/typeof_type.rs @@ -1,10 +1,16 @@ use crate::prelude::*; -use rome_js_syntax::TsTypeofType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsTypeofType, TsTypeofTypeFields}; -impl FormatNode for TsTypeofType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - let r#typeof = self.typeof_token().format(formatter)?; - let expression_name = self.expression_name().format(formatter)?; - formatted![formatter, r#typeof, space_token(), expression_name] +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsTypeofType, formatter: &Formatter) -> FormatResult { + let TsTypeofTypeFields { + typeof_token, + expression_name, + } = node.as_fields(); + + let r#typeof = typeof_token.format(); + let expression_name = expression_name.format(); + formatted![formatter, [r#typeof, space_token(), expression_name]] } } diff --git a/crates/rome_js_formatter/src/ts/types/undefined_type.rs b/crates/rome_js_formatter/src/ts/types/undefined_type.rs index 127767a4b561..31503911e534 100644 --- a/crates/rome_js_formatter/src/ts/types/undefined_type.rs +++ b/crates/rome_js_formatter/src/ts/types/undefined_type.rs @@ -1,8 +1,11 @@ use crate::prelude::*; -use rome_js_syntax::TsUndefinedType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsUndefinedType, TsUndefinedTypeFields}; -impl FormatNode for TsUndefinedType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.undefined_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsUndefinedType, formatter: &Formatter) -> FormatResult { + let TsUndefinedTypeFields { undefined_token } = node.as_fields(); + + formatted![formatter, [undefined_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/union_type.rs b/crates/rome_js_formatter/src/ts/types/union_type.rs index 01c4525fd836..7306d467aca0 100644 --- a/crates/rome_js_formatter/src/ts/types/union_type.rs +++ b/crates/rome_js_formatter/src/ts/types/union_type.rs @@ -1,13 +1,14 @@ use crate::prelude::*; +use crate::FormatNodeFields; use rome_js_syntax::TsUnionType; use rome_js_syntax::TsUnionTypeFields; -impl FormatNode for TsUnionType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsUnionType, formatter: &Formatter) -> FormatResult { let TsUnionTypeFields { leading_separator_token, types, - } = self.as_fields(); + } = node.as_fields(); let leading_separator_token = match leading_separator_token { Some(token) => { @@ -23,7 +24,7 @@ impl FormatNode for TsUnionType { None => if_group_breaks(format_elements![token("|"), space_token()]), }; - let types = types.format(formatter)?; + let types = formatted![formatter, [types.format()]]?; // Push trailing comments for the union out of the group (and indent block), // so any potential line break doesn't influence the formatting of the type itself @@ -31,14 +32,18 @@ impl FormatNode for TsUnionType { formatted![ formatter, - group_elements(indent(formatted![ - formatter, - soft_line_break(), - leading_separator_token, - leading_comments, - types, - ]?)), - trailing_comments + [ + group_elements(indent(formatted![ + formatter, + [ + soft_line_break(), + leading_separator_token, + leading_comments, + types, + ] + ]?)), + trailing_comments + ] ] } } diff --git a/crates/rome_js_formatter/src/ts/types/unknown_type.rs b/crates/rome_js_formatter/src/ts/types/unknown_type.rs index 6a8f2a4df708..2450a3220ecc 100644 --- a/crates/rome_js_formatter/src/ts/types/unknown_type.rs +++ b/crates/rome_js_formatter/src/ts/types/unknown_type.rs @@ -1,8 +1,10 @@ use crate::prelude::*; -use rome_js_syntax::TsUnknownType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsUnknownType, TsUnknownTypeFields}; -impl FormatNode for TsUnknownType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.unknown_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsUnknownType, formatter: &Formatter) -> FormatResult { + let TsUnknownTypeFields { unknown_token } = node.as_fields(); + formatted![formatter, [unknown_token.format()]] } } diff --git a/crates/rome_js_formatter/src/ts/types/void_type.rs b/crates/rome_js_formatter/src/ts/types/void_type.rs index 3fac2fe2cbbf..a68d0d11bce1 100644 --- a/crates/rome_js_formatter/src/ts/types/void_type.rs +++ b/crates/rome_js_formatter/src/ts/types/void_type.rs @@ -1,8 +1,11 @@ use crate::prelude::*; -use rome_js_syntax::TsVoidType; +use crate::FormatNodeFields; +use rome_js_syntax::{TsVoidType, TsVoidTypeFields}; -impl FormatNode for TsVoidType { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - self.void_token().format(formatter) +impl FormatNodeFields for FormatNodeRule { + fn format_fields(node: &TsVoidType, formatter: &Formatter) -> FormatResult { + let TsVoidTypeFields { void_token } = node.as_fields(); + + formatted![formatter, [void_token.format()]] } } diff --git a/crates/rome_js_formatter/src/utils/array.rs b/crates/rome_js_formatter/src/utils/array.rs index 6fa113efbe52..4a705069c11f 100644 --- a/crates/rome_js_formatter/src/utils/array.rs +++ b/crates/rome_js_formatter/src/utils/array.rs @@ -1,5 +1,6 @@ use crate::prelude::*; +use crate::AsFormat; use rome_js_syntax::{ JsAnyArrayAssignmentPatternElement, JsAnyArrayBindingPatternElement, JsAnyArrayElement, JsLanguage, @@ -13,7 +14,7 @@ pub(crate) fn format_array_node( ) -> FormatResult where N: AstSeparatedList, - I: ArrayNodeElement, + for<'a> I: ArrayNodeElement + AsFormat<'a>, { // Specifically do not use format_separated as arrays need separators // inserted after holes regardless of the formatting since this makes a @@ -29,7 +30,7 @@ where let is_disallow = matches!(separator_mode, TrailingSeparatorMode::Disallow); let is_force = matches!(separator_mode, TrailingSeparatorMode::Force); - let elem = node.format(formatter)?; + let elem = node.format(); let separator = if is_disallow { // Trailing separators are disallowed, replace it with an empty element if let Some(separator) = element.trailing_separator()? { @@ -41,7 +42,10 @@ where // In forced separator mode or if this element is not the last in the list, print the separator formatted![ formatter, - element.trailing_separator().or_format(|| token(",")) + [&element + .trailing_separator() + .format() + .or_format(|| token(","))] ]? } else if let Some(separator) = element.trailing_separator()? { formatter.format_replaced(separator, if_group_breaks(token(","))) @@ -51,7 +55,7 @@ where Ok(( node.syntax().clone(), - formatted![formatter, elem, separator]?, + formatted![formatter, [elem, separator]]?, )) }) .collect::>>()?; @@ -70,7 +74,7 @@ pub(crate) enum TrailingSeparatorMode { Force, } -pub(crate) trait ArrayNodeElement: AstNode + Format + Clone { +pub(crate) trait ArrayNodeElement: AstNode { /// Determines how the trailing separator should be printer for this element fn separator_mode(&self) -> TrailingSeparatorMode; } diff --git a/crates/rome_js_formatter/src/utils/binary_like_expression.rs b/crates/rome_js_formatter/src/utils/binary_like_expression.rs index 3a290e300856..c6c2b36e9c9c 100644 --- a/crates/rome_js_formatter/src/utils/binary_like_expression.rs +++ b/crates/rome_js_formatter/src/utils/binary_like_expression.rs @@ -1,4 +1,5 @@ use crate::prelude::*; + use rome_js_syntax::{ JsAnyExpression, JsAnyInProperty, JsBinaryExpression, JsBinaryOperator, JsInExpression, JsInstanceofExpression, JsLanguage, JsLogicalExpression, JsLogicalOperator, JsPrivateName, @@ -117,8 +118,8 @@ pub(crate) fn format_binary_like_expression( let left = parent.left()?; - let formatted = left.format_node(formatter)?; let has_comments = left.syntax().has_comments_direct(); + let formatted = formatted![formatter, [left]]?; flatten_items.items.push(FlattenItem::regular( formatted, @@ -207,13 +208,17 @@ fn format_with_or_without_parenthesis( let (leading, content, trailing) = formatted_node.split_trivia(); let formatted = formatted![ formatter, - leading, - group_elements(formatted![ - formatter, - token("("), - soft_block_indent(formatted![formatter, content, trailing]?), - token(")") - ]?) + [ + leading, + group_elements(formatted![ + formatter, + [ + token("("), + soft_block_indent(formatted![formatter, [content, trailing]]?), + token(")") + ] + ]?) + ] ]?; (formatted, true) @@ -312,7 +317,7 @@ impl FlattenItems { ) -> FormatResult<()> { let right = binary_like_expression.right()?; let has_comments = right.syntax().has_comments_direct(); - let right_formatted = right.format(formatter)?; + let right_formatted = formatted![formatter, [right.format()]]?; let (formatted_node, _) = format_with_or_without_parenthesis( binary_like_expression.operator()?, @@ -371,7 +376,7 @@ impl FlattenItems { let (formatted_right, parenthesized) = format_with_or_without_parenthesis( operator, right.syntax(), - right.format(formatter)?, + formatted![formatter, [right.format()]]?, formatter, )?; @@ -425,7 +430,7 @@ impl FlattenItems { let operator = match &element.operator { Some(operator) => { // SAFETY: `syntax_token.format` never returns MissingToken. - formatted![formatter, space_token(), operator].unwrap() + formatted![formatter, [space_token(), operator.format()]].unwrap() } None => empty_element(), }; @@ -864,14 +869,14 @@ impl AstNode for JsAnyBinaryLikeLeftExpression { } } -impl FormatNode for JsAnyBinaryLikeLeftExpression { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { +impl Format for JsAnyBinaryLikeLeftExpression { + fn format(&self, formatter: &Formatter) -> FormatResult { match self { JsAnyBinaryLikeLeftExpression::JsAnyExpression(expression) => { - expression.format(formatter) + formatted![formatter, [expression.format()]] } JsAnyBinaryLikeLeftExpression::JsPrivateName(private_name) => { - private_name.format_fields(formatter) + formatted![formatter, [private_name.format()]] } } } diff --git a/crates/rome_js_formatter/src/utils/format_conditional.rs b/crates/rome_js_formatter/src/utils/format_conditional.rs index d84f1ae7ba57..501f21de9727 100644 --- a/crates/rome_js_formatter/src/utils/format_conditional.rs +++ b/crates/rome_js_formatter/src/utils/format_conditional.rs @@ -43,22 +43,24 @@ impl Conditional { ), }; - formatted![formatter, head, body] + formatted![formatter, [head, body]] } fn format_head(&self, formatter: &Formatter) -> FormatResult { match self { Conditional::Expression(expr) => { - formatted![formatter, expr.test()?.format(formatter)?, space_token(),] + formatted![formatter, [expr.test()?.format(), space_token(),]] } Conditional::Type(t) => formatted![ formatter, - t.check_type()?.format(formatter)?, - space_token(), - t.extends_token()?.format(formatter)?, - space_token(), - t.extends_type()?.format(formatter)?, - space_token(), + [ + t.check_type()?.format(), + space_token(), + t.extends_token()?.format(), + space_token(), + t.extends_type()?.format(), + space_token(), + ] ], } } @@ -112,18 +114,12 @@ impl Conditional { let body = if left_or_right_is_conditional || parent_is_conditional { indent(formatted![ formatter, - hard_line_break(), - consequent, - hard_line_break(), - alternate + [hard_line_break(), consequent, hard_line_break(), alternate] ]?) } else { group_elements(formatted![ formatter, - space_token(), - consequent, - space_token(), - alternate + [space_token(), consequent, space_token(), alternate] ]?) }; Ok(body) @@ -139,16 +135,20 @@ impl Conditional { if let Some(consequent) = consequent { formatted![ formatter, - expr.question_mark_token().format(formatter)?, - space_token(), - consequent + [ + expr.question_mark_token().format(), + space_token(), + consequent + ] ] } else { formatted![ formatter, - expr.question_mark_token().format(formatter)?, - space_token(), - expr.consequent().format(formatter)? + [ + expr.question_mark_token().format(), + space_token(), + expr.consequent().format() + ] ] } } @@ -156,16 +156,16 @@ impl Conditional { if let Some(consequent) = consequent { formatted![ formatter, - ty.question_mark_token().format(formatter)?, - space_token(), - consequent + [ty.question_mark_token().format(), space_token(), consequent] ] } else { formatted![ formatter, - ty.question_mark_token().format(formatter)?, - space_token(), - ty.true_type().format(formatter)? + [ + ty.question_mark_token().format(), + space_token(), + ty.true_type().format() + ] ] } } @@ -182,16 +182,16 @@ impl Conditional { if let Some(alternate) = alternate { formatted![ formatter, - expr.colon_token().format(formatter)?, - space_token(), - alternate + [expr.colon_token().format(), space_token(), alternate] ] } else { formatted![ formatter, - expr.colon_token().format(formatter)?, - space_token(), - expr.alternate().format(formatter)? + [ + expr.colon_token().format(), + space_token(), + expr.alternate().format() + ] ] } } @@ -199,16 +199,16 @@ impl Conditional { if let Some(alternate) = alternate { formatted![ formatter, - ty.colon_token().format(formatter)?, - space_token(), - alternate + [ty.colon_token().format(), space_token(), alternate] ] } else { formatted![ formatter, - ty.colon_token().format(formatter)?, - space_token(), - ty.false_type().format(formatter)? + [ + ty.colon_token().format(), + space_token(), + ty.false_type().format() + ] ] } } diff --git a/crates/rome_js_formatter/src/utils/member_chain/mod.rs b/crates/rome_js_formatter/src/utils/member_chain/mod.rs index c391cf87fdf8..efa2cab38450 100644 --- a/crates/rome_js_formatter/src/utils/member_chain/mod.rs +++ b/crates/rome_js_formatter/src/utils/member_chain/mod.rs @@ -2,12 +2,9 @@ mod flatten_item; mod groups; mod simple_argument; +use crate::prelude::*; use crate::utils::member_chain::flatten_item::FlattenItem; use crate::utils::member_chain::groups::{Groups, HeadGroup}; -use crate::{ - format_elements, group_elements, hard_line_break, indent, Format, FormatElement, FormatResult, - Formatter, -}; use rome_js_syntax::{ JsCallExpression, JsComputedMemberExpression, JsExpressionStatement, JsStaticMemberExpression, }; @@ -323,11 +320,14 @@ fn flatten_call_expression( let call_expression = JsCallExpression::cast(node).unwrap(); let callee = call_expression.callee()?; flatten_call_expression(queue, callee.syntax().clone(), formatter)?; - let formatted = vec![ - formatted!(formatter, call_expression.optional_chain_token())?, - formatted!(formatter, call_expression.type_arguments())?, - call_expression.arguments().format(formatter)?, - ]; + let formatted = vec![formatted![ + formatter, + [ + call_expression.optional_chain_token().format(), + call_expression.type_arguments().format(), + call_expression.arguments().format() + ] + ]?]; queue.push(FlattenItem::CallExpression(call_expression, formatted)); } @@ -335,10 +335,13 @@ fn flatten_call_expression( let static_member = JsStaticMemberExpression::cast(node).unwrap(); let object = static_member.object()?; flatten_call_expression(queue, object.syntax().clone(), formatter)?; - let formatted = vec![ - static_member.operator_token().format(formatter)?, - static_member.member().format(formatter)?, - ]; + let formatted = vec![formatted![ + formatter, + [ + static_member.operator_token().format(), + static_member.member().format(), + ] + ]?]; queue.push(FlattenItem::StaticMember(static_member, formatted)); } @@ -346,12 +349,15 @@ fn flatten_call_expression( let computed_expression = JsComputedMemberExpression::cast(node).unwrap(); let object = computed_expression.object()?; flatten_call_expression(queue, object.syntax().clone(), formatter)?; - let formatted = vec![ - formatted!(formatter, computed_expression.optional_chain_token())?, - computed_expression.l_brack_token().format(formatter)?, - computed_expression.member().format(formatter)?, - computed_expression.r_brack_token().format(formatter)?, - ]; + let formatted = vec![formatted!( + formatter, + [ + computed_expression.optional_chain_token().format(), + computed_expression.l_brack_token().format(), + computed_expression.member().format(), + computed_expression.r_brack_token().format(), + ] + )?]; queue.push(FlattenItem::ComputedExpression( computed_expression, @@ -360,7 +366,7 @@ fn flatten_call_expression( } _ => { - let formatted = node.format(formatter)?; + let formatted = formatted![formatter, [node.format()]]?; queue.push(FlattenItem::Node(node, formatted)); } } diff --git a/crates/rome_js_formatter/src/utils/mod.rs b/crates/rome_js_formatter/src/utils/mod.rs index ebbd2d18416f..3df66a78a30c 100644 --- a/crates/rome_js_formatter/src/utils/mod.rs +++ b/crates/rome_js_formatter/src/utils/mod.rs @@ -8,15 +8,11 @@ mod member_chain; #[cfg(test)] mod quickcheck_utils; -use crate::format_extensions::FormatOptional; -use crate::{ - empty_element, empty_line, hard_group_elements, space_token, token, Format, FormatElement, - Formatter, JsFormatter, QuoteStyle, Token, -}; +use crate::prelude::*; pub(crate) use binary_like_expression::{format_binary_like_expression, JsAnyBinaryLikeExpression}; pub(crate) use format_conditional::{format_conditional, Conditional}; pub(crate) use member_chain::format_call_expression; -use rome_formatter::{normalize_newlines, FormatResult}; +use rome_formatter::{normalize_newlines, QuoteStyle}; use rome_js_syntax::suppression::{has_suppressions_category, SuppressionCategory}; use rome_js_syntax::{ JsAnyExpression, JsAnyFunction, JsAnyStatement, JsInitializerClause, JsLanguage, @@ -53,8 +49,9 @@ pub(crate) fn format_initializer_clause( ) -> FormatResult { formatted![ formatter, - initializer - .with_or_empty(|initializer| { formatted![formatter, space_token(), initializer] }) + [initializer + .format() + .with_or_empty(|initializer| { formatted![formatter, [space_token(), initializer]] })] ] } @@ -64,10 +61,10 @@ pub(crate) fn format_interpreter( ) -> FormatResult { formatted![ formatter, - interpreter.with_or( - |interpreter| formatted![formatter, interpreter, empty_line()], + [interpreter.format().with_or( + |interpreter| formatted![formatter, [interpreter, empty_line()]], empty_element, - ) + )] ] } @@ -120,24 +117,18 @@ pub(crate) fn format_head_body_statement( if matches!(body, JsAnyStatement::JsBlockStatement(_)) { Ok(hard_group_elements(formatted![ formatter, - head, - space_token(), - body.format(formatter)?, + [head, space_token(), body.format(),] ]?)) } else if matches!(body, JsAnyStatement::JsEmptyStatement(_)) { // Force semicolon insertion if the body is empty formatted![ formatter, - hard_group_elements(head), - body.format(formatter)?, - token(";"), + [hard_group_elements(head), body.format(), token(";"),] ] } else { formatted![ formatter, - hard_group_elements(head), - space_token(), - body.format(formatter)?, + [hard_group_elements(head), space_token(), body.format(),] ] } } @@ -149,7 +140,7 @@ pub(crate) fn has_formatter_suppressions(node: &JsSyntaxNode) -> bool { /// This function consumes a list of modifiers and applies a predictable sorting. pub(crate) fn sort_modifiers_by_precedence(list: &List) -> Vec where - Node: AstNode + Clone, + Node: AstNode, List: AstNodeList, Modifiers: for<'a> From<&'a Node>, { @@ -205,7 +196,7 @@ impl TemplateElement { } = template_element.as_fields(); let dollar_curly_token = dollar_curly_token?; - let expression = expression.format(formatter)?; + let expression = formatted![formatter, [expression.format()]]?; let r_curly_token = r_curly_token?; (dollar_curly_token, expression, r_curly_token) @@ -218,7 +209,7 @@ impl TemplateElement { } = template_element.as_fields(); let dollar_curly_token = dollar_curly_token?; - let ty = ty.format(formatter)?; + let ty = formatted![formatter, [ty.format()]]?; let r_curly_token = r_curly_token?; (dollar_curly_token, ty, r_curly_token) @@ -228,9 +219,7 @@ impl TemplateElement { if should_hard_group { Ok(hard_group_elements(formatted![ formatter, - dollar_curly_token.format(formatter)?, - middle, - r_curly_token.format(formatter)? + [dollar_curly_token.format(), middle, r_curly_token.format()] ]?)) } else { formatter.format_delimited_soft_block_indent( @@ -378,12 +367,14 @@ pub(crate) fn format_with_semicolon( formatted![ formatter, - content, - semicolon.or_format(if is_unknown { - empty_element - } else { - || token(";") - }) + [ + content, + semicolon.format().or_format(if is_unknown { + empty_element + } else { + || token(";") + }) + ] ] } diff --git a/crates/rome_js_formatter/tests/check_reformat.rs b/crates/rome_js_formatter/tests/check_reformat.rs index 4924a95b87f1..4803cc7b3736 100644 --- a/crates/rome_js_formatter/tests/check_reformat.rs +++ b/crates/rome_js_formatter/tests/check_reformat.rs @@ -1,6 +1,7 @@ use rome_diagnostics::{file::SimpleFiles, termcolor, Emitter}; +use rome_formatter::FormatOptions; -use rome_js_formatter::{format_node, FormatOptions}; +use rome_js_formatter::format_node; use rome_js_parser::{parse, SourceType}; use rome_js_syntax::JsSyntaxNode; diff --git a/crates/rome_js_formatter/tests/prettier_tests.rs b/crates/rome_js_formatter/tests/prettier_tests.rs index d53db04506ac..a558eff8948d 100644 --- a/crates/rome_js_formatter/tests/prettier_tests.rs +++ b/crates/rome_js_formatter/tests/prettier_tests.rs @@ -13,7 +13,7 @@ use std::{ }; use rome_diagnostics::{file::SimpleFiles, termcolor, Emitter}; -use rome_js_formatter::{FormatOptions, IndentStyle}; +use rome_formatter::{FormatOptions, IndentStyle}; use rome_js_parser::{parse, SourceType}; use crate::check_reformat::CheckReformatParams; diff --git a/crates/rome_js_formatter/tests/spec_test.rs b/crates/rome_js_formatter/tests/spec_test.rs index f213ccd1acf0..5fb498233ad0 100644 --- a/crates/rome_js_formatter/tests/spec_test.rs +++ b/crates/rome_js_formatter/tests/spec_test.rs @@ -1,7 +1,8 @@ use rome_core::App; use rome_formatter::LineWidth; +use rome_formatter::{FormatOptions, IndentStyle, Printed, QuoteStyle}; use rome_fs::RomePath; -use rome_js_formatter::{format_node, FormatOptions, IndentStyle, Printed, QuoteStyle}; +use rome_js_formatter::format_node; use rome_js_parser::{parse, ModuleKind, SourceType}; use serde::{Deserialize, Serialize}; use std::fmt::Debug; diff --git a/crates/rome_lsp/Cargo.toml b/crates/rome_lsp/Cargo.toml index 01f209e32116..916036caf620 100644 --- a/crates/rome_lsp/Cargo.toml +++ b/crates/rome_lsp/Cargo.toml @@ -12,6 +12,7 @@ serde = { version = "1.0.133", features = ["derive"] } anyhow = "1.0.52" indexmap = "1.8.0" rome_js_formatter = { path = "../rome_js_formatter" } +rome_formatter = { path = "../rome_formatter" } rome_analyze = { path = "../rome_analyze" } rome_diagnostics = { path = "../rome_diagnostics" } rome_flags = { path = "../rome_flags" } diff --git a/crates/rome_lsp/src/handlers/formatting.rs b/crates/rome_lsp/src/handlers/formatting.rs index 14a7baa44b43..22c783b34c3a 100644 --- a/crates/rome_lsp/src/handlers/formatting.rs +++ b/crates/rome_lsp/src/handlers/formatting.rs @@ -2,7 +2,7 @@ use crate::config::{FormatterWorkspaceSettings, WorkspaceSettings}; use crate::line_index::{self, LineCol}; use anyhow::{bail, Result}; use rome_diagnostics::file::FileId; -use rome_js_formatter::{FormatOptions, IndentStyle, QuoteStyle}; +use rome_formatter::{FormatOptions, IndentStyle, QuoteStyle}; use rome_js_parser::{parse, SourceType}; use rome_js_syntax::{TextRange, TokenAtOffset}; use std::str::FromStr; diff --git a/rustfmt.toml b/rustfmt.toml index 4c46e8b5ec8b..43d4840c7995 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1 @@ -newline_style = "Unix" \ No newline at end of file +newline_style = "Unix" diff --git a/website/playground/Cargo.toml b/website/playground/Cargo.toml index bf851e2920d1..b208960ef962 100644 --- a/website/playground/Cargo.toml +++ b/website/playground/Cargo.toml @@ -11,6 +11,7 @@ crate-type = ["cdylib"] [dependencies] wasm-bindgen = "0.2.79" rome_js_formatter = { path = "../../crates/rome_js_formatter" } +rome_formatter = { path = "../../crates/rome_formatter" } rome_js_parser = { path = "../../crates/rome_js_parser", features = ["serde"] } rome_diagnostics = { path = "../../crates/rome_diagnostics" } rome_analyze = { path = "../../crates/rome_analyze" } diff --git a/website/playground/src/lib.rs b/website/playground/src/lib.rs index fcb24536c1d6..0b037783b090 100644 --- a/website/playground/src/lib.rs +++ b/website/playground/src/lib.rs @@ -8,7 +8,8 @@ use rome_console::markup; use rome_diagnostics::file::{Files, SimpleFiles}; use rome_diagnostics::termcolor::{ColorSpec, WriteColor}; use rome_diagnostics::{DiagnosticHeader, Emitter}; -use rome_js_formatter::{format_node, FormatOptions, IndentStyle}; +use rome_formatter::{FormatOptions, IndentStyle}; +use rome_js_formatter::format_node; use rome_js_parser::{parse, LanguageVariant, SourceType}; use serde_json::json; use std::io; diff --git a/xtask/bench/Cargo.toml b/xtask/bench/Cargo.toml index 7edea665e55e..1b1f5a7ec9c7 100644 --- a/xtask/bench/Cargo.toml +++ b/xtask/bench/Cargo.toml @@ -9,6 +9,7 @@ xtask = { path = '../', version = "0.0" } rome_js_syntax = { path = "../../crates/rome_js_syntax" } rome_js_parser = { path = "../../crates/rome_js_parser" } rome_diagnostics = { path = "../../crates/rome_diagnostics" } +rome_formatter = { path = "../../crates/rome_formatter"} rome_js_formatter = { path = "../../crates/rome_js_formatter"} rome_analyze = { path = "../../crates/rome_analyze"} diff --git a/xtask/bench/src/features/formatter.rs b/xtask/bench/src/features/formatter.rs index 85fe93512a8e..868d89cd292c 100644 --- a/xtask/bench/src/features/formatter.rs +++ b/xtask/bench/src/features/formatter.rs @@ -1,5 +1,6 @@ use crate::BenchmarkSummary; -use rome_js_formatter::{format_node, FormatOptions, Printed}; +use rome_formatter::{FormatOptions, Printed}; +use rome_js_formatter::format_node; use rome_js_syntax::JsSyntaxNode; use std::fmt::{Display, Formatter}; use std::time::Duration; diff --git a/xtask/codegen/src/formatter.rs b/xtask/codegen/src/formatter.rs index 8c3e12790849..b4be3609cd0f 100644 --- a/xtask/codegen/src/formatter.rs +++ b/xtask/codegen/src/formatter.rs @@ -242,7 +242,7 @@ pub fn generate_formatter() { // script to build the module import files let mut modules = ModuleIndex::new(project_root().join("crates/rome_js_formatter/src")); let mut format_impls = - FormatImpls::new(project_root().join("crates/rome_js_formatter/src/generated.rs")); + BoilerplateImpls::new(project_root().join("crates/rome_js_formatter/src/generated.rs")); // Build an unified iterator over all the AstNode types let names = ast @@ -279,8 +279,10 @@ pub fn generate_formatter() { let path = name_to_path(&kind, &name); modules.insert(&repo, &path); - let id = Ident::new(&name, Span::call_site()); - format_impls.push(&kind, &id); + let node_id = Ident::new(&name, Span::call_site()); + let format_id = Ident::new(&format!("Format{name}"), Span::call_site()); + + format_impls.push(&kind, &node_id, &format_id); // Union nodes except for AnyFunction and AnyClass have a generated // implementation, the codegen will always overwrite any existing file @@ -303,23 +305,37 @@ pub fn generate_formatter() { let tokens = match kind { NodeKind::List { separated: false } => quote! { use crate::prelude::*; - use rome_js_syntax::#id; + use crate::generated::#format_id; + use rome_js_syntax::#node_id; - impl Format for #id { - fn format(&self, formatter: &Formatter) -> FormatResult { - Ok(formatter.format_list(self.clone())) + impl FormatRule<#node_id> for #format_id { + fn format(node: &#node_id, formatter: &Formatter) -> FormatResult { + Ok(formatter.format_list(node)) } } }, - NodeKind::Node | NodeKind::List { separated: true } => { + NodeKind::List { .. } => quote! { + use crate::prelude::*; + use crate::formatter::verbatim_node; + use crate::generated::#format_id; + use rome_js_syntax::#node_id; + + impl FormatRule<#node_id> for #format_id { + fn format(node: &#node_id, formatter: &Formatter) -> FormatResult { + verbatim_node(node.syntax()).format(formatter) + } + } + }, + NodeKind::Node => { quote! { use crate::prelude::*; + use crate::{formatter::verbatim_node, FormatNodeFields}; use rome_rowan::AstNode; - use rome_js_syntax::{#id}; + use rome_js_syntax::#node_id; - impl FormatNode for #id { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - verbatim_node(self.syntax()).format(formatter) + impl FormatNodeFields<#node_id> for FormatNodeRule<#node_id> { + fn format_fields(node: &#node_id, formatter: &Formatter) -> FormatResult { + verbatim_node(node.syntax()).format(formatter) } } } @@ -327,12 +343,13 @@ pub fn generate_formatter() { NodeKind::Unknown => { quote! { use crate::prelude::*; + use crate::{FormatNodeFields, formatter::unknown_node}; use rome_rowan::AstNode; - use rome_js_syntax::{#id}; + use rome_js_syntax::#node_id; - impl FormatNode for #id { - fn format_fields(&self, formatter: &Formatter) -> FormatResult { - unknown_node(self.syntax()).format(formatter) + impl FormatNodeFields<#node_id> for FormatNodeRule<#node_id> { + fn format_fields(node: &#node_id, formatter: &Formatter) -> FormatResult { + unknown_node(node.syntax()).format(formatter) } } } @@ -343,17 +360,18 @@ pub fn generate_formatter() { .into_iter() .map(|variant| { let variant = Ident::new(&variant, Span::call_site()); - quote! { Self::#variant(node) => node.format(formatter), } + quote! { #node_id::#variant(node) => formatted![formatter, [node.format()]], } }) .collect(); quote! { use crate::prelude::*; - use rome_js_syntax::#id; + use crate::generated::#format_id; + use rome_js_syntax::#node_id; - impl Format for #id { - fn format(&self, formatter: &Formatter) -> FormatResult { - match self { + impl FormatRule<#node_id> for #format_id { + fn format(node: &#node_id, formatter: &Formatter) -> FormatResult { + match node { #( #match_arms )* } } @@ -381,12 +399,12 @@ pub fn generate_formatter() { repo.stage_paths(&stage); } -struct FormatImpls { +struct BoilerplateImpls { path: PathBuf, impls: Vec, } -impl FormatImpls { +impl BoilerplateImpls { fn new(file_name: PathBuf) -> Self { Self { path: file_name, @@ -394,15 +412,48 @@ impl FormatImpls { } } - fn push(&mut self, kind: &NodeKind, id: &Ident) { - if matches!(kind, NodeKind::Node | NodeKind::Unknown) { - self.impls.push(quote! { - impl Format for rome_js_syntax::#id { - fn format(&self, formatter: &Formatter) -> FormatResult { - self.format_node(formatter) + fn push(&mut self, kind: &NodeKind, node_id: &Ident, format_id: &Ident) { + match kind { + NodeKind::Node | NodeKind::Unknown => { + self.impls.push(quote! { + impl<'a> AsFormat<'a> for rome_js_syntax::#node_id { + type Format = FormatRefWithRule<'a, rome_js_syntax::#node_id, FormatNodeRule>; + + fn format(&'a self) -> Self::Format { + FormatRefWithRule::new(self) + } } - } - }); + + impl IntoFormat for rome_js_syntax::#node_id { + type Format = FormatOwnedWithRule>; + + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new(self) + } + } + }); + } + _ => { + self.impls.push(quote! { + pub struct #format_id; + + impl<'a> AsFormat<'a> for rome_js_syntax::#node_id { + type Format = FormatRefWithRule<'a, rome_js_syntax::#node_id, #format_id>; + + fn format(&'a self) -> Self::Format { + FormatRefWithRule::new(self) + } + } + + impl IntoFormat for rome_js_syntax::#node_id { + type Format = FormatOwnedWithRule; + + fn into_format(self) -> Self::Format { + FormatOwnedWithRule::new(self) + } + } + }); + } } } @@ -410,7 +461,8 @@ impl FormatImpls { let impls = self.impls; let tokens = quote! { - use crate::prelude::*; + use rome_formatter::{FormatRefWithRule, FormatOwnedWithRule}; + use crate::{AsFormat, IntoFormat, FormatNodeRule}; #( #impls )* };