From 1bf87bb5db10c1ce8d8076347a15262fe2e29a3c Mon Sep 17 00:00:00 2001 From: Konstantin Kharlamov Date: Thu, 1 May 2025 20:28:29 +0700 Subject: [PATCH] typescript-ts-mode: align ternary-chain branches (bug#78187) * lisp/progmodes/typescript-ts-mode.el: (typescript-ts-mode--indent-rules): Make sure each new ternary branch is aligned with the previous one. * test/lisp/progmodes/typescript-ts-mode-resources/indent.erts: (Chained ternary expressions): New test. (cherry picked from commit c80fbe3f2355ab7182dcba98ed9717f0231aab00) --- lisp/progmodes/typescript-ts-mode.el | 2 +- .../progmodes/typescript-ts-mode-resources/indent.erts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index 6ae3ddd646a..525bda2a33f 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -162,7 +162,7 @@ Argument LANGUAGE is either `typescript' or `tsx'." ((and (parent-is "comment") c-ts-common-looking-at-star) c-ts-common-comment-start-after-first-star -1) ((parent-is "comment") prev-adaptive-prefix 0) - ((parent-is "ternary_expression") parent-bol typescript-ts-mode-indent-offset) + ((parent-is "ternary_expression") standalone-parent typescript-ts-mode-indent-offset) ((parent-is "member_expression") parent-bol typescript-ts-mode-indent-offset) ((parent-is "named_imports") parent-bol typescript-ts-mode-indent-offset) ((parent-is "statement_block") parent-bol typescript-ts-mode-indent-offset) diff --git a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts index 1305029a9e1..e8b1d57f132 100644 --- a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts @@ -93,6 +93,15 @@ const foo = () => { }; =-=-= +Name: Chained ternary expressions + +=-= +const a = cond1 ? 1 + : cond2 ? 2 + : cond3 ? 3 + : 4; +=-=-= + Code: (lambda () (setq tsx-ts-mode-indent-offset 2) -- 2.39.5