Subject: bug#77803: closed (Re: bug#77803: [PATCH v2] Don't indent variable names to their declarator expression (bug#77803))

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 18 Apr 2025 23:44:04 +0000

Your bug report

#77803: tsx-ts-mode: wrong indentation for variables declarations

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
77803: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=77803
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#77803: [PATCH v2] Don't indent variable names to their declarator expression (bug#77803)
From: Yuan Fu <[email-masked]>
To: Konstantin Kharlamov <[email-masked]>
Cc: Eli Zaretskii <[email-masked]>, [email-masked], [email-masked]
Date: Fri, 18 Apr 2025 16:43:17 -0700
List-Id: <debbugs-submit.debbugs.gnu.org>

> On Apr 15, 2025, at 10:09 PM, Konstantin Kharlamov <[email-masked]> wrote:
> 
> On Tue, 2025-04-15 at 17:53 +0300, Konstantin Kharlamov wrote:
>> On Tue, 2025-04-15 at 17:42 +0300, Eli Zaretskii wrote:
>>> 
>>> Try
>>>       make -C test lisp/progmodes/typescript-ts-mode-tests
>> 
>> Thank you, please see the patch!
> 
> v2: no code change, just noticed a typo in patch description, a "one
> space" instead of "two spaces" after the dot, and a missing dot in the
> final sentence: fixed.
From 036125357f2c7a7d476516516ec8060fcb82ca77 Mon Sep 17 00:00:00 2001
From: Konstantin Kharlamov <[email-masked]>
Date: Tue, 15 Apr 2025 17:34:11 +0300
Subject: [PATCH v2] Don't indent variable names to their declarator expression
 (bug#77803)

Before this commit in code like:

    const a = 1,
          b = 2;

the b would get indented to `const'.  Similarly for `var' and `let'.
The expected behavior instead is getting indented to
`typescript-ts-mode-indent-offset'.

* lisp/progmodes/typescript-ts-mode.el
(typescript-ts-mode--indent-rules): indent identifiers declarations to
`typescript-ts-mode-indent-offset'.
* test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
(Lexical and variable declarations): update test accordingly.
---
 lisp/progmodes/typescript-ts-mode.el          |  2 +-
 .../typescript-ts-mode-resources/indent.erts  | 28 +++++++++----------
 2 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index bc4b635735f..590d2b55235 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -140,7 +140,7 @@ typescript-ts-mode--indent-rules
      ((parent-is "type_arguments") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "type_parameters") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is ,(rx (or "variable" "lexical") "_" (or "declaration" "declarator")))
-      typescript-ts-mode--anchor-decl 1)
+      parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "arguments") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "array") parent-bol typescript-ts-mode-indent-offset)
      ((parent-is "formal_parameters") 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 0db35295222..1305029a9e1 100644
--- a/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
+++ b/test/lisp/progmodes/typescript-ts-mode-resources/indent.erts
@@ -67,22 +67,22 @@ Name: Lexical and variable declarations
 =-=
 const foo = () => {
   let x = 1,
-      yyyy: {
-        [k: string | number]: string,
-      } = {
-        "foo": "foo",
-        "bar": "bar",
-      };
+    yyyy: {
+      [k: string | number]: string,
+    } = {
+      "foo": "foo",
+      "bar": "bar",
+    };
   var obar = 1,
-      fo: { [x: any]: any } = {
-        "a": 1,
-        "b": 2,
-      };
+    fo: { [x: any]: any } = {
+      "a": 1,
+      "b": 2,
+    };
   const cccc = 1,
-        bbb = {
-          "x": 0
-        },
-        ddddd = 0;
+    bbb = {
+      "x": 0
+    },
+    ddddd = 0;
   // First decls with value starting on same line
   const a = (x: string): string => {
     return x + x;
-- 
2.49.0

Thanks! I personally like the current indentation, but indeed other editors, and more importantly prettier, indents like what your patch implemented. I applied the patch to emacs-30 and pushed.

Yuan

Subject: tsx-ts-mode: wrong indentation for variables declarations
From: Konstantin Kharlamov <[email-masked]>
To: [email-masked]
Date: Mon, 14 Apr 2025 18:41:42 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

Given this TypeScript snippet:

    const a = 1,
          b = 2;
    var c = 3,
        d = 4;

…both b and d are expected to be indented to `typescript-ts-mode-indent-offset`
(2 by default). This both makes logical sense and is the behavior in another
editor VSCode.

Instead it gets indented to the length of `const` and `var` + space.

I'd note a separate problem: if you have this code:

    const a = 1,
      b = 2,
          c = 3;

…and you try to indent `c`, instead of getting indented to the previous line it
keeps being at "const + space" length.