forked from rome/tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rome_formatter): tag_expression (rome#2262)
the simplest tag_expression (that is not self closing) to format is the smallest possible tree that needs no formatting. for example `<a></a>`.
- Loading branch information
1 parent
76e74c9
commit 8fd9d42
Showing
9 changed files
with
83 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::{AstNode, JsxName}; | ||
use crate::{ | ||
formatter_traits::FormatTokenAndNode, FormatElement, FormatResult, Formatter, ToFormatElement, | ||
}; | ||
use rome_js_syntax::{AstNode, JsxName, JsxNameFields}; | ||
impl ToFormatElement for JsxName { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
Ok(formatter.format_verbatim(self.syntax())) | ||
let JsxNameFields { value_token } = self.as_fields(); | ||
|
||
value_token.format(formatter) | ||
} | ||
} |
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,7 +1,8 @@ | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::{AstNode, JsxTagExpression}; | ||
use crate::{format_elements, token, FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::{AstNode, JsxTagExpression, JsxTagExpressionFields}; | ||
impl ToFormatElement for JsxTagExpression { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
Ok(formatter.format_verbatim(self.syntax())) | ||
let JsxTagExpressionFields { tag } = self.as_fields(); | ||
Ok(tag?.to_format_element(formatter)?) | ||
} | ||
} |
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,7 +1,22 @@ | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::{AstNode, JsxClosingElement}; | ||
use crate::{ | ||
format_elements, formatter_traits::FormatTokenAndNode, FormatElement, FormatResult, Formatter, | ||
ToFormatElement, | ||
}; | ||
use rome_js_syntax::{AstNode, JsxClosingElement, JsxClosingElementFields}; | ||
impl ToFormatElement for JsxClosingElement { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
Ok(formatter.format_verbatim(self.syntax())) | ||
let JsxClosingElementFields { | ||
l_angle_token, | ||
slash_token, | ||
name, | ||
r_angle_token, | ||
} = self.as_fields(); | ||
|
||
Ok(format_elements![ | ||
l_angle_token.format(formatter)?, | ||
slash_token.format(formatter)?, | ||
name?.to_format_element(formatter)?, | ||
r_angle_token.format(formatter)? | ||
]) | ||
} | ||
} |
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,7 +1,17 @@ | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::{AstNode, JsxElement}; | ||
use crate::{format_elements, token, FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::{AstNode, JsxElement, JsxElementFields}; | ||
impl ToFormatElement for JsxElement { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
Ok(formatter.format_verbatim(self.syntax())) | ||
let JsxElementFields { | ||
opening_element, | ||
children, | ||
closing_element, | ||
} = self.as_fields(); | ||
|
||
Ok(format_elements![ | ||
opening_element?.to_format_element(formatter)?, | ||
formatter.format_list(children), | ||
closing_element?.to_format_element(formatter)? | ||
]) | ||
} | ||
} |
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,7 +1,22 @@ | ||
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement}; | ||
use rome_js_syntax::{AstNode, JsxOpeningElement}; | ||
use crate::{ | ||
format_elements, formatter_traits::FormatTokenAndNode, FormatElement, FormatResult, Formatter, | ||
ToFormatElement, | ||
}; | ||
use rome_js_syntax::{AstNode, JsxOpeningElement, JsxOpeningElementFields}; | ||
impl ToFormatElement for JsxOpeningElement { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
Ok(formatter.format_verbatim(self.syntax())) | ||
let JsxOpeningElementFields { | ||
l_angle_token, | ||
name, | ||
attributes, | ||
r_angle_token, | ||
} = self.as_fields(); | ||
|
||
Ok(format_elements![ | ||
l_angle_token.format(formatter)?, | ||
name?.to_format_element(formatter)?, | ||
formatter.format_list(attributes), | ||
r_angle_token.format(formatter)? | ||
]) | ||
} | ||
} |
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
1 change: 1 addition & 0 deletions
1
crates/rome_formatter/tests/specs/jsx/expressions/tag_expression.jsx
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<a></a> |
17 changes: 17 additions & 0 deletions
17
crates/rome_formatter/tests/specs/jsx/expressions/tag_expression.jsx.snap.new
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
source: crates/rome_formatter/tests/spec_test.rs | ||
assertion_line: 197 | ||
expression: tag_expression.jsx | ||
|
||
--- | ||
# Input | ||
<a></a> | ||
============================= | ||
# Outputs | ||
## Output 1 | ||
----- | ||
Indent style: Tab | ||
Line width: 80 | ||
----- | ||
<a></a>; | ||
|
8fd9d42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.