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

Commit

Permalink
Rename ForStmt, CallExpr and NewExpr (#1886)
Browse files Browse the repository at this point in the history
Renames and restructures 

* `ForStmt`
* `CallExpr`
* `NewExpr`
  • Loading branch information
MichaReiser authored Jan 4, 2022
1 parent 651d418 commit 4a87d4f
Show file tree
Hide file tree
Showing 44 changed files with 656 additions and 830 deletions.
26 changes: 10 additions & 16 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,
JsArrayBindingPattern, JsArrayExpression, JsArrowFunctionExpression, JsBlockStatement,
JsBooleanLiteralExpression, JsCallArguments, JsCallExpression, 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 Expand Up @@ -144,7 +138,7 @@ impl ToFormatElement for SyntaxNode {
JsSyntaxKind::JS_ARRAY_BINDING_PATTERN => JsArrayBindingPattern::cast(self.clone())
.unwrap()
.to_format_element(formatter),
JsSyntaxKind::CALL_EXPR => CallExpr::cast(self.clone())
JsSyntaxKind::JS_CALL_EXPRESSION => JsCallExpression::cast(self.clone())
.unwrap()
.to_format_element(formatter),
JsSyntaxKind::JS_CALL_ARGUMENTS => JsCallArguments::cast(self.clone())
Expand Down
4 changes: 2 additions & 2 deletions crates/rome_formatter/src/ts/expressions/call_expression.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{format_elements, FormatElement, FormatResult, Formatter, ToFormatElement};
use rslint_parser::ast::CallExpr;
use rslint_parser::ast::JsCallExpression;

impl ToFormatElement for CallExpr {
impl ToFormatElement for JsCallExpression {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
let name = formatter.format_node(self.callee()?)?;
let arguments = formatter.format_node(self.arguments()?)?;
Expand Down
12 changes: 6 additions & 6 deletions crates/rome_formatter/src/ts/expressions/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{
};
use rslint_parser::ast::{
JsAnyExpression, JsAssignmentExpression, JsAwaitExpression, JsBinaryExpression,
JsComputedMemberExpression, JsConditionalExpression, JsLogicalExpression,
JsComputedMemberExpression, JsConditionalExpression, JsLogicalExpression, JsNewExpression,
JsParenthesizedExpression, JsThisExpression, JsUnaryExpression, JsYieldArgument,
JsYieldExpression, NewExpr, NewTarget,
JsYieldExpression, NewTarget,
};
use rslint_parser::{token_set, TokenSet, T};

Expand Down Expand Up @@ -39,8 +39,8 @@ impl ToFormatElement for JsAnyExpression {
JsAnyExpression::JsStaticMemberExpression(static_member_expression) => {
static_member_expression.to_format_element(formatter)
}
JsAnyExpression::NewExpr(new_expr) => new_expr.to_format_element(formatter),
JsAnyExpression::CallExpr(call_expression) => {
JsAnyExpression::JsNewExpression(new_expr) => new_expr.to_format_element(formatter),
JsAnyExpression::JsCallExpression(call_expression) => {
call_expression.to_format_element(formatter)
}
JsAnyExpression::JsUnaryExpression(unary_expression) => {
Expand Down Expand Up @@ -125,7 +125,7 @@ impl ToFormatElement for JsComputedMemberExpression {
}
}

impl ToFormatElement for NewExpr {
impl ToFormatElement for JsNewExpression {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
let arguments = if let Some(arguments) = self.arguments() {
formatter.format_node(arguments)?
Expand All @@ -137,7 +137,7 @@ impl ToFormatElement for NewExpr {
formatter.format_token(&self.new_token()?)?,
// TODO handle TsTypeArgs
space_token(),
formatter.format_node(self.object()?)?,
formatter.format_node(self.callee()?)?,
arguments,
])
}
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
9 changes: 0 additions & 9 deletions crates/rslint_parser/src/ast/expr_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,6 @@ impl Template {
}
}

impl CallExpr {
pub fn opt_chain_token(&self) -> Option<SyntaxToken> {
self.syntax()
.children_with_tokens()
.filter_map(|child| child.into_token())
.find(|tok| tok.kind() == QUESTIONDOT)
}
}

/// A simple macro for making assign, binop, or unary operators
#[macro_export]
macro_rules! op {
Expand Down
Loading

0 comments on commit 4a87d4f

Please sign in to comment.