Subject: bug#68879: closed (Re: bug#68879: [PATCH] Compatibility issue with a newer version of tree-sitter-javascript)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 03 Feb 2024 09:23:01 +0000

Your bug report

#68879: [PATCH] Compatibility issue with a newer version of tree-sitter-javascript

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].

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

Subject: Re: bug#68879: [PATCH] Compatibility issue with a newer version of tree-sitter-javascript
From: Eli Zaretskii <[email-masked]>
To: Vincenzo Pupillo <[email-masked]>
Cc: [email-masked]
Date: Sat, 03 Feb 2024 11:21:34 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Vincenzo Pupillo <[email-masked]>
> Date: Thu, 1 Feb 2024 16:18:38 +0000
> 
> starting from version 0.20.2 (released yesterday) of tree-sitter-javascript 
> the "function" primary expression has been renamed to "function_expression". 
> 
> The attached patch (for emacs 29) supports the old and new versions.
> I also have a version for emacs 30.

Thanks, installed on the emacs-29 branch, and closing the bug.

Please note the minor changes I made in your commit log message, and
try to follow these conventions in the future.

Subject: [PATCH] Compatibility issue with a newer version of tree-sitter-javascript
From: Vincenzo Pupillo <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Thu, 1 Feb 2024 16:18:38 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi, 
starting from version 0.20.2 (released yesterday) of tree-sitter-javascript 
the "function" primary expression has been renamed to "function_expression". 

The attached patch (for emacs 29) supports the old and new versions.
I also have a version for emacs 30.

Thank you. 
V.

-- 
Vincenzo Pupillo
Direzione ICT
Università degli Studi di Milano / University of Milan (Italy)
Via Giuseppe Colombo, 46, 20133 Milano

>From 91b8853fb71e72f65b135535cf4d2bb3f1d3722f Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Thu, 1 Feb 2024 16:57:39 +0100
Subject: [PATCH] Fixed incompatibility with tree-sitter-javascrip >= 0.20.2 .

Starting from version 0.20.2 it has the primary expression \"fuction\".
has been renamed to \"function_expression\". A new function checks if
the new primary expression is available, so it returns the correct rules.

*
lisp/progmodes/js.el (js--treesit-font-lock-compatibility-definition-feature):
the new function.

* lisp/progmodes/js.el (js--treesit-font-lock-settings): Use this.
---
 lisp/progmodes/js.el | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index e4ccfd73cc7..12c4d0aedb8 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3427,6 +3427,26 @@ c-paragraph-start
 
 ;;; Tree sitter integration
 
+(defun js--treesit-font-lock-compatibility-definition-feature ()
+  "Font lock helper, to handle different releases of tree-sitter-javascript.
+Check if a node type is available, then return the right font lock rules
+for \"definition\" feature."
+  (condition-case nil
+      (progn (treesit-query-capture 'javascript '((function_expression) @cap))
+             ;; starting from 0.20.2
+             '((function_expression
+                name: (identifier) @font-lock-function-name-face)
+               (variable_declarator
+                name: (identifier) @font-lock-function-name-face
+                value: [(function_expression) (arrow_function)])))
+    (error
+     ;; older version
+     '((function
+        name: (identifier) @font-lock-function-name-face)
+       (variable_declarator
+        name: (identifier) @font-lock-function-name-face
+        value: [(function) (arrow_function)])))))
+
 (defun js-jsx--treesit-indent-compatibility-bb1f97b ()
   "Indent rules helper, to handle different releases of tree-sitter-javascript.
 Check if a node type is available, then return the right indent rules."
@@ -3538,8 +3558,7 @@ js--treesit-font-lock-settings
 
    :language 'javascript
    :feature 'definition
-   '((function
-      name: (identifier) @font-lock-function-name-face)
+   `(,@(js--treesit-font-lock-compatibility-definition-feature)
 
      (class_declaration
       name: (identifier) @font-lock-type-face)
@@ -3558,10 +3577,6 @@ js--treesit-font-lock-settings
      (variable_declarator
       name: (identifier) @font-lock-variable-name-face)
 
-     (variable_declarator
-      name: (identifier) @font-lock-function-name-face
-      value: [(function) (arrow_function)])
-
      (variable_declarator
       name: [(array_pattern (identifier) @font-lock-variable-name-face)
              (object_pattern
-- 
2.43.0