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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rslint_parser): Update while loops to match new AST Facade (#…
…1774) Changes the js grammar to match our new AST facade as defined in #1725 (and proposed in #1719) * `Continue` Statement * Rename from `ContinueStmt` to `JsContinueStatement` * Inline the label identifier (It's not a normal "variable" reference but a label reference) * `Break` Statement * Rename from `BreakStmt` to `JsBreakStatement` * Inline the label identifier (It's not a normal "variable" reference but a label reference) * `While` Statement * Rename from `WhileStmt` to `JsWhileStatement` * Rename `cons` to `body` * Inline the condition and rename `condition` to `test` * `DoWhileStatement` * Rename to `JsDoWhileStatement` * Inline condition * rename `cons` to `body` * rename `condition` to `test`
- Loading branch information
1 parent
93bbf01
commit 10a557e
Showing
20 changed files
with
434 additions
and
286 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
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.