Subject: bug#64647: closed (Re: bug#64647: treesit-query-error due to a recent change to tree-sitter-javascript grammar definition)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 23 Jul 2023 05:18:02 +0000

Your bug report

#64647: treesit-query-error due to a recent change to tree-sitter-javascript grammar definition

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

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

Subject: Re: bug#64647: treesit-query-error due to a recent change to tree-sitter-javascript grammar definition
From: Eli Zaretskii <[email-masked]>
To: Theodor Thornhill <[email-masked]>
Cc: [email-masked], [email-masked], [email-masked]
Date: Sun, 23 Jul 2023 08:17:56 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> From: Theodor Thornhill <[email-masked]>
> Cc: [email-masked], [email-masked]
> Date: Sat, 22 Jul 2023 23:22:44 +0200
> 
> Vincenzo Pupillo <[email-masked]> writes:
> 
> > The changes were made with two different patches. The one that modifies the 
> > indentation is this one: 
> > https://github.com/tree-sitter/tree-sitter-typescript/commit/
> > b893426b82492e59388a326b824a346d829487e8
> >
> > Thanks.
> > Ciao
> > V.
> 
> Great! Installed and pushed the patches to emacs-29. Thanks, Vincenzo!

Thank you all for a fast and efficient solution.

(The commit needed a small fixup, though.)

Closing the bug.

Subject: treesit-query-error due to a recent change to tree-sitter-javascript grammar definition
From: Vincenzo Pupillo <[email-masked]>
To: [email-masked]
Date: Sat, 15 Jul 2023 14:34:29 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi, 
this commit (bb1f97b643b77fc1f082d621bf533b4b14cf0c30) changed the definition 
of the JSX grammar to tree-sitter-javascript. This causes a node type error:
"
Error while displaying: (jit-lock-function 1) reported (treesit-query-error 
"Node type error at" 24 "(jsx_opening_element [(nested_identifier (identifier)) 
(identifier)] @font-lock-function-call-face) (jsx_closing_element 
[(nested_identifier (identifier)) (identifier)] @font- lock-function-call-face) 
(jsx_self_closing_element [(nested_identifier (identifier)) (identifier)] @font-
lock-function-call-face) (jsx_attribute (property_identifier) @font-lock-
constant-face)" "Debug the query with `treesit-query-validate'")
"
Indentation also has problems due to the deletion of "jsx_fragment" definition.

The patch in attachment fixes both problems.
Thank you
Vincenzo

p.s. nvim-treesitter tries to limit these problems by indicating which commit 
to install. Does it make sense to try a similar approach with emacs as well? 

>From fab9765fdaa7d4712d0bf3b4b8068d02f4dd73c2 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Sat, 15 Jul 2023 13:47:41 +0200
Subject: [PATCH] Updated JSX support due to changes in tree-sitter-javascript

A recent change in tree-sitter-javascript grammar support for
JSX (commit bb1f97b), changed two things:
1. renamed nested_identifier to member_expression
2. removed jsx_fragment, jsx_text is used instead

* lisp/progmodes/js-ts-mode.el: (js--treesit-font-lock-settings):
replace nested_identifier with member_expression
* lisp/progmodes/js-ts-mode.el: (js--treesit-indent-rules): replace
jsx_fragment with jsx_text
---
 lisp/progmodes/js.el | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index de1a820ba11..7ee72a22daa 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3462,8 +3462,8 @@ js--treesit-indent-rules
        ((parent-is "statement_block") parent-bol js-indent-level)
 
        ;; JSX
-       ((match "<" "jsx_fragment") parent 0)
-       ((parent-is "jsx_fragment") parent js-indent-level)
+       ((match "<" "jsx_text") parent 0)
+       ((parent-is "jsx_text") parent js-indent-level)
        ((node-is "jsx_closing_element") parent 0)
        ((match "jsx_element" "statement") parent js-indent-level)
        ((parent-is "jsx_element") parent js-indent-level)
@@ -3600,15 +3600,15 @@ js--treesit-font-lock-settings
    :language 'javascript
    :feature 'jsx
    '((jsx_opening_element
-      [(nested_identifier (identifier)) (identifier)]
+      [(member_expression (identifier)) (identifier)]
       @font-lock-function-call-face)
 
      (jsx_closing_element
-      [(nested_identifier (identifier)) (identifier)]
+      [(member_expression (identifier)) (identifier)]
       @font-lock-function-call-face)
 
      (jsx_self_closing_element
-      [(nested_identifier (identifier)) (identifier)]
+      [(member_expression (identifier)) (identifier)]
       @font-lock-function-call-face)
 
      (jsx_attribute
-- 
2.41.0