This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rome_js_formatter): Move node formatting into its own trait
Today, the formatting that must happen for each JS node happens inside `Formatter.format_syntax_node` and the `formatter_traits`. This PR moves the common logic applied by all nodes and tokens into the `ToFormatElement` implementation and renames it to `Format`. * Rename `ToFormatElement` to `Format` and `to_format_element` to `format` * Implement `Format` for `JsSyntaxToken`. CSS, JSON etc. can implement their own generic token formatting logic * Introduce a new `FormatNode` trait (language specific) that implements the formatting of a node and calls into `format_fields` that is implemented for each field. * Make the `FormatterTraits` node and language independent. Rename to `FormatTraits`. `Format`, `FormatterTraits`, `FormatResult`, and `FormatError` are now all language independent. However, some still depend on the `Formatter`. The next step is to move many of the `Formatter`'s helper function out of the Formatter so that it becomes language independent.
- Loading branch information
1 parent
1e5378a
commit ce5b9c0
Showing
403 changed files
with
3,423 additions
and
1,988 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use crate::{Format, FormatElement, FormatResult, Formatter}; | ||
use rome_js_syntax::{map_syntax_node, JsSyntaxNode}; | ||
|
||
impl ToFormatElement for JsSyntaxNode { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
map_syntax_node!(self.clone(), node => node.to_format_element(formatter)) | ||
impl Format for JsSyntaxNode { | ||
fn format(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
map_syntax_node!(self.clone(), node => node.format(formatter)) | ||
} | ||
} |
Oops, something went wrong.