Subject: bug#75422: 30.0.93; [PATCH] forward-sexp and backward-sexp jump outside of comments in tsx-ts-mode

From: Juri Linkov <[email-masked]>
Date: Tue, 07 Jan 2025 19:44:27 +0200

> Steps to reproduce
> - emacs -Q test.tsx
> - (tsx-ts-mode)
> - Move point at the end of the comment at line 3
> - (backward-sexp)
>
> The expected point position after (backward-sexp) is "treesit-thing-|settings"
> or at least stay inside of the comment line, however, point moves to the
> beginning of "Hello".
> Likewise, if you C-x C-e at the end of the comment line, it evaluates "Hello".
>
> --- test.tsx (| is point) ---
> export const App = () => {
>   const greeting = "Hello"
>   // treesit-thing-settings|
>   return <>{greeting}</>
> }
> --- END test.tsx ---
>
> It happens because tsx-ts-mode doesn't recognize comments. In
> typescript-ts-base-mode, treesit-thing-settings is set to have "text" as
> a thing for typescript but it's missing in tsx-ts-mode when it's set for
> tsx.

Thanks for the report.  This is fixed in Emacs 31.

However, maybe Yuan will agree to add this small fix to Emacs 30?

> diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
> index 4a38d1da596..0ffcb144771 100644
> --- a/lisp/progmodes/typescript-ts-mode.el
> +++ b/lisp/progmodes/typescript-ts-mode.el
> @@ -564,7 +564,9 @@ tsx-ts-mode
>                     (sentence ,(regexp-opt
>                                 (append typescript-ts-mode--sentence-nodes
>                                         '("jsx_element"
> -                                         "jsx_self_closing_element")))))))
> +                                         "jsx_self_closing_element"))))
> +                   (text ,(regexp-opt '("comment"
> +                                        "template_string"))))))