GNU bug report logs - #77369
typescript-ts-mode's defun definition is wrong

Previous Next

Package: emacs;

Reported by: Daniel Colascione <dancol <at> dancol.org>

Date: Sat, 29 Mar 2025 18:18:01 UTC

Severity: normal

Done: Yuan Fu <casouri <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 77369 in the body.
You can then email your comments to 77369 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#77369; Package emacs. (Sat, 29 Mar 2025 18:18:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Colascione <dancol <at> dancol.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 29 Mar 2025 18:18:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Colascione <dancol <at> dancol.org>
To: bug-gnu-emacs <at> gnu.org
Subject: typescript-ts-mode's defun definition is wrong
Date: Sat, 29 Mar 2025 14:17:15 -0400
Not sure whether this is a bug or just surprising design, but in this
code:

    function Blah(foo) {
      const foo = 1;
      const bar = 2;
    }

with point on "const foo", I do not expect end-of-defun to go to "const
bar".  I expect it to go to the closing curly brace.




Reply sent to Yuan Fu <casouri <at> gmail.com>:
You have taken responsibility. (Sun, 30 Mar 2025 04:22:01 GMT) Full text and rfc822 format available.

Notification sent to Daniel Colascione <dancol <at> dancol.org>:
bug acknowledged by developer. (Sun, 30 Mar 2025 04:22:01 GMT) Full text and rfc822 format available.

Message #10 received at 77369-done <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Daniel Colascione <dancol <at> dancol.org>
Cc: Theodor Thornhill <theo <at> thornhill.no>, 77369-done <at> debbugs.gnu.org
Subject: Re: bug#77369: typescript-ts-mode's defun definition is wrong
Date: Sat, 29 Mar 2025 21:21:05 -0700

> On Mar 29, 2025, at 11:17 AM, Daniel Colascione <dancol <at> dancol.org> wrote:
> 
> Not sure whether this is a bug or just surprising design, but in this
> code:
> 
>    function Blah(foo) {
>      const foo = 1;
>      const bar = 2;
>    }
> 
> with point on "const foo", I do not expect end-of-defun to go to "const
> bar".  I expect it to go to the closing curly brace.

Yeah, that’s because const foo = 1; is a “lexical_declaration”, which is considered a defunct in typescript-ts-mode, because in js you can have arrow functions like

const Blah = (foo) => {
  return true;
};

Which is also a “lexical_declaration”. I guess we can refine the pattern matching to check if it’s an arrow function and only then consider it a defun.

I did that, now on latest master, end-of-defun should move to the end of the function in your example.

Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77369; Package emacs. (Thu, 03 Apr 2025 07:31:02 GMT) Full text and rfc822 format available.

Message #13 received at 77369 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Daniel Colascione <dancol <at> dancol.org>,
 Yuan Fu <casouri <at> gmail.com>, Juri Linkov <juri <at> linkov.net>
Cc: 77369 <at> debbugs.gnu.org
Subject: Re: bug#77369: typescript-ts-mode's defun definition is wrong
Date: Thu, 03 Apr 2025 10:30:19 +0300
> From: Daniel Colascione <dancol <at> dancol.org>
> Date: Sat, 29 Mar 2025 14:17:15 -0400
> 
> Not sure whether this is a bug or just surprising design, but in this
> code:
> 
>     function Blah(foo) {
>       const foo = 1;
>       const bar = 2;
>     }
> 
> with point on "const foo", I do not expect end-of-defun to go to "const
> bar".  I expect it to go to the closing curly brace.

Juri and Yuan, any comments or suggestions?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77369; Package emacs. (Thu, 03 Apr 2025 07:47:01 GMT) Full text and rfc822 format available.

Message #16 received at 77369 <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Daniel Colascione <dancol <at> dancol.org>, 77369 <at> debbugs.gnu.org,
 Juri Linkov <juri <at> linkov.net>
Subject: Re: bug#77369: typescript-ts-mode's defun definition is wrong
Date: Thu, 3 Apr 2025 00:46:04 -0700

> On Apr 3, 2025, at 12:30 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Daniel Colascione <dancol <at> dancol.org>
>> Date: Sat, 29 Mar 2025 14:17:15 -0400
>> 
>> Not sure whether this is a bug or just surprising design, but in this
>> code:
>> 
>>    function Blah(foo) {
>>      const foo = 1;
>>      const bar = 2;
>>    }
>> 
>> with point on "const foo", I do not expect end-of-defun to go to "const
>> bar".  I expect it to go to the closing curly brace.
> 
> Juri and Yuan, any comments or suggestions?

