Subject: bug#79465: js-ts-mode treesit-thing-settings

From: Juri Linkov <[email-masked]>
Date: Thu, 18 Sep 2025 09:48:04 +0300

While improving treesit-things for ts-modes,
I hesitated to change js--treesit-thing-settings,
but now don't see a problem with adapting the same rule
as already used by c-ts-mode for a long time that
matches all nodes except "{" "}" "[" "]" "(" ")" ",".

The problem is that the existing 'js--treesit-sexp-nodes'
is a list of nodes joined together by 'js--regexp-opt-symbol',
whereas the new definition is a sexp matcher.

Therefore we could make the internal variable
'js--treesit-sexp-nodes' obsolete like in this patch:

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 00c57b72e18..0fda7d62145 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3949,38 +3949,11 @@ js--treesit-sentence-nodes
   "Nodes that designate sentences in JavaScript.
 See `treesit-thing-settings' for more information.")
 
-(defvar js--treesit-sexp-nodes
-  '("expression"
-    "parenthesized_expression"
-    "formal_parameters"
-    "pattern"
-    "array"
-    "function"
-    "string"
-    "template_string"
-    "template_substitution"
-    "escape"
-    "template"
-    "regex"
-    "number"
-    "identifier"
-    "property_identifier"
-    "this"
-    "super"
-    "true"
-    "false"
-    "null"
-    "undefined"
-    "arguments"
-    "pair"
-    "jsx"
-    "statement_block"
-    "object"
-    "object_pattern"
-    "named_imports"
-    "class_body")
+(defvar js--treesit-sexp-nodes nil
   "Nodes that designate sexps in JavaScript.
 See `treesit-thing-settings' for more information.")
+(make-obsolete 'js--treesit-sexp-nodes
+               "`js--treesit-sexp-nodes' will be removed soon, use `js--treesit-thing-settings' instead." "31.1")
 
 (defvar js--treesit-list-nodes
   '("export_clause"
@@ -4011,7 +3984,13 @@ js--treesit-jsdoc-beginning-regexp
 
 (defvar js--treesit-thing-settings
   `((javascript
-     (sexp ,(js--regexp-opt-symbol js--treesit-sexp-nodes))
+     (sexp ,(if js--treesit-sexp-nodes
+                (js--regexp-opt-symbol js--treesit-sexp-nodes)
+              `(not (or (and named
+                             ,(rx bos (or "program" "comment") eos))
+                        (and anonymous
+                             ,(rx (or "{" "}" "[" "]"
+                                      "(" ")" ",")))))))
      (list ,(js--regexp-opt-symbol js--treesit-list-nodes))
      (sentence ,(js--regexp-opt-symbol js--treesit-sentence-nodes))
      (text ,(js--regexp-opt-symbol '("comment"