]> git.eshelyaron.com Git - emacs.git/commitdiff
typescript-ts-mode: align ternary-chain branches (bug#78187)
authorKonstantin Kharlamov <Hi-Angel@yandex.ru>
Thu, 1 May 2025 13:28:29 +0000 (20:28 +0700)
committerEshel Yaron <me@eshelyaron.com>
Tue, 20 May 2025 20:51:58 +0000 (22:51 +0200)
* 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
test/lisp/progmodes/typescript-ts-mode-resources/indent.erts

index 6ae3ddd646aa2b19ed3cad732fd13823f431587f..525bda2a33f60e1a0aeb890dc89d051067b03f65 100644 (file)
@@ -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)
index 1305029a9e150b7d96aa00cc7b1ed68ebf8ee5ce..e8b1d57f1327aba448f0bf9a5f364ac8dcf1e052 100644 (file)
@@ -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)