[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
emacs-29 9af03e0e189 2/5: typescript-ts-mode: Support indentation for co
From: |
Dmitry Gutov |
Subject: |
emacs-29 9af03e0e189 2/5: typescript-ts-mode: Support indentation for conditionals without braces |
Date: |
Tue, 21 Nov 2023 09:27:11 -0500 (EST) |
branch: emacs-29
commit 9af03e0e1897bce2fce71b79549d4461d7ea1dad
Author: Noah Peart <noah.v.peart@gmail.com>
Commit: Dmitry Gutov <dmitry@gutov.dev>
typescript-ts-mode: Support indentation for conditionals without braces
* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--indent-rules): Support indentation for
conditionals without braces (bug#67031).
* test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
(Statement indentation without braces): New test.
---
lisp/progmodes/typescript-ts-mode.el | 5 +++++
.../typescript-ts-mode-resources/indent.erts | 22 ++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/lisp/progmodes/typescript-ts-mode.el
b/lisp/progmodes/typescript-ts-mode.el
index ec220ab8d03..4e039abd236 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -124,6 +124,11 @@ Argument LANGUAGE is either `typescript' or `tsx'."
((parent-is "arrow_function") parent-bol typescript-ts-mode-indent-offset)
((parent-is "parenthesized_expression") parent-bol
typescript-ts-mode-indent-offset)
((parent-is "binary_expression") parent-bol
typescript-ts-mode-indent-offset)
+ ((match "while" "do_statement") parent-bol 0)
+ ((match "else" "if_statement") parent-bol 0)
+ ((parent-is ,(rx (or (seq (or "if" "for" "for_in" "while" "do")
"_statement")
+ "else_clause")))
+ parent-bol typescript-ts-mode-indent-offset)
,@(when (eq language 'tsx)
(append (tsx-ts-mode--indent-compatibility-b893426)
diff --git a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
index 146ee76574e..20f423259b4 100644
--- a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
@@ -23,6 +23,28 @@ const foo = () => {
}
=-=-=
+Name: Statement indentation without braces
+
+=-=
+const foo = () => {
+ if (true)
+ console.log("if_statement");
+ else if (false)
+ console.log("if_statement");
+ else
+ console.log("else_clause");
+ for (let i = 0; i < 1; i++)
+ console.log("for_statement");
+ for (let i of [true])
+ console.log("for_in_statement");
+ while (false)
+ console.log("while_statement");
+ do
+ console.log("do_statement");
+ while (false)
+};
+=-=-=
+
Code:
(lambda ()
(setq indent-tabs-mode nil)