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

Commit

Permalink
Rename ArrowExpr to JsArrowFunctionExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Nov 15, 2021
1 parent fe4302e commit c64a86e
Show file tree
Hide file tree
Showing 21 changed files with 374 additions and 364 deletions.
28 changes: 15 additions & 13 deletions crates/rome_formatter/src/cst.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::{FormatElement, FormatResult, Formatter, ToFormatElement};
use rslint_parser::ast::{
ArgList, ArrayPattern, ArrowExpr, AssignPattern, CallExpr, ClassBody, ClassDecl, ClassProp,
Condition, ConstructorParameters, ForInStmt, ForStmt, ForStmtInit, ForStmtTest, ForStmtUpdate,
Getter, IdentProp, JsArrayExpression, JsBlockStatement, JsBooleanLiteral, JsCaseClause,
JsCatchClause, JsContinueStatement, JsDebuggerStatement, JsDefaultClause, JsDoWhileStatement,
JsEmptyStatement, JsExpressionStatement, JsFinallyClause, JsFunctionDeclaration, JsIfStatement,
JsLabeledStatement, JsNullLiteral, JsNumberLiteral, JsParameterList,
JsReferenceIdentifierExpression, JsReturnStatement, JsRoot, JsSequenceExpression,
JsStringLiteral, JsSwitchStatement, JsTryStatement, JsVariableDeclarationStatement,
JsVariableDeclarator, JsWhileStatement, JsWithStatement, LiteralProp, Name, ObjectExpr, Setter,
SinglePattern,
ArgList, ArrayPattern, AssignPattern, CallExpr, ClassBody, ClassDecl, ClassProp, Condition,
ConstructorParameters, ForInStmt, ForStmt, ForStmtInit, ForStmtTest, ForStmtUpdate, Getter,
IdentProp, JsArrayExpression, JsArrowFunctionExpression, JsBlockStatement, JsBooleanLiteral,
JsCaseClause, JsCatchClause, JsContinueStatement, JsDebuggerStatement, JsDefaultClause,
JsDoWhileStatement, JsEmptyStatement, JsExpressionStatement, JsFinallyClause,
JsFunctionDeclaration, JsIfStatement, JsLabeledStatement, JsNullLiteral, JsNumberLiteral,
JsParameterList, JsReferenceIdentifierExpression, JsReturnStatement, JsRoot,
JsSequenceExpression, JsStringLiteral, JsSwitchStatement, JsTryStatement,
JsVariableDeclarationStatement, JsVariableDeclarator, JsWhileStatement, JsWithStatement,
LiteralProp, Name, ObjectExpr, Setter, SinglePattern,
};
use rslint_parser::{AstNode, SyntaxKind, SyntaxNode};

Expand All @@ -19,9 +19,11 @@ impl ToFormatElement for SyntaxNode {
SyntaxKind::JS_ARRAY_EXPRESSION => JsArrayExpression::cast(self.clone())
.unwrap()
.to_format_element(formatter),
SyntaxKind::ARROW_EXPR => ArrowExpr::cast(self.clone())
.unwrap()
.to_format_element(formatter),
SyntaxKind::JS_ARROW_FUNCTION_EXPRESSION => {
JsArrowFunctionExpression::cast(self.clone())
.unwrap()
.to_format_element(formatter)
}
SyntaxKind::ASSIGN_PATTERN => AssignPattern::cast(self.clone())
.unwrap()
.to_format_element(formatter),
Expand Down
11 changes: 0 additions & 11 deletions crates/rome_formatter/src/ts/expr_or_block.rs

This file was deleted.

21 changes: 16 additions & 5 deletions crates/rome_formatter/src/ts/expressions/arrow_expr.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use rslint_parser::ast::{ArrowExpr, ArrowExprParams};
use rslint_parser::ast::{
JsAnyArrowFunctionBody, JsAnyArrowFunctionParameters, JsArrowFunctionExpression,
};

use crate::{
concat_elements, format_elements, space_token, token, FormatElement, FormatResult, Formatter,
ToFormatElement,
};

impl ToFormatElement for ArrowExpr {
impl ToFormatElement for JsArrowFunctionExpression {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
let mut tokens: Vec<FormatElement> = vec![];

Expand All @@ -16,14 +18,14 @@ impl ToFormatElement for ArrowExpr {
));
}

if let Some(params) = self.params() {
if let Some(params) = self.parameter_list() {
match params {
ArrowExprParams::Name(name) => {
JsAnyArrowFunctionParameters::JsIdentifierBinding(name) => {
tokens.push(token("("));
tokens.push(formatter.format_node(name)?);
tokens.push(token(")"));
}
ArrowExprParams::JsParameterList(params) => {
JsAnyArrowFunctionParameters::JsParameterList(params) => {
tokens.push(formatter.format_node(params)?)
}
}
Expand All @@ -39,3 +41,12 @@ impl ToFormatElement for ArrowExpr {
Ok(concat_elements(tokens))
}
}

impl ToFormatElement for JsAnyArrowFunctionBody {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
match self {
JsAnyArrowFunctionBody::JsFunctionBody(body) => body.to_format_element(formatter),
JsAnyArrowFunctionBody::JsAnyExpression(expr) => expr.to_format_element(formatter),
}
}
}
2 changes: 1 addition & 1 deletion crates/rome_formatter/src/ts/expressions/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rslint_parser::ast::JsAnyExpression;
impl ToFormatElement for JsAnyExpression {
fn to_format_element(&self, formatter: &Formatter) -> FormatResult<FormatElement> {
match self {
JsAnyExpression::ArrowExpr(arrow) => arrow.to_format_element(formatter),
JsAnyExpression::JsArrowFunctionExpression(arrow) => arrow.to_format_element(formatter),
JsAnyExpression::JsAnyLiteral(literal) => literal.to_format_element(formatter),
JsAnyExpression::Template(_) => todo!(),
JsAnyExpression::JsReferenceIdentifierExpression(name_ref) => {
Expand Down
3 changes: 1 addition & 2 deletions crates/rome_formatter/src/ts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod any_js_array_element;
mod arg_list;
mod auxiliary;
mod bindings;
mod class;
mod condition;
mod declarators;
mod expr_or_block;
mod expressions;
mod getter;
mod ident;
Expand All @@ -17,7 +17,6 @@ mod script;
mod setter;
mod spread;
mod statements;
mod bindings;

#[cfg(test)]
mod test {
Expand Down
6 changes: 3 additions & 3 deletions crates/rslint_parser/src/ast/expr_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ impl JsStringLiteral {
}
}

impl ArrowExpr {
pub fn body(&self) -> Option<ExprOrBlock> {
ExprOrBlock::cast(self.syntax().children().last()?)
impl JsArrowFunctionExpression {
pub fn body(&self) -> Option<JsAnyArrowFunctionBody> {
JsAnyArrowFunctionBody::cast(self.syntax().children().last()?)
}
}

Expand Down
Loading

0 comments on commit c64a86e

Please sign in to comment.