I pushed a fix for it. Maybe my message got lost? Though now that I think of it, I should’ve pushed the fix to emacs-30 instead of master...

Below is my last message:
> 
> Yeah, that’s because const foo = 1; is a “lexical_declaration”, which is considered a defunct in typescript-ts-mode, because in js you can have arrow functions like
> 
> const Blah = (foo) => {
>  return true;
> };
> 
> Which is also a “lexical_declaration”. I guess we can refine the pattern matching to check if it’s an arrow function and only then consider it a defun.
> 
> I did that, now on latest master, end-of-defun should move to the end of the function in your example.
> 
Yuan



Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77369; Package emacs. (Thu, 03 Apr 2025 07:58:02 GMT) Full text and rfc822 format available.

Message #19 received at 77369 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Yuan Fu <casouri <at> gmail.com>
Cc: dancol <at> dancol.org, 77369 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#77369: typescript-ts-mode's defun definition is wrong
Date: Thu, 03 Apr 2025 10:56:41 +0300
> From: Yuan Fu <casouri <at> gmail.com>
> Date: Thu, 3 Apr 2025 00:46:04 -0700
> Cc: Daniel Colascione <dancol <at> dancol.org>,
>  Juri Linkov <juri <at> linkov.net>,
>  77369 <at> debbugs.gnu.org
> 
> > On Apr 3, 2025, at 12:30 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> > 
> >> From: Daniel Colascione <dancol <at> dancol.org>
> >> Date: Sat, 29 Mar 2025 14:17:15 -0400
> >> 
> >> Not sure whether this is a bug or just surprising design, but in this
> >> code:
> >> 
> >>    function Blah(foo) {
> >>      const foo = 1;
> >>      const bar = 2;
> >>    }
> >> 
> >> with point on "const foo", I do not expect end-of-defun to go to "const
> >> bar".  I expect it to go to the closing curly brace.
> > 
> > Juri and Yuan, any comments or suggestions?
> 
> I pushed a fix for it. Maybe my message got lost?

Or maybe I missed it, in which case my apologies.

> Though now that I think of it, I should’ve pushed the fix to emacs-30 instead of master...

Yes, please backport to emacs-30, and thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77369; Package emacs. (Fri, 04 Apr 2025 05:55:01 GMT) Full text and rfc822 format available.

Message #22 received at 77369-done <at> debbugs.gnu.org (full text, mbox):

From: Yuan Fu <casouri <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 77369-done <at> debbugs.gnu.org, dancol <at> dancol.org, juri <at> linkov.net
Subject: Re: bug#77369: typescript-ts-mode's defun definition is wrong
Date: Thu, 3 Apr 2025 22:54:17 -0700

> On Apr 3, 2025, at 12:56 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
> 
>> From: Yuan Fu <casouri <at> gmail.com>
>> Date: Thu, 3 Apr 2025 00:46:04 -0700
>> Cc: Daniel Colascione <dancol <at> dancol.org>,
>> Juri Linkov <juri <at> linkov.net>,
>> 77369 <at> debbugs.gnu.org
>> 
>>> On Apr 3, 2025, at 12:30 AM, Eli Zaretskii <eliz <at> gnu.org> wrote:
>>> 
>>>> From: Daniel Colascione <dancol <at> dancol.org>
>>>> Date: Sat, 29 Mar 2025 14:17:15 -0400
>>>> 
>>>> Not sure whether this is a bug or just surprising design, but in this
>>>> code:
>>>> 
>>>>   function Blah(foo) {
>>>>     const foo = 1;
>>>>     const bar = 2;
>>>>   }
>>>> 
>>>> with point on "const foo", I do not expect end-of-defun to go to "const
>>>> bar".  I expect it to go to the closing curly brace.
>>> 
>>> Juri and Yuan, any comments or suggestions?
>> 
>> I pushed a fix for it. Maybe my message got lost?
> 
> Or maybe I missed it, in which case my apologies.
> 
>> Though now that I think of it, I should’ve pushed the fix to emacs-30 instead of master...
> 
> Yes, please backport to emacs-30, and thanks.

Cool, backported to emacs-30.

Yuan





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 02 May 2025 11:24:15 GMT) Full text and rfc822 format available.

This bug report was last modified 100 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.