Skip to content

Commit 537185d

Browse files
committed
fix(formatter): should always group the left side of AssignmentPattern (#14730)
1 parent faada4d commit 537185d

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

crates/oxc_formatter/src/write/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,14 @@ impl<'a> FormatWrite<'a> for AstNode<'a, AssignmentPattern<'a>> {
948948
let comments = f.context().comments().own_line_comments_before(self.right.span().start);
949949
write!(
950950
f,
951-
[FormatLeadingComments::Comments(comments), left, space(), "=", space(), self.right()]
951+
[
952+
FormatLeadingComments::Comments(comments),
953+
group(&left),
954+
space(),
955+
"=",
956+
space(),
957+
self.right()
958+
]
952959
)
953960
}
954961
}

crates/oxc_formatter/tests/fixtures/ts/parameters/object-pattern.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,18 @@
1111
export function useCopyToClipboard({ timeout = 2000, onCopy }: {
1212
timeout?: number;
1313
onCopy?: () => void;
14-
} = {}) {}
14+
} = {}) { }
15+
16+
function callbackUrl(
17+
{ baseUrl, params }: { baseUrl: string; params?: string } = {
18+
baseUrl: "",
19+
params: undefined,
20+
}
21+
) { }
22+
23+
function parseTitle(
24+
item: PageObjectResponse | DatabaseObjectResponse,
25+
{
26+
maxLength = DocumentValidation.maxTitleLength,
27+
}: { maxLength?: number } = {}
28+
) {}

crates/oxc_formatter/tests/fixtures/ts/parameters/object-pattern.ts.snap

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,21 @@ source: crates/oxc_formatter/tests/fixtures/mod.rs
1515
export function useCopyToClipboard({ timeout = 2000, onCopy }: {
1616
timeout?: number;
1717
onCopy?: () => void;
18-
} = {}) {}
18+
} = {}) { }
19+
20+
function callbackUrl(
21+
{ baseUrl, params }: { baseUrl: string; params?: string } = {
22+
baseUrl: "",
23+
params: undefined,
24+
}
25+
) { }
26+
27+
function parseTitle(
28+
item: PageObjectResponse | DatabaseObjectResponse,
29+
{
30+
maxLength = DocumentValidation.maxTitleLength,
31+
}: { maxLength?: number } = {}
32+
) {}
1933

2034
==================== Output ====================
2135
(
@@ -39,4 +53,18 @@ export function useCopyToClipboard({
3953
onCopy?: () => void;
4054
} = {}) {}
4155

56+
function callbackUrl(
57+
{ baseUrl, params }: { baseUrl: string; params?: string } = {
58+
baseUrl: "",
59+
params: undefined,
60+
},
61+
) {}
62+
63+
function parseTitle(
64+
item: PageObjectResponse | DatabaseObjectResponse,
65+
{
66+
maxLength = DocumentValidation.maxTitleLength,
67+
}: { maxLength?: number } = {},
68+
) {}
69+
4270
===================== End =====================

0 commit comments

Comments
 (0)