From 34fab40303e8e7db2ea6c20dffb150ff01ca4428 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Mon, 27 Oct 2025 09:32:54 +0000 Subject: [PATCH] fix(formatter): correct calculating layout for `ChainExpression` in `StaticMemberExpression` (#14986) --- .../oxc_formatter/src/write/member_expression.rs | 4 +++- .../fixtures/ts/static-members/chain-expression.ts | 3 +++ .../ts/static-members/chain-expression.ts.snap | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 crates/oxc_formatter/tests/fixtures/ts/static-members/chain-expression.ts create mode 100644 crates/oxc_formatter/tests/fixtures/ts/static-members/chain-expression.ts.snap diff --git a/crates/oxc_formatter/src/write/member_expression.rs b/crates/oxc_formatter/src/write/member_expression.rs index 64f1c603ea7b7..b1f87cae15f2e 100644 --- a/crates/oxc_formatter/src/write/member_expression.rs +++ b/crates/oxc_formatter/src/write/member_expression.rs @@ -141,7 +141,9 @@ fn layout<'a>( let mut first_non_static_member_ancestor = parent; while matches!( first_non_static_member_ancestor, - AstNodes::StaticMemberExpression(_) | AstNodes::ComputedMemberExpression(_) + AstNodes::StaticMemberExpression(_) + | AstNodes::ComputedMemberExpression(_) + | AstNodes::ChainExpression(_) ) { first_non_static_member_ancestor = first_non_static_member_ancestor.parent(); } diff --git a/crates/oxc_formatter/tests/fixtures/ts/static-members/chain-expression.ts b/crates/oxc_formatter/tests/fixtures/ts/static-members/chain-expression.ts new file mode 100644 index 0000000000000..497eb4dab9a08 --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/static-members/chain-expression.ts @@ -0,0 +1,3 @@ +this._position = this._editor + ._getViewModel() + ?.getPrimaryCursorState().modelState.position; diff --git a/crates/oxc_formatter/tests/fixtures/ts/static-members/chain-expression.ts.snap b/crates/oxc_formatter/tests/fixtures/ts/static-members/chain-expression.ts.snap new file mode 100644 index 0000000000000..a815e07b2f4ed --- /dev/null +++ b/crates/oxc_formatter/tests/fixtures/ts/static-members/chain-expression.ts.snap @@ -0,0 +1,14 @@ +--- +source: crates/oxc_formatter/tests/fixtures/mod.rs +--- +==================== Input ==================== +this._position = this._editor + ._getViewModel() + ?.getPrimaryCursorState().modelState.position; + +==================== Output ==================== +this._position = this._editor + ._getViewModel() + ?.getPrimaryCursorState().modelState.position; + +===================== End =====================