Skip to content

Commit 5ea3bb6

Browse files
committed
fix(formatter): incorrect handling of ObjectPattern as an AssignmentPattern of a parameter (#14711)
1 parent 83e783a commit 5ea3bb6

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

crates/oxc_formatter/src/write/object_pattern_like.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ impl<'a> ObjectPatternLike<'a, '_> {
5353

5454
fn is_inline(&self, f: &Formatter<'_, 'a>) -> bool {
5555
match self {
56-
Self::ObjectPattern(node) => {
57-
matches!(node.parent, AstNodes::FormalParameter(_))
58-
}
56+
Self::ObjectPattern(node) => match node.parent {
57+
AstNodes::FormalParameter(_) => true,
58+
AstNodes::AssignmentPattern(_) => {
59+
matches!(node.parent.parent(), AstNodes::FormalParameter(_))
60+
}
61+
_ => false,
62+
},
5963
Self::ObjectAssignmentTarget(node) => false,
6064
}
6165
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@
66
messenger: Messenger;
77
}) => {
88

9-
}
9+
}
10+
11+
export function useCopyToClipboard({ timeout = 2000, onCopy }: {
12+
timeout?: number;
13+
onCopy?: () => void;
14+
} = {}) {}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ source: crates/oxc_formatter/tests/fixtures/mod.rs
1111
}) => {
1212

1313
}
14+
15+
export function useCopyToClipboard({ timeout = 2000, onCopy }: {
16+
timeout?: number;
17+
onCopy?: () => void;
18+
} = {}) {}
19+
1420
==================== Output ====================
1521
(
1622
options,
@@ -25,4 +31,12 @@ source: crates/oxc_formatter/tests/fixtures/mod.rs
2531
},
2632
) => {};
2733

34+
export function useCopyToClipboard({
35+
timeout = 2000,
36+
onCopy,
37+
}: {
38+
timeout?: number;
39+
onCopy?: () => void;
40+
} = {}) {}
41+
2842
===================== End =====================

0 commit comments

Comments
 (0)