diff --git a/crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs b/crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs index 34abf4c96726..468bcdf6f1d5 100644 --- a/crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs +++ b/crates/rome_js_analyze/src/analyzers/nursery/use_exponentiation_operator.rs @@ -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}; @@ -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::().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() @@ -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(_)