aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoah Peart2023-11-21 15:59:48 +0200
committerDmitry Gutov2023-11-21 16:26:54 +0200
commit9af03e0e1897bce2fce71b79549d4461d7ea1dad (patch)
tree4f2903b14f6543c23f50ddd758f30b16a7c91635
parent61cdf42a48fab24b7ee4098ffedf7254080f808b (diff)
downloademacs-9af03e0e1897bce2fce71b79549d4461d7ea1dad.tar.gz
emacs-9af03e0e1897bce2fce71b79549d4461d7ea1dad.zip
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.
-rw-r--r--lisp/progmodes/typescript-ts-mode.el5
-rw-r--r--test/lisp/progmodes/typescript-ts-mode-resources/indent.erts22
2 files changed, 27 insertions, 0 deletions
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'."
124 ((parent-is "arrow_function") parent-bol typescript-ts-mode-indent-offset) 124 ((parent-is "arrow_function") parent-bol typescript-ts-mode-indent-offset)
125 ((parent-is "parenthesized_expression") parent-bol typescript-ts-mode-indent-offset) 125 ((parent-is "parenthesized_expression") parent-bol typescript-ts-mode-indent-offset)
126 ((parent-is "binary_expression") parent-bol typescript-ts-mode-indent-offset) 126 ((parent-is "binary_expression") parent-bol typescript-ts-mode-indent-offset)
127 ((match "while" "do_statement") parent-bol 0)
128 ((match "else" "if_statement") parent-bol 0)
129 ((parent-is ,(rx (or (seq (or "if" "for" "for_in" "while" "do") "_statement")
130 "else_clause")))
131 parent-bol typescript-ts-mode-indent-offset)
127 132
128 ,@(when (eq language 'tsx) 133 ,@(when (eq language 'tsx)
129 (append (tsx-ts-mode--indent-compatibility-b893426) 134 (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 = () => {
23} 23}
24=-=-= 24=-=-=
25 25
26Name: Statement indentation without braces
27
28=-=
29const foo = () => {
30 if (true)
31 console.log("if_statement");
32 else if (false)
33 console.log("if_statement");
34 else
35 console.log("else_clause");
36 for (let i = 0; i < 1; i++)
37 console.log("for_statement");
38 for (let i of [true])
39 console.log("for_in_statement");
40 while (false)
41 console.log("while_statement");
42 do
43 console.log("do_statement");
44 while (false)
45};
46=-=-=
47
26Code: 48Code:
27 (lambda () 49 (lambda ()
28 (setq indent-tabs-mode nil) 50 (setq indent-tabs-mode nil)