From ab126284081cd1f6a3317dc1e94636bf17af2375 Mon Sep 17 00:00:00 2001 From: nverno Date: Mon, 27 Nov 2023 08:55:23 -0800 Subject: [PATCH] Fix typescript-ts-mode indentation for switch statements * lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode): Add indentation rule for switch case and default keywords. (Bug#67488) --- lisp/progmodes/typescript-ts-mode.el | 3 +++ .../typescript-ts-mode-resources/indent.erts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index a2b16d1beea..0fbac709c63 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -107,6 +107,9 @@ Argument LANGUAGE is either `typescript' or `tsx'." ((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) + ((or (node-is "case") + (node-is "default")) + parent-bol typescript-ts-mode-indent-offset) ((parent-is "switch_case") parent-bol typescript-ts-mode-indent-offset) ((parent-is "switch_default") parent-bol typescript-ts-mode-indent-offset) ((parent-is "type_arguments") 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 20f423259b4..7b6185e0386 100644 --- a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts +++ b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts @@ -45,6 +45,23 @@ const foo = () => { }; =-=-= +Name: Switch statement + +=-= +const foo = (x: string) => { + switch (x) { + case "a": + console.log(x); + return 1; + case "b": + return 2; + case "c": + default: + return 0; + } +}; +=-=-= + Code: (lambda () (setq indent-tabs-mode nil) -- 2.39.2