Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
Update for (...) ast structure
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Dec 23, 2021
1 parent 6b481c5 commit 4fd4e7c
Show file tree
Hide file tree
Showing 13 changed files with 364 additions and 557 deletions.
24 changes: 9 additions & 15 deletions crates/rome_formatter/src/cst.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement};
use rslint_parser::ast::{
CallExpr, ForStmt, ForStmtTest, ForStmtUpdate, JsArrayBindingPattern, JsArrayExpression,
JsArrowFunctionExpression, JsBlockStatement, JsBooleanLiteralExpression, JsCallArguments,
JsCaseClause, JsCatchClause, JsClassDeclaration, JsConstructorParameters, JsContinueStatement,
JsDebuggerStatement, JsDefaultClause, JsDoWhileStatement, JsEmptyStatement,
JsExpressionStatement, JsFinallyClause, JsForInStatement, JsFunctionDeclaration,
JsGetterClassMember, JsIdentifierBinding, JsIdentifierExpression, JsIfStatement,
JsLabeledStatement, JsNullLiteralExpression, JsNumberLiteralExpression, JsObjectExpression,
JsParameters, JsPropertyClassMember, JsPropertyObjectMember, JsReturnStatement, JsScript,
CallExpr, JsArrayBindingPattern, JsArrayExpression, JsArrowFunctionExpression,
JsBlockStatement, JsBooleanLiteralExpression, JsCallArguments, JsCaseClause, JsCatchClause,
JsClassDeclaration, JsConstructorParameters, JsContinueStatement, JsDebuggerStatement,
JsDefaultClause, JsDoWhileStatement, JsEmptyStatement, JsExpressionStatement, JsFinallyClause,
JsForInStatement, JsForStatement, JsFunctionDeclaration, JsGetterClassMember,
JsIdentifierBinding, JsIdentifierExpression, JsIfStatement, JsLabeledStatement,
JsNullLiteralExpression, JsNumberLiteralExpression, JsObjectExpression, JsParameters,
JsPropertyClassMember, JsPropertyObjectMember, JsReturnStatement, JsScript,
JsSequenceExpression, JsSetterClassMember, JsShorthandPropertyObjectMember, JsSpread,
JsStringLiteralExpression, JsSwitchStatement, JsTryStatement, JsVariableDeclaration,
JsVariableStatement, JsWhileStatement, JsWithStatement,
Expand Down Expand Up @@ -82,13 +82,7 @@ impl ToFormatElement for SyntaxNode {
JsSyntaxKind::JS_IF_STATEMENT => JsIfStatement::cast(self.clone())
.unwrap()
.to_format_element(formatter),
JsSyntaxKind::FOR_STMT => ForStmt::cast(self.clone())
.unwrap()
.to_format_element(formatter),
JsSyntaxKind::FOR_STMT_TEST => ForStmtTest::cast(self.clone())
.unwrap()
.to_format_element(formatter),
JsSyntaxKind::FOR_STMT_UPDATE => ForStmtUpdate::cast(self.clone())
JsSyntaxKind::JS_FOR_STATEMENT => JsForStatement::cast(self.clone())
.unwrap()
.to_format_element(formatter),
JsSyntaxKind::JS_EMPTY_STATEMENT => JsEmptyStatement::cast(self.clone())
Expand Down
18 changes: 3 additions & 15 deletions crates/rome_formatter/src/ts/statements/for_stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::{
concat_elements, format_elements, group_elements, soft_indent, soft_line_break_or_space,
space_token, FormatElement, FormatResult, Formatter, ToFormatElement,
};
use rslint_parser::ast::{ForStmt, ForStmtTest, ForStmtUpdate, JsAnyForInitializer};
use rslint_parser::ast::{JsAnyForInitializer, JsForStatement};

impl ToFormatElement for ForStmt {
impl ToFormatElement for JsForStatement {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
let inner =
if self.initializer().is_some() || self.test().is_some() || self.update().is_some() {
Expand Down Expand Up @@ -42,7 +42,7 @@ impl ToFormatElement for ForStmt {
group_elements(soft_indent(inner)),
formatter.format_token(&self.r_paren_token()?)?,
space_token(),
formatter.format_node(self.cons()?)?
formatter.format_node(self.body()?)?
]))
}
}
Expand All @@ -55,15 +55,3 @@ impl ToFormatElement for JsAnyForInitializer {
}
}
}

impl ToFormatElement for ForStmtTest {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
formatter.format_node(self.expr()?)
}
}

impl ToFormatElement for ForStmtUpdate {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
formatter.format_node(self.expr()?)
}
}
2 changes: 1 addition & 1 deletion crates/rome_formatter/src/ts/statements/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl ToFormatElement for JsAnyStatement {
JsAnyStatement::JsWhileStatement(while_statement) => {
while_statement.to_format_element(formatter)
}
JsAnyStatement::ForStmt(for_stmt) => for_stmt.to_format_element(formatter),
JsAnyStatement::JsForStatement(for_stmt) => for_stmt.to_format_element(formatter),
JsAnyStatement::JsForInStatement(for_in_statement) => {
for_in_statement.to_format_element(formatter)
}
Expand Down
Loading

0 comments on commit 4fd4e7c

Please sign in to comment.