Subject: bug#66988: 30.0.50; treesit-forward-sexp not working properly in js-ts-mode and tsx-ts-mode

From: Juri Linkov <[email-masked]>
Date: Fri, 10 Nov 2023 09:37:38 +0200

> @@ -3843,6 +3843,7 @@ js--treesit-sexp-nodes
>      "undefined"
>      "arguments"
>      "pair"
> +    "parenthesized_expression"
>      "jsx")
>    "Nodes that designate sexps in JavaScript.
>  See `treesit-thing-settings' for more information.")

I had the same problem and to make this mode more usable had to use such patch:

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 5a669fdbd42..4c07fbd94b7 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3825,7 +3825,9 @@ js--treesit-sentence-nodes
 See `treesit-thing-settings' for more information.")
 
 (defvar js--treesit-sexp-nodes
-  '("expression"
+  '("expression" ;; SHOULD NOT MATCH "expression_statement", BUT SHOULD MATCH "parenthesized_expression"
+    "parenthesized_expression"
+    "formal_parameters"
     "pattern"
     "array"
     "function"
@@ -3843,7 +3845,13 @@ js--treesit-sexp-nodes
     "undefined"
     "arguments"
     "pair"
-    "jsx")
+    "jsx"
+    "statement_block"
+    "object"
+    "object_pattern"
+    "named_imports"
+    "class_body"
+    )
   "Nodes that designate sexps in JavaScript.
 See `treesit-thing-settings' for more information.")
 
PS:
Also tried to replace
  (setq-local treesit-sexp-type-regexp (regexp-opt js--treesit-sexp-nodes))
with
  (setq-local treesit-sexp-type-regexp (rx-to-string `(seq bol (or ,@js--treesit-sexp-nodes) eol)))