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
37 changes: 18 additions & 19 deletions crates/oxc_formatter/src/print/arrow_function_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ impl<'a, 'b> FormatJsArrowFunctionExpression<'a, 'b> {
};
}

write!(f, formatted_signature);

let body_has_soft_line_break =
arrow_expression.is_none_or(|expression| match expression {
Expression::ArrowFunctionExpression(_)
Expand All @@ -178,7 +180,7 @@ impl<'a, 'b> FormatJsArrowFunctionExpression<'a, 'b> {
});

if body_has_soft_line_break {
write!(f, [formatted_signature, space(), format_body]);
write!(f, [space(), format_body]);
} else {
let should_add_parens = arrow.expression && should_add_parens(body);

Expand All @@ -194,24 +196,21 @@ impl<'a, 'b> FormatJsArrowFunctionExpression<'a, 'b> {

write!(
f,
[
formatted_signature,
group(&format_args!(
soft_line_indent_or_space(&format_with(|f| {
if should_add_parens {
write!(f, if_group_fits_on_line(&"("));
}

write!(f, format_body);

if should_add_parens {
write!(f, if_group_fits_on_line(&")"));
}
})),
is_last_call_arg.then_some(&FormatTrailingCommas::All),
should_add_soft_line.then_some(soft_line_break())
))
]
group(&format_args!(
soft_line_indent_or_space(&format_with(|f| {
if should_add_parens {
write!(f, if_group_fits_on_line(&"("));
}

write!(f, format_body);

if should_add_parens {
write!(f, if_group_fits_on_line(&")"));
}
})),
is_last_call_arg.then_some(&FormatTrailingCommas::All),
should_add_soft_line.then_some(soft_line_break())
))
);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(): {
any
// this comment causes function body in a new line
} => ({
any
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
(): {
any
// this comment causes function body in a new line
} => ({
any
});

==================== Output ====================
------------------
{ printWidth: 80 }
------------------
(): {
any;
// this comment causes function body in a new line
} => ({
any,
});

-------------------
{ printWidth: 100 }
-------------------
(): {
any;
// this comment causes function body in a new line
} => ({
any,
});

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