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

Commit

Permalink
chore: support in expression
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioduarte committed Nov 27, 2022
1 parent fd8f47c commit 9d31756
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rome_diagnostics::Applicability;
use rome_js_factory::{make, syntax::T};
use rome_js_syntax::{
JsAnyExpression, JsBinaryOperator, JsCallExpression, JsClassDeclaration, JsClassExpression,
JsExtendsClause, OperatorPrecedence,
JsExtendsClause, JsInExpression, OperatorPrecedence,
};
use rome_rowan::{AstNode, AstSeparatedList, BatchMutationExt};

Expand Down Expand Up @@ -268,8 +268,16 @@ fn does_expression_need_parens(
// Skips already parenthesized expressions
JsAnyExpression::JsParenthesizedExpression(_) => return None,
JsAnyExpression::JsBinaryExpression(bin_expr) => {
if bin_expr.parent::<JsInExpression>().is_some() {
return Some(true);
}

let binding = bin_expr.right().ok()?;
let call_expr = binding.as_js_call_expression();

bin_expr.operator().ok()? != JsBinaryOperator::Exponent
|| bin_expr.right().ok()?.as_js_call_expression()? != node
|| call_expr.is_none()
|| call_expr? != node
}
JsAnyExpression::JsCallExpression(call_expr) => !call_expr
.arguments()
Expand Down Expand Up @@ -297,8 +305,12 @@ fn does_expression_need_parens(
})
.any(|arg| &arg == node),
JsAnyExpression::JsComputedMemberExpression(member_expr) => {
member_expr.member().ok()?.as_js_call_expression()? != node
let binding = member_expr.member().ok()?;
let call_expr = binding.as_js_call_expression();

call_expr.is_none() || call_expr? != node
}
JsAnyExpression::JsInExpression(_) => return Some(true),
JsAnyExpression::JsClassExpression(_)
| JsAnyExpression::JsStaticMemberExpression(_)
| JsAnyExpression::JsUnaryExpression(_)
Expand Down

0 comments on commit 9d31756

Please sign in to comment.