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 660
refactor(rslint_parser): Update while loops to match new AST Facade #1774
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 11 additions & 11 deletions
22
crates/rome_formatter/src/ts/statements/break_statement.rs
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,21 +1,21 @@ | ||
use crate::{ | ||
empty_element, format_elements, group_elements, space_token, token, FormatElement, | ||
FormatResult, Formatter, ToFormatElement, | ||
empty_element, format_elements, space_token, token, FormatElement, FormatResult, Formatter, | ||
ToFormatElement, | ||
}; | ||
use rslint_parser::ast::BreakStmt; | ||
use rslint_parser::ast::JsBreakStatement; | ||
|
||
impl ToFormatElement for BreakStmt { | ||
impl ToFormatElement for JsBreakStatement { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
let break_element = formatter.format_token(&self.break_token()?)?; | ||
let ident = if let Some(ident_token) = self.ident_token() { | ||
group_elements(format_elements![ | ||
space_token(), | ||
formatter.format_token(&ident_token)? | ||
]) | ||
let label = if let Some(label_token) = self.label_token() { | ||
format_elements![space_token(), formatter.format_token(&label_token)?] | ||
} else { | ||
empty_element() | ||
}; | ||
|
||
Ok(format_elements![break_element, ident, token(";")]) | ||
Ok(format_elements![ | ||
formatter.format_token(&self.break_token()?)?, | ||
label, | ||
token(";") | ||
]) | ||
} | ||
} |
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
25 changes: 12 additions & 13 deletions
25
crates/rome_formatter/src/ts/statements/do_while_statement.rs
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
21 changes: 11 additions & 10 deletions
21
crates/rome_formatter/src/ts/statements/while_statement.rs
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,20 +1,21 @@ | ||
use crate::{ | ||
format_elements, space_token, FormatElement, FormatResult, Formatter, ToFormatElement, | ||
format_elements, group_elements, soft_indent, space_token, FormatElement, FormatResult, | ||
Formatter, ToFormatElement, | ||
}; | ||
use rslint_parser::ast::WhileStmt; | ||
use rslint_parser::ast::JsWhileStatement; | ||
|
||
impl ToFormatElement for WhileStmt { | ||
impl ToFormatElement for JsWhileStatement { | ||
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> { | ||
let while_token = formatter.format_token(&self.while_token()?)?; | ||
let condition = formatter.format_node(self.condition()?)?; | ||
let cons = formatter.format_node(self.cons()?)?; | ||
|
||
Ok(format_elements![ | ||
while_token, | ||
formatter.format_token(&self.while_token()?)?, | ||
space_token(), | ||
condition, | ||
group_elements(format_elements![ | ||
formatter.format_token(&self.l_paren_token()?)?, | ||
soft_indent(formatter.format_node(self.test()?)?), | ||
formatter.format_token(&self.r_paren_token()?)? | ||
]), | ||
space_token(), | ||
cons | ||
formatter.format_node(self.body()?)? | ||
]) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The group here didn't had any effect. Groups only change the output if they contain any
soft
indent/space/line breaks.