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.
This commit is contained in:
Noah Peart 2023-11-21 15:59:48 +02:00 committed by Dmitry Gutov
parent 61cdf42a48
commit 9af03e0e18
2 changed files with 27 additions and 0 deletions

View file

@ -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)

View file

@ -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)