Skip to content

Commit 6cba9b1

Browse files
committed
fix(formatter): should not merge tail with head for MemberChain when its parent is ArrowFunctionExpression (#14663)
1 parent f44d3c0 commit 6cba9b1

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

crates/oxc_formatter/src/utils/member_chain/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ impl<'a, 'b> MemberChain<'a, 'b> {
9494
has_computed_property ||
9595
is_factory(&identifier.name) ||
9696
// If an identifier has a name that is shorter than the tab with, then we join it with the "head"
97-
(matches!(parent, AstNodes::ExpressionStatement(_))
97+
(matches!(parent, AstNodes::ExpressionStatement(stmt) if {
98+
if let AstNodes::ArrowFunctionExpression(arrow) = stmt.parent.parent() {
99+
!arrow.expression
100+
} else {
101+
true
102+
}
103+
})
98104
&& has_short_name(&identifier.name, f.options().indent_width.value()))
99105
} else {
100106
matches!(node.as_ref(), Expression::ThisExpression(_))
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(id) =>
2+
id
3+
.replace('@', resolve(__dirname, './mods/'))
4+
.replace('#', resolve(__dirname, '../../'))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
source: crates/oxc_formatter/tests/fixtures/mod.rs
3+
---
4+
==================== Input ====================
5+
(id) =>
6+
id
7+
.replace('@', resolve(__dirname, './mods/'))
8+
.replace('#', resolve(__dirname, '../../'))
9+
10+
==================== Output ====================
11+
(id) =>
12+
id
13+
.replace("@", resolve(__dirname, "./mods/"))
14+
.replace("#", resolve(__dirname, "../../"));
15+
16+
===================== End =====================

0 commit comments

Comments
 (0)