Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions crates/oxc_formatter/src/write/call_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ pub fn arguments_grouped_layout(
let second_can_group_fn = || second_can_group;

// Check if we should group the last argument (second)
if should_group_last_argument_impl(Some(first), second, second_can_group_fn, f) {
if should_group_last_argument_impl(2, Some(first), second, second_can_group_fn, f) {
return Some(GroupedCallArgumentLayout::GroupedLastArgument);
}

Expand Down Expand Up @@ -344,6 +344,7 @@ fn should_group_first_argument(
/// Takes the penultimate argument as an Expression for the 2-argument case,
/// or extracts it from the arguments array for other cases.
fn should_group_last_argument_impl(
args_len: usize,
penultimate: Option<&Expression>,
last: &Expression,
last_can_group_fn: impl FnOnce() -> bool,
Expand Down Expand Up @@ -396,7 +397,8 @@ fn should_group_last_argument_impl(
match last {
Expression::ArrayExpression(array) if penultimate.is_some() => {
// Not for `useEffect`
if matches!(penultimate, Some(Expression::ArrowFunctionExpression(_))) {
if args_len == 2 && matches!(penultimate, Some(Expression::ArrowFunctionExpression(_)))
{
return false;
}

Expand All @@ -415,7 +417,7 @@ fn should_group_last_argument(args: &[Argument], f: &Formatter<'_, '_>) -> bool

let penultimate = iter.next_back().and_then(|arg| arg.as_expression());
let last_can_group_fn = || can_group_expression_argument(last, f);
should_group_last_argument_impl(penultimate, last, last_can_group_fn, f)
should_group_last_argument_impl(args.len(), penultimate, last, last_can_group_fn, f)
}

/// Check if `ty` is a relatively simple type annotation, allowing a few
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/calls/issue-16427.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
useImperativeHandle(ref, () => ({ getIsPending: () => isPending }), [
isPending,
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
useImperativeHandle(ref, () => ({ getIsPending: () => isPending }), [
isPending,
]);

==================== Output ====================
------------------
{ printWidth: 80 }
------------------
useImperativeHandle(ref, () => ({ getIsPending: () => isPending }), [
isPending,
]);

-------------------
{ printWidth: 100 }
-------------------
useImperativeHandle(ref, () => ({ getIsPending: () => isPending }), [isPending]);

===================== End =====================
Loading