Skip to content

Commit e6bce8e

Browse files
committed
fix(formatter): break the left hand side of AssignmentLike node if it is an ObjectPattern with three properties (#14756)
1 parent dc57a2b commit e6bce8e

File tree

3 files changed

+39
-6
lines changed

3 files changed

+39
-6
lines changed

crates/oxc_formatter/src/utils/assignment_like.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,22 +604,24 @@ impl<'a> AssignmentLike<'a, '_> {
604604
return false;
605605
};
606606

607-
let properties = &object.properties;
608-
if properties.len() <= 2 {
607+
if object.len() <= 2 {
609608
return false;
610609
}
611610

612-
properties.iter().any(|property| {
613-
!property.shorthand || !property.value.kind.is_binding_identifier()
611+
object.properties.iter().any(|property| {
612+
!property.shorthand || property.value.kind.is_assignment_pattern()
614613
})
615614
}
616615
AssignmentLike::AssignmentExpression(assignment) => {
617616
let AssignmentTarget::ObjectAssignmentTarget(object) = &assignment.left else {
618617
return false;
619618
};
620619

621-
let properties = &object.properties;
622-
properties.iter().any(|property| match property {
620+
if object.len() <= 2 {
621+
return false;
622+
}
623+
624+
object.properties.iter().any(|property| match property {
623625
AssignmentTargetProperty::AssignmentTargetPropertyIdentifier(
624626
property_identifier,
625627
) => property_identifier.init.is_some(),
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
let { className, unfurl: unfurlAttrr, ...attrs } = getAttributesFromNode(node);
3+
4+
({ className, unfurl: unfurlAttrr, ...attrs } = { className: "name", unfurl: "unfurl", others: [1, 2, 3]});
5+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
{
6+
let { className, unfurl: unfurlAttrr, ...attrs } = getAttributesFromNode(node);
7+
8+
({ className, unfurl: unfurlAttrr, ...attrs } = { className: "name", unfurl: "unfurl", others: [1, 2, 3]});
9+
};
10+
11+
==================== Output ====================
12+
{
13+
let {
14+
className,
15+
unfurl: unfurlAttrr,
16+
...attrs
17+
} = getAttributesFromNode(node);
18+
19+
({
20+
className,
21+
unfurl: unfurlAttrr,
22+
...attrs
23+
} = { className: "name", unfurl: "unfurl", others: [1, 2, 3] });
24+
}
25+
26+
===================== End =====================

0 commit comments

Comments
 (0)