diff --git a/crates/oxc_formatter/src/utils/member_chain/mod.rs b/crates/oxc_formatter/src/utils/member_chain/mod.rs index 792eb8ed1606a..123e0676705c7 100644 --- a/crates/oxc_formatter/src/utils/member_chain/mod.rs +++ b/crates/oxc_formatter/src/utils/member_chain/mod.rs @@ -94,7 +94,13 @@ impl<'a, 'b> MemberChain<'a, 'b> { has_computed_property || is_factory(&identifier.name) || // If an identifier has a name that is shorter than the tab with, then we join it with the "head" - (matches!(parent, AstNodes::ExpressionStatement(_)) + (matches!(parent, AstNodes::ExpressionStatement(stmt) if { + if let AstNodes::ArrowFunctionExpression(arrow) = stmt.parent.parent() { + !arrow.expression + } else { + true + } + }) && has_short_name(&identifier.name, f.options().indent_width.value())) } else { matches!(node.as_ref(), Expression::ThisExpression(_)) diff --git a/crates/oxc_formatter/tests/fixtures/js/member-chains/arrow.js b/crates/oxc_formatter/tests/fixtures/js/member-chains/arrow.js new file mode 100644 index 0000000000000..a60958094a9f4 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/member-chains/arrow.js @@ -0,0 +1,4 @@ +(id) => + id + .replace('@', resolve(__dirname, './mods/')) + .replace('#', resolve(__dirname, '../../')) diff --git a/crates/oxc_formatter/tests/fixtures/js/member-chains/arrow.js.snap b/crates/oxc_formatter/tests/fixtures/js/member-chains/arrow.js.snap new file mode 100644 index 0000000000000..63b2a78ab2a8f --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/js/member-chains/arrow.js.snap @@ -0,0 +1,16 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +(id) => + id + .replace('@', resolve(__dirname, './mods/')) + .replace('#', resolve(__dirname, '../../')) + +==================== Output ==================== +(id) => + id + .replace("@", resolve(__dirname, "./mods/")) + .replace("#", resolve(__dirname, "../../")); + +===================== End =====================