From 7d64b9682584e6ad17808694cf09b7dba2f62285 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Fri, 17 Oct 2025 23:34:17 +0000 Subject: [PATCH] fix(formatter): should wrap parentheses with JSX arguments of `NewExpression` (#14717) Another weird case in Prettier, it only needs to wrap for NewExpression, why is CallexExpression excluded? --- crates/oxc_formatter/src/utils/jsx.rs | 4 +++- .../tests/fixtures/js/jsx/new-expression.jsx | 6 ++++++ .../tests/fixtures/js/jsx/new-expression.jsx.snap | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 crates/oxc_formatter/tests/fixtures/js/jsx/new-expression.jsx create mode 100644 crates/oxc_formatter/tests/fixtures/js/jsx/new-expression.jsx.snap diff --git a/crates/oxc_formatter/src/utils/jsx.rs b/crates/oxc_formatter/src/utils/jsx.rs index 97e9953dfbec7..16b64d40ffcfd 100644 --- a/crates/oxc_formatter/src/utils/jsx.rs +++ b/crates/oxc_formatter/src/utils/jsx.rs @@ -78,7 +78,6 @@ pub fn get_wrap_state(parent: &AstNodes<'_>) -> WrapState { AstNodes::ArrayExpression(_) | AstNodes::JSXAttribute(_) | AstNodes::JSXExpressionContainer(_) - | AstNodes::Argument(_) | AstNodes::ConditionalExpression(_) => WrapState::NoWrap, AstNodes::StaticMemberExpression(member) => { if member.optional { @@ -87,6 +86,9 @@ pub fn get_wrap_state(parent: &AstNodes<'_>) -> WrapState { WrapState::WrapOnBreak } } + AstNodes::Argument(argument) if matches!(argument.parent, AstNodes::CallExpression(_)) => { + WrapState::NoWrap + } AstNodes::ExpressionStatement(stmt) => { // `() =>
` // ^^^^^^^^^^^ diff --git a/crates/oxc_formatter/tests/fixtures/js/jsx/new-expression.jsx b/crates/oxc_formatter/tests/fixtures/js/jsx/new-expression.jsx new file mode 100644 index 0000000000000..d42de0e09520d --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/jsx/new-expression.jsx @@ -0,0 +1,6 @@ +return new ImageResponse( + ( +