From unknown Sat Aug 16 21:19:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#65234: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars Resent-From: Danny Freeman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 11 Aug 2023 21:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 65234 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 65234@debbugs.gnu.org Cc: Vincenzo Pupillo , Daniel Colascione X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16917896773703 (code B ref -1); Fri, 11 Aug 2023 21:35:01 +0000 Received: (at submit) by debbugs.gnu.org; 11 Aug 2023 21:34:37 +0000 Received: from localhost ([127.0.0.1]:48191 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUZmF-0000xZ-Of for submit@debbugs.gnu.org; Fri, 11 Aug 2023 17:34:37 -0400 Received: from lists.gnu.org ([2001:470:142::17]:55404) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUZmA-0000wz-HA for submit@debbugs.gnu.org; Fri, 11 Aug 2023 17:34:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUZm5-0002Zt-2y for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 17:34:25 -0400 Received: from out-121.mta1.migadu.com ([95.215.58.121]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUZm2-00019S-0a for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 17:34:24 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dfreeman.email; s=key1; t=1691789655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=erxApkNBrKmITHtMOPH3F2CjN8ORL6TDnT+z3v2krIE=; b=PZBZoZy7V9DkeBgtD/w6uEm6G5x8j5OILbX813RdNroE90U/KKEzjZx+b9yEphPgZdmd8R NaC7qNVUuZHCj0Qkb6uYkIXiDeRaX5ill1TTfMEt4sES4gDaA1o3IjxBwORzqRWYfRY7Io /hZUU09ck5zDQsC5WgcNlWeOUG1S1h8= From: Danny Freeman Date: Fri, 11 Aug 2023 17:18:32 -0400 Message-ID: <87jzu1p8kt.fsf@dfreeman.email> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=95.215.58.121; envelope-from=danny@dfreeman.email; helo=out-121.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) --=-=-= Content-Type: text/plain I have a patch to fix a bug I found in js-ts-mode. Description of Problem: A new function was wrtiten to account for a breaking change in the tree-sitter-javascript grammar, see [0] This function returns some tree-sitter queries used by the js-ts-mode font lock settings. We attempted to check for the breaking change by running a query (treesit-query-capture 'javascript '((member_expression) @capture)) which would in theory fail when an old grammar is being used. The problem is that this query does not fail on old grammars, so the backwards incompatible font-lock queries are always used. When font-locking a JSX file, the queries that look like (jsx_opening_element [(member_expression) ... throw errors and font locking fails (only on jsx elements). Solution: Instead of fixing the bb1f97b compatibility check with something like (treesit-query-capture 'javascript '((jsx_opening_element (member_expression) @capture))) I have opted re-write the font lock rules that capture the same nodes by the "name:" field instead of by the specific node names (where the backwards incompatible change took place). The possible nodes that can be in the "name" field: After [1]: "identifier" "member_expression" "jsx_namespace_name" Before [2]: "identifier" "nested_identifier" "jsx_namespace_name" "jsx_namespace_name" is an additional node captured by these rules. As an example, in the JSX expression "Foo:bar" is a node of type "jsx_namespace_name" and would be captured with @font-lock-function-call-face, where before this change it was not captured or highlighted at all. If there is a reason this should not be captured and highlighted, a new query can be added in to capture these nodes first with @default so they are not highlighted like before. Some thoughts: These backwards incompatible grammar changes are rough to deal with, but I'm glad they are taken into account. I use nixos, and the current stable version 23.05 packages the older version of the JS grammar for emacs which is how I noticed this. I wish the developers of the js grammar were more careful about backwards compatible changes. The fact that they were renaming a node without much reason didn't seem to bother any of the maintainers. --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Fix-jsx-font-lock-in-older-tree-sitter-js-grammars.patch >From ab7e8c1e7120fa129840e4951803542509bee116 Mon Sep 17 00:00:00 2001 From: dannyfreeman Date: Fri, 11 Aug 2023 16:43:58 -0400 Subject: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars * lisp/progmodes/js.el (js--treesit-font-lock-settings): Use queries that are backwards compatible with tree-sitter-javascript bb1f97b * list/progmodes/js.el (-jsx--treesit-font-lock-compatibility-bb1f97b): deleted unused function --- lisp/progmodes/js.el | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index c583b6f6191..9d2990e7bc9 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3501,35 +3501,6 @@ js--treesit-operators "&&" "||" "!") "JavaScript operators for tree-sitter font-locking.") -(defun js-jsx--treesit-font-lock-compatibility-bb1f97b () - "Font lock rules helper, to handle different releases of tree-sitter-javascript. -Check if a node type is available, then return the right font lock rules." - ;; handle commit bb1f97b - (condition-case nil - (progn (treesit-query-capture 'javascript '((member_expression) @capture)) - '((jsx_opening_element - [(member_expression (identifier)) (identifier)] - @font-lock-function-call-face) - - (jsx_closing_element - [(member_expression (identifier)) (identifier)] - @font-lock-function-call-face) - - (jsx_self_closing_element - [(member_expression (identifier)) (identifier)] - @font-lock-function-call-face))) - (error '((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))))) - (defvar js--treesit-font-lock-settings (treesit-font-lock-rules @@ -3639,8 +3610,10 @@ js--treesit-font-lock-settings :language 'javascript :feature 'jsx - (append (js-jsx--treesit-font-lock-compatibility-bb1f97b) - '((jsx_attribute (property_identifier) @font-lock-constant-face))) + '((jsx_opening_element name: (_) @font-lock-function-call-face) + (jsx_closing_element name: (_) @font-lock-function-call-face) + (jsx_self_closing_element name: (_) @font-lock-function-call-face) + (jsx_attribute (property_identifier) @font-lock-constant-face)) :language 'javascript :feature 'number -- 2.40.1 --=-=-= Content-Type: text/plain Sources [0]: https://github.com/tree-sitter/tree-sitter-javascript/commit/bb1f97b643b77fc1f082d621bf533b4b14cf0c30 [1]: https://github.com/tree-sitter/tree-sitter-javascript/blob/bb1f97b643b77fc1f082d621bf533b4b14cf0c30/grammar.js#L637-L641 [2]: https://github.com/tree-sitter/tree-sitter-javascript/blob/5720b249490b3c17245ba772f6be4a43edb4e3b7/grammar.js#L635-L639 Thank you, -- Danny Freeman --=-=-=-- From unknown Sat Aug 16 21:19:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#65234: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 12 Aug 2023 05:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65234 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Danny Freeman , Yuan Fu , Theodor Thornhill Cc: 65234@debbugs.gnu.org, v.pupillo@gmail.com, dancol@dancol.org Received: via spool by 65234-submit@debbugs.gnu.org id=B65234.16918188864695 (code B ref 65234); Sat, 12 Aug 2023 05:42:02 +0000 Received: (at 65234) by debbugs.gnu.org; 12 Aug 2023 05:41:26 +0000 Received: from localhost ([127.0.0.1]:48442 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUhNN-0001Dd-S8 for submit@debbugs.gnu.org; Sat, 12 Aug 2023 01:41:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53936) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUhNL-0001DM-FU for 65234@debbugs.gnu.org; Sat, 12 Aug 2023 01:41:24 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUhNF-0002rI-6H; Sat, 12 Aug 2023 01:41:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=yyRNjtJlAYhHbg/LJCOdS87x1fSGf3VEdBqfUaCUwyY=; b=fsdzXnyURwNh 1bcfNnhu+4j+Q9+RKfD99cPCyYwN+Qu3WXQkXXVmJPWElsDGncvQ8TcGQPkXkZS4Ub0CPRWbOGb8y aUehcpCMLdpeto0v1vf44q2+Yf4Vse/5gzlN60G75A21CmYpb1qkDM8IHsNeZjhcacShZ/7qvpksT +tV2nZHXLwu/SKb6qaYxOwMvGlVpwV1W9W/vNjszQ6Y273KchEdVq3R3lw23hUVysJulxHwokULyg s0HHahl9X4Z5fVJeUBL5xJSmeDJEt1F5q/ivi1yhAIQYooV38Xd5CjmQKvB2i4rawqlRSeXTeVSrM B79T5ELpAgnW0U2cNdqa5A==; Date: Sat, 12 Aug 2023 08:41:45 +0300 Message-Id: <83sf8og6li.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <87jzu1p8kt.fsf@dfreeman.email> (bug-gnu-emacs@gnu.org) References: <87jzu1p8kt.fsf@dfreeman.email> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: Vincenzo Pupillo , > Daniel Colascione > Date: Fri, 11 Aug 2023 17:18:32 -0400 > From: Danny Freeman via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > I have a patch to fix a bug I found in js-ts-mode. > > Description of Problem: > A new function was wrtiten to account for a breaking change in the > tree-sitter-javascript grammar, see [0] > > This function returns some tree-sitter queries used by the js-ts-mode > font lock settings. > > We attempted to check for the breaking change by running a query > (treesit-query-capture 'javascript '((member_expression) @capture)) > which would in theory fail when an old grammar is being used. > > The problem is that this query does not fail on old grammars, so the > backwards incompatible font-lock queries are always used. When > font-locking a JSX file, the queries that look like > (jsx_opening_element [(member_expression) ... > throw errors and font locking fails (only on jsx elements). > > Solution: > Instead of fixing the bb1f97b compatibility check with something like > > (treesit-query-capture 'javascript > '((jsx_opening_element (member_expression) @capture))) > > I have opted re-write the font lock rules that capture the same > nodes by the "name:" field instead of by the specific node names (where > the backwards incompatible change took place). > > The possible nodes that can be in the "name" field: > After [1]: "identifier" "member_expression" "jsx_namespace_name" > Before [2]: "identifier" "nested_identifier" "jsx_namespace_name" > > "jsx_namespace_name" is an additional node captured by these rules. As > an example, in the JSX expression > > > > "Foo:bar" is a node of type "jsx_namespace_name" and would be captured > with @font-lock-function-call-face, where before this change it was not > captured or highlighted at all. If there is a reason this should not be > captured and highlighted, a new query can be added in to capture these > nodes first with @default so they are not highlighted like before. > > Some thoughts: > These backwards incompatible grammar changes are rough to deal with, but > I'm glad they are taken into account. I use nixos, and the current > stable version 23.05 packages the older version of the JS grammar for > emacs which is how I noticed this. I wish the developers of the js > grammar were more careful about backwards compatible changes. The fact > that they were renaming a node without much reason didn't seem to bother > any of the maintainers. Yuan, Theo: any comments on this? Is this safe enough to go into the emacs-29 branch? Thanks. From unknown Sat Aug 16 21:19:20 2025 X-Loop: help-debbugs@gnu.org Subject: bug#65234: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 16 Aug 2023 02:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65234 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii , Danny Freeman , Yuan Fu , Theodor Thornhill Cc: 65234@debbugs.gnu.org, v.pupillo@gmail.com, dancol@dancol.org Received: via spool by 65234-submit@debbugs.gnu.org id=B65234.169215146210008 (code B ref 65234); Wed, 16 Aug 2023 02:05:01 +0000 Received: (at 65234) by debbugs.gnu.org; 16 Aug 2023 02:04:22 +0000 Received: from localhost ([127.0.0.1]:38459 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qW5tV-0002bM-Ml for submit@debbugs.gnu.org; Tue, 15 Aug 2023 22:04:21 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:50555) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qW5tU-0002b7-51 for 65234@debbugs.gnu.org; Tue, 15 Aug 2023 22:04:20 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 0695B5C03B0; Tue, 15 Aug 2023 22:04:14 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 15 Aug 2023 22:04:14 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1692151454; x=1692237854; bh=7wlVB05BaRQ0UXoUBXr1Sjj0X+deHX+jBYd 1tGuufHg=; b=HVhvYxogC0MxYMfByRS9w8m802U+f24b6iRu08KKEpjaIXhup0F VKFMtQp0eOn5u21e3me323I5t2iCPQF7NUEfUsoiVxRO/eH+us59zpfkVdQeyDEl pt4d9zrT1u/Lko3F3TQCppGSXpRYgkPKzigGiMul+P363cjxJrCx4b16vo5214k/ AnWV/tOek3UjvvbuW/O8qJmm6xzPguOOtVGI24vLDn0cAHY7Ijd2QR4T/fmGgXxk LdWHKrsB2A709H0SYOQb5mLgYbDdYy8QViqKHsKTpxZMPY/KUX6TJ8QrWo6fOV2E U3F4W6iI/vijVd7eWlOKXOp0elQHHi1in/w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1692151454; x=1692237854; bh=7wlVB05BaRQ0UXoUBXr1Sjj0X+deHX+jBYd 1tGuufHg=; b=WFHc30woW50CATh3idim0yRznGXPpIRAZXWv3R5Zk/dvD+6QwC4 Oc1Nz4+9/NypiLCWfeoVGxiwd+p0YI56ai7uOjXLcW8wxWRogwUbTNlfluYNAVIL HEb0Ycl+2WT/dS+mSvPNdNpTXFURZ6eUnoJHVEMpleHtXqO59R2aQvS5whHxc8yA XHrgBcxxcxetfO1MgtbxbE9hR83wVZLmmXVlIhcYtxLOodOSccKHVEgtBdsehN8w ym6dRxDQjZQd4FkZUCCulrGAPS15qde+joCH6dt580vGbi4iaJE7VLSX5BBjfWmd gEj8L1Cb0DGaeUaZPcMEwo7aQlP/Ae9HIhw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedruddtkedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpeffmhhi thhrhicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrth htvghrnhepiefgteevheevveffheeltdeukeeiieekueefgedugfefgefhudelgfefveel vdevnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepug hmihhtrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 15 Aug 2023 22:04:11 -0400 (EDT) Message-ID: Date: Wed, 16 Aug 2023 05:04:10 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US References: <87jzu1p8kt.fsf@dfreeman.email> <83sf8og6li.fsf@gnu.org> From: Dmitry Gutov In-Reply-To: <83sf8og6li.fsf@gnu.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -1.7 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.7 (--) On 12/08/2023 08:41, Eli Zaretskii wrote: > Yuan, Theo: any comments on this? Is this safe enough to go into the > emacs-29 branch? It looks good to me (and works okay too). I also saw the same error in my testing. Especially since Emacs 29.2 is not quite imminent, I think it's a good idea to install this: queries are simpler and thus more reliable. And the fixed-fix, of course. From unknown Sat Aug 16 21:19:20 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Danny Freeman Subject: bug#65234: closed (Re: bug#65234: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars) Message-ID: References: <83zg2q5bze.fsf@gnu.org> <87jzu1p8kt.fsf@dfreeman.email> X-Gnu-PR-Message: they-closed 65234 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 65234@debbugs.gnu.org Date: Thu, 17 Aug 2023 08:08:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1692259682-24598-1" This is a multi-part message in MIME format... ------------=_1692259682-24598-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #65234: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars 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 65234@debbugs.gnu.org. --=20 65234: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D65234 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1692259682-24598-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 65234-done) by debbugs.gnu.org; 17 Aug 2023 08:07:04 +0000 Received: from localhost ([127.0.0.1]:42717 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWY1o-0006Mr-Sn for submit@debbugs.gnu.org; Thu, 17 Aug 2023 04:07:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54608) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWY1m-0006Mc-QV for 65234-done@debbugs.gnu.org; Thu, 17 Aug 2023 04:06:47 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWY1g-0004eF-47; Thu, 17 Aug 2023 04:06:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=I/NsV04u1SbmXTRCVoKdSl45cPI1eGFNrxiXJ7zFuNE=; b=e2yxk0EyO6Wx W5Ot3w7cyGX58lyr6gQTJNhnlyu6sEuicjPNsnQESyQC0LfJqAt50i0XbUnzPQn1rFVX7RF4ZnpgI ExqV6CmYKzIn1Zhdu+PurtZ/mT2Tv/g7hZIV7fChgiLXtaufj+T+Tk9ZPLl+BlOsbOZihK4h41q3U qGQ0wKUBzQLxtOH5Sv7ZTbMtuYtd36uRpP+yILWKh5CpIdQnfyaTfxsYdCbTGymT6T5V7ls3ghPBq 4pjC4B/lVgHqtJr0DDRupPQBnKXVOHQBlz7YwX+spi/GCyMBYTP3APYHTzUVGKTORYwaAVy1y4Zs+ 8DUc6j1B+7necTmSkvherw==; Date: Thu, 17 Aug 2023 11:06:45 +0300 Message-Id: <83zg2q5bze.fsf@gnu.org> From: Eli Zaretskii To: Dmitry Gutov In-Reply-To: (message from Dmitry Gutov on Wed, 16 Aug 2023 05:04:10 +0300) Subject: Re: bug#65234: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars References: <87jzu1p8kt.fsf@dfreeman.email> <83sf8og6li.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 65234-done Cc: casouri@gmail.com, 65234-done@debbugs.gnu.org, danny@dfreeman.email, v.pupillo@gmail.com, theo@thornhill.no, dancol@dancol.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) > Date: Wed, 16 Aug 2023 05:04:10 +0300 > Cc: 65234@debbugs.gnu.org, v.pupillo@gmail.com, dancol@dancol.org > From: Dmitry Gutov > > On 12/08/2023 08:41, Eli Zaretskii wrote: > > Yuan, Theo: any comments on this? Is this safe enough to go into the > > emacs-29 branch? > > It looks good to me (and works okay too). I also saw the same error in > my testing. > > Especially since Emacs 29.2 is not quite imminent, I think it's a good > idea to install this: queries are simpler and thus more reliable. And > the fixed-fix, of course. Thanks, installed on the emacs-29 branch, and closing the bug. ------------=_1692259682-24598-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 11 Aug 2023 21:34:37 +0000 Received: from localhost ([127.0.0.1]:48191 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUZmF-0000xZ-Of for submit@debbugs.gnu.org; Fri, 11 Aug 2023 17:34:37 -0400 Received: from lists.gnu.org ([2001:470:142::17]:55404) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUZmA-0000wz-HA for submit@debbugs.gnu.org; Fri, 11 Aug 2023 17:34:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUZm5-0002Zt-2y for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 17:34:25 -0400 Received: from out-121.mta1.migadu.com ([95.215.58.121]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qUZm2-00019S-0a for bug-gnu-emacs@gnu.org; Fri, 11 Aug 2023 17:34:24 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dfreeman.email; s=key1; t=1691789655; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=erxApkNBrKmITHtMOPH3F2CjN8ORL6TDnT+z3v2krIE=; b=PZBZoZy7V9DkeBgtD/w6uEm6G5x8j5OILbX813RdNroE90U/KKEzjZx+b9yEphPgZdmd8R NaC7qNVUuZHCj0Qkb6uYkIXiDeRaX5ill1TTfMEt4sES4gDaA1o3IjxBwORzqRWYfRY7Io /hZUU09ck5zDQsC5WgcNlWeOUG1S1h8= From: Danny Freeman To: bug-gnu-emacs@gnu.org Subject: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars Date: Fri, 11 Aug 2023 17:18:32 -0400 Message-ID: <87jzu1p8kt.fsf@dfreeman.email> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=95.215.58.121; envelope-from=danny@dfreeman.email; helo=out-121.mta1.migadu.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit Cc: Vincenzo Pupillo , Daniel Colascione X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) --=-=-= Content-Type: text/plain I have a patch to fix a bug I found in js-ts-mode. Description of Problem: A new function was wrtiten to account for a breaking change in the tree-sitter-javascript grammar, see [0] This function returns some tree-sitter queries used by the js-ts-mode font lock settings. We attempted to check for the breaking change by running a query (treesit-query-capture 'javascript '((member_expression) @capture)) which would in theory fail when an old grammar is being used. The problem is that this query does not fail on old grammars, so the backwards incompatible font-lock queries are always used. When font-locking a JSX file, the queries that look like (jsx_opening_element [(member_expression) ... throw errors and font locking fails (only on jsx elements). Solution: Instead of fixing the bb1f97b compatibility check with something like (treesit-query-capture 'javascript '((jsx_opening_element (member_expression) @capture))) I have opted re-write the font lock rules that capture the same nodes by the "name:" field instead of by the specific node names (where the backwards incompatible change took place). The possible nodes that can be in the "name" field: After [1]: "identifier" "member_expression" "jsx_namespace_name" Before [2]: "identifier" "nested_identifier" "jsx_namespace_name" "jsx_namespace_name" is an additional node captured by these rules. As an example, in the JSX expression "Foo:bar" is a node of type "jsx_namespace_name" and would be captured with @font-lock-function-call-face, where before this change it was not captured or highlighted at all. If there is a reason this should not be captured and highlighted, a new query can be added in to capture these nodes first with @default so they are not highlighted like before. Some thoughts: These backwards incompatible grammar changes are rough to deal with, but I'm glad they are taken into account. I use nixos, and the current stable version 23.05 packages the older version of the JS grammar for emacs which is how I noticed this. I wish the developers of the js grammar were more careful about backwards compatible changes. The fact that they were renaming a node without much reason didn't seem to bother any of the maintainers. --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Fix-jsx-font-lock-in-older-tree-sitter-js-grammars.patch >From ab7e8c1e7120fa129840e4951803542509bee116 Mon Sep 17 00:00:00 2001 From: dannyfreeman Date: Fri, 11 Aug 2023 16:43:58 -0400 Subject: [PATCH] Fix jsx font-lock in older tree-sitter-js grammars * lisp/progmodes/js.el (js--treesit-font-lock-settings): Use queries that are backwards compatible with tree-sitter-javascript bb1f97b * list/progmodes/js.el (-jsx--treesit-font-lock-compatibility-bb1f97b): deleted unused function --- lisp/progmodes/js.el | 35 ++++------------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index c583b6f6191..9d2990e7bc9 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3501,35 +3501,6 @@ js--treesit-operators "&&" "||" "!") "JavaScript operators for tree-sitter font-locking.") -(defun js-jsx--treesit-font-lock-compatibility-bb1f97b () - "Font lock rules helper, to handle different releases of tree-sitter-javascript. -Check if a node type is available, then return the right font lock rules." - ;; handle commit bb1f97b - (condition-case nil - (progn (treesit-query-capture 'javascript '((member_expression) @capture)) - '((jsx_opening_element - [(member_expression (identifier)) (identifier)] - @font-lock-function-call-face) - - (jsx_closing_element - [(member_expression (identifier)) (identifier)] - @font-lock-function-call-face) - - (jsx_self_closing_element - [(member_expression (identifier)) (identifier)] - @font-lock-function-call-face))) - (error '((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))))) - (defvar js--treesit-font-lock-settings (treesit-font-lock-rules @@ -3639,8 +3610,10 @@ js--treesit-font-lock-settings :language 'javascript :feature 'jsx - (append (js-jsx--treesit-font-lock-compatibility-bb1f97b) - '((jsx_attribute (property_identifier) @font-lock-constant-face))) + '((jsx_opening_element name: (_) @font-lock-function-call-face) + (jsx_closing_element name: (_) @font-lock-function-call-face) + (jsx_self_closing_element name: (_) @font-lock-function-call-face) + (jsx_attribute (property_identifier) @font-lock-constant-face)) :language 'javascript :feature 'number -- 2.40.1 --=-=-= Content-Type: text/plain Sources [0]: https://github.com/tree-sitter/tree-sitter-javascript/commit/bb1f97b643b77fc1f082d621bf533b4b14cf0c30 [1]: https://github.com/tree-sitter/tree-sitter-javascript/blob/bb1f97b643b77fc1f082d621bf533b4b14cf0c30/grammar.js#L637-L641 [2]: https://github.com/tree-sitter/tree-sitter-javascript/blob/5720b249490b3c17245ba772f6be4a43edb4e3b7/grammar.js#L635-L639 Thank you, -- Danny Freeman --=-=-=-- ------------=_1692259682-24598-1--