all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#69024: [PATCH] Breaking change in tree-sitter-typescript/tsx starting version 0.20.4
@ 2024-02-10 23:38 Loïc Lemaître
  2024-02-11  3:02 ` Dmitry Gutov
  0 siblings, 1 reply; 6+ messages in thread
From: Loïc Lemaître @ 2024-02-10 23:38 UTC (permalink / raw)
  To: 69024

[-- Attachment #1: Type: text/plain, Size: 234 bytes --]

Hi,

A similar patch is also needed for Typescript/TSX in relation to this 
closed bug in Javascript :
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68879

The attached patch should do the job.

Thank you in advance.

Loïc Lemaître

[-- Attachment #2: 0001-Handle-tree-sitter-grammar-breaking-change-for-funct.patch --]
[-- Type: text/x-patch, Size: 14276 bytes --]

From 4b7fb0045e67180a4cfe15a11b1a72772fcc7f04 Mon Sep 17 00:00:00 2001
From: Loic Lemaitre <loic.lemaitre@gmail.com>
Date: Sun, 11 Feb 2024 00:11:32 +0100
Subject: [PATCH] Handle tree-sitter grammar breaking change for "function"
 expression.

Starting from version 0.20.4 of the typescript/tsx grammar, "function"
becomes "function_expression". The right expression is used depending
on the grammar version.
---
 lisp/progmodes/typescript-ts-mode.el | 362 ++++++++++++++-------------
 1 file changed, 188 insertions(+), 174 deletions(-)

diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el
index 89ca47571eb..7021f012dcd 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -199,183 +199,197 @@ tsx-ts-mode--font-lock-compatibility-bb1f97b
 	      [(nested_identifier (identifier)) (identifier)]
 	      @typescript-ts-jsx-tag-face)))))
 
+(defun tsx-ts-mode--font-lock-compatibility-function-expression (language)
+  "Handle tree-sitter grammar breaking change for `function' expression.
+
+LANGUAGE can be `typescript' or `tsx'.  Starting from version 0.20.4 of the
+typescript/tsx grammar, `function' becomes `function_expression'."
+  (condition-case nil
+      (progn (treesit-query-capture language '((function_expression) @cap))
+             ;; New version of the grammar
+             'function_expression)
+    (treesit-query-error
+    ;; Old version of the grammar
+    'function)))
+
 (defun typescript-ts-mode--font-lock-settings (language)
   "Tree-sitter font-lock settings.
 Argument LANGUAGE is either `typescript' or `tsx'."
-  (treesit-font-lock-rules
-   :language language
-   :feature 'comment
-   `([(comment) (hash_bang_line)] @font-lock-comment-face)
-
-   :language language
-   :feature 'constant
-   `(((identifier) @font-lock-constant-face
-      (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
-     [(true) (false) (null)] @font-lock-constant-face)
-
-   :language language
-   :feature 'keyword
-   `([,@typescript-ts-mode--keywords] @font-lock-keyword-face
-     [(this) (super)] @font-lock-keyword-face)
-
-   :language language
-   :feature 'string
-   `((regex pattern: (regex_pattern)) @font-lock-regexp-face
-     (string) @font-lock-string-face
-     (template_string) @js--fontify-template-string
-     (template_substitution ["${" "}"] @font-lock-misc-punctuation-face))
-
-   :language language
-   :override t ;; for functions assigned to variables
-   :feature 'declaration
-   `((function
-      name: (identifier) @font-lock-function-name-face)
-     (function_declaration
-      name: (identifier) @font-lock-function-name-face)
-     (function_signature
-      name: (identifier) @font-lock-function-name-face)
-
-     (method_definition
-      name: (property_identifier) @font-lock-function-name-face)
-     (method_signature
-      name: (property_identifier) @font-lock-function-name-face)
-     (required_parameter (identifier) @font-lock-variable-name-face)
-     (optional_parameter (identifier) @font-lock-variable-name-face)
-
-     (variable_declarator
-      name: (identifier) @font-lock-function-name-face
-      value: [(function) (arrow_function)])
-
-     (variable_declarator
-      name: (identifier) @font-lock-variable-name-face)
-
-     (enum_declaration (identifier) @font-lock-type-face)
-
-     (extends_clause value: (identifier) @font-lock-type-face)
-     ;; extends React.Component<T>
-     (extends_clause value: (member_expression
-                             object: (identifier) @font-lock-type-face
-                             property: (property_identifier) @font-lock-type-face))
-
-     (arrow_function
-      parameter: (identifier) @font-lock-variable-name-face)
-
-     (variable_declarator
-      name: (array_pattern
-             (identifier)
-             (identifier) @font-lock-function-name-face)
-      value: (array (number) (function)))
-
-     (catch_clause
-      parameter: (identifier) @font-lock-variable-name-face)
-
-     ;; full module imports
-     (import_clause (identifier) @font-lock-variable-name-face)
-     ;; named imports with aliasing
-     (import_clause (named_imports (import_specifier
-                                    alias: (identifier) @font-lock-variable-name-face)))
-     ;; named imports without aliasing
-     (import_clause (named_imports (import_specifier
-                                    !alias
-                                    name: (identifier) @font-lock-variable-name-face)))
-
-     ;; full namespace import (* as alias)
-     (import_clause (namespace_import (identifier) @font-lock-variable-name-face)))
-
-   :language language
-   :feature 'identifier
-   `((nested_type_identifier
-      module: (identifier) @font-lock-type-face)
-
-     (type_identifier) @font-lock-type-face
-
-     (predefined_type) @font-lock-type-face
-
-     (new_expression
-      constructor: (identifier) @font-lock-type-face)
-
-     (enum_body (property_identifier) @font-lock-type-face)
-
-     (enum_assignment name: (property_identifier) @font-lock-type-face)
-
-     (variable_declarator
-      name: (identifier) @font-lock-variable-name-face)
-
-     (for_in_statement
-      left: (identifier) @font-lock-variable-name-face)
-
-     (arrow_function
-      parameters:
-      [(_ (identifier) @font-lock-variable-name-face)
-       (_ (_ (identifier) @font-lock-variable-name-face))
-       (_ (_ (_ (identifier) @font-lock-variable-name-face)))]))
-
-   :language language
-   :feature 'property
-   `((property_signature
-      name: (property_identifier) @font-lock-property-name-face)
-     (public_field_definition
-      name: (property_identifier) @font-lock-property-name-face)
-
-     (pair key: (property_identifier) @font-lock-property-use-face)
-
-     ((shorthand_property_identifier) @font-lock-property-use-face))
-
-   :language language
-   :feature 'expression
-   '((assignment_expression
-      left: [(identifier) @font-lock-function-name-face
-             (member_expression
-              property: (property_identifier) @font-lock-function-name-face)]
-      right: [(function) (arrow_function)]))
-
-   :language language
-   :feature 'function
-   '((call_expression
-      function:
-      [(identifier) @font-lock-function-call-face
-       (member_expression
-        property: (property_identifier) @font-lock-function-call-face)]))
-
-   :language language
-   :feature 'pattern
-   `((pair_pattern
-      key: (property_identifier) @font-lock-property-use-face
-      value: [(identifier) @font-lock-variable-name-face
-              (assignment_pattern left: (identifier) @font-lock-variable-name-face)])
-
-     (array_pattern (identifier) @font-lock-variable-name-face)
-
-     ((shorthand_property_identifier_pattern) @font-lock-variable-name-face))
-
-   :language language
-   :feature 'jsx
-   (append (tsx-ts-mode--font-lock-compatibility-bb1f97b language)
-	   `((jsx_attribute (property_identifier) @typescript-ts-jsx-attribute-face)))
-
-   :language language
-   :feature 'number
-   `((number) @font-lock-number-face
-     ((identifier) @font-lock-number-face
-      (:match "\\`\\(?:NaN\\|Infinity\\)\\'" @font-lock-number-face)))
-
-   :language language
-   :feature 'operator
-   `([,@typescript-ts-mode--operators] @font-lock-operator-face
-     (ternary_expression ["?" ":"] @font-lock-operator-face))
-
-   :language language
-   :feature 'bracket
-   '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
-
-   :language language
-   :feature 'delimiter
-   '((["," "." ";" ":"]) @font-lock-delimiter-face)
-
-   :language language
-   :feature 'escape-sequence
-   :override t
-   '((escape_sequence) @font-lock-escape-face)))
+  (let ((func-exp (tsx-ts-mode--font-lock-compatibility-function-expression language)))
+    (treesit-font-lock-rules
+     :language language
+     :feature 'comment
+     `([(comment) (hash_bang_line)] @font-lock-comment-face)
+
+     :language language
+     :feature 'constant
+     `(((identifier) @font-lock-constant-face
+        (:match "\\`[A-Z_][0-9A-Z_]*\\'" @font-lock-constant-face))
+       [(true) (false) (null)] @font-lock-constant-face)
+
+     :language language
+     :feature 'keyword
+     `([,@typescript-ts-mode--keywords] @font-lock-keyword-face
+       [(this) (super)] @font-lock-keyword-face)
+
+     :language language
+     :feature 'string
+     `((regex pattern: (regex_pattern)) @font-lock-regexp-face
+       (string) @font-lock-string-face
+       (template_string) @js--fontify-template-string
+       (template_substitution ["${" "}"] @font-lock-misc-punctuation-face))
+
+     :language language
+     :override t ;; for functions assigned to variables
+     :feature 'declaration
+     `((,func-exp
+        name: (identifier) @font-lock-function-name-face)
+       (function_declaration
+        name: (identifier) @font-lock-function-name-face)
+       (function_signature
+        name: (identifier) @font-lock-function-name-face)
+
+       (method_definition
+        name: (property_identifier) @font-lock-function-name-face)
+       (method_signature
+        name: (property_identifier) @font-lock-function-name-face)
+       (required_parameter (identifier) @font-lock-variable-name-face)
+       (optional_parameter (identifier) @font-lock-variable-name-face)
+
+       (variable_declarator
+        name: (identifier) @font-lock-function-name-face
+        value: [(,func-exp) (arrow_function)])
+
+       (variable_declarator
+        name: (identifier) @font-lock-variable-name-face)
+
+       (enum_declaration (identifier) @font-lock-type-face)
+
+       (extends_clause value: (identifier) @font-lock-type-face)
+       ;; extends React.Component<T>
+       (extends_clause value: (member_expression
+                               object: (identifier) @font-lock-type-face
+                               property: (property_identifier) @font-lock-type-face))
+
+       (arrow_function
+        parameter: (identifier) @font-lock-variable-name-face)
+
+       (variable_declarator
+        name: (array_pattern
+               (identifier)
+               (identifier) @font-lock-function-name-face)
+        value: (array (number) (,func-exp)))
+
+       (catch_clause
+        parameter: (identifier) @font-lock-variable-name-face)
+
+       ;; full module imports
+       (import_clause (identifier) @font-lock-variable-name-face)
+       ;; named imports with aliasing
+       (import_clause (named_imports (import_specifier
+                                      alias: (identifier) @font-lock-variable-name-face)))
+       ;; named imports without aliasing
+       (import_clause (named_imports (import_specifier
+                                      !alias
+                                      name: (identifier) @font-lock-variable-name-face)))
+
+       ;; full namespace import (* as alias)
+       (import_clause (namespace_import (identifier) @font-lock-variable-name-face)))
+
+     :language language
+     :feature 'identifier
+     `((nested_type_identifier
+        module: (identifier) @font-lock-type-face)
+
+       (type_identifier) @font-lock-type-face
+
+       (predefined_type) @font-lock-type-face
+
+       (new_expression
+        constructor: (identifier) @font-lock-type-face)
+
+       (enum_body (property_identifier) @font-lock-type-face)
+
+       (enum_assignment name: (property_identifier) @font-lock-type-face)
+
+       (variable_declarator
+        name: (identifier) @font-lock-variable-name-face)
+
+       (for_in_statement
+        left: (identifier) @font-lock-variable-name-face)
+
+       (arrow_function
+        parameters:
+        [(_ (identifier) @font-lock-variable-name-face)
+         (_ (_ (identifier) @font-lock-variable-name-face))
+         (_ (_ (_ (identifier) @font-lock-variable-name-face)))]))
+
+     :language language
+     :feature 'property
+     `((property_signature
+        name: (property_identifier) @font-lock-property-name-face)
+       (public_field_definition
+        name: (property_identifier) @font-lock-property-name-face)
+
+       (pair key: (property_identifier) @font-lock-property-use-face)
+
+       ((shorthand_property_identifier) @font-lock-property-use-face))
+
+     :language language
+     :feature 'expression
+     `((assignment_expression
+        left: [(identifier) @font-lock-function-name-face
+               (member_expression
+                property: (property_identifier) @font-lock-function-name-face)]
+        right: [(,func-exp) (arrow_function)]))
+
+     :language language
+     :feature 'function
+     '((call_expression
+        function:
+        [(identifier) @font-lock-function-call-face
+         (member_expression
+          property: (property_identifier) @font-lock-function-call-face)]))
+
+     :language language
+     :feature 'pattern
+     `((pair_pattern
+        key: (property_identifier) @font-lock-property-use-face
+        value: [(identifier) @font-lock-variable-name-face
+                (assignment_pattern left: (identifier) @font-lock-variable-name-face)])
+
+       (array_pattern (identifier) @font-lock-variable-name-face)
+
+       ((shorthand_property_identifier_pattern) @font-lock-variable-name-face))
+
+     :language language
+     :feature 'jsx
+     (append (tsx-ts-mode--font-lock-compatibility-bb1f97b language)
+	     `((jsx_attribute (property_identifier) @typescript-ts-jsx-attribute-face)))
+
+     :language language
+     :feature 'number
+     `((number) @font-lock-number-face
+       ((identifier) @font-lock-number-face
+        (:match "\\`\\(?:NaN\\|Infinity\\)\\'" @font-lock-number-face)))
+
+     :language language
+     :feature 'operator
+     `([,@typescript-ts-mode--operators] @font-lock-operator-face
+       (ternary_expression ["?" ":"] @font-lock-operator-face))
+
+     :language language
+     :feature 'bracket
+     '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
+
+     :language language
+     :feature 'delimiter
+     '((["," "." ";" ":"]) @font-lock-delimiter-face)
+
+     :language language
+     :feature 'escape-sequence
+     :override t
+     '((escape_sequence) @font-lock-escape-face))))
 
 ;;;###autoload
 (define-derived-mode typescript-ts-base-mode prog-mode "TypeScript"
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#69024: [PATCH] Breaking change in tree-sitter-typescript/tsx starting version 0.20.4
  2024-02-10 23:38 bug#69024: [PATCH] Breaking change in tree-sitter-typescript/tsx starting version 0.20.4 Loïc Lemaître
@ 2024-02-11  3:02 ` Dmitry Gutov
  2024-02-11  6:50   ` Eli Zaretskii
  2024-02-11 10:37   ` Loïc Lemaître
  0 siblings, 2 replies; 6+ messages in thread
From: Dmitry Gutov @ 2024-02-11  3:02 UTC (permalink / raw)
  To: Loïc Lemaître, 69024

Hi!

On 11/02/2024 01:38, Loïc Lemaître wrote:
> A similar patch is also needed for Typescript/TSX in relation to this 
> closed bug in Javascript :
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68879
> 
> The attached patch should do the job.

Thanks for the patch! Pushed to emacs-29.

It probably doesn't exhaust our capability to accept your patches 
without copyright assignment, but it would help if you can get started 
on it, to contribute more in the future.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69024: [PATCH] Breaking change in tree-sitter-typescript/tsx starting version 0.20.4
  2024-02-11  3:02 ` Dmitry Gutov
@ 2024-02-11  6:50   ` Eli Zaretskii
  2024-02-11 12:27     ` Dmitry Gutov
  2024-02-11 10:37   ` Loïc Lemaître
  1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2024-02-11  6:50 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: 69024, loic.lemaitre

> Date: Sun, 11 Feb 2024 05:02:17 +0200
> From: Dmitry Gutov <dmitry@gutov.dev>
> 
> On 11/02/2024 01:38, Loïc Lemaître wrote:
> > A similar patch is also needed for Typescript/TSX in relation to this 
> > closed bug in Javascript :
> > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68879
> > 
> > The attached patch should do the job.
> 
> Thanks for the patch! Pushed to emacs-29.

Should this bug be closed now?

And what about bug#68924 -- does this solve that one as well?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69024: [PATCH] Breaking change in tree-sitter-typescript/tsx starting version 0.20.4
  2024-02-11  3:02 ` Dmitry Gutov
  2024-02-11  6:50   ` Eli Zaretskii
@ 2024-02-11 10:37   ` Loïc Lemaître
  2024-02-11 11:38     ` Eli Zaretskii
  1 sibling, 1 reply; 6+ messages in thread
From: Loïc Lemaître @ 2024-02-11 10:37 UTC (permalink / raw)
  To: Dmitry Gutov, 69024

[-- Attachment #1: Type: text/plain, Size: 820 bytes --]

Thanks !

For the copyright assignment, I have read this page 
https://www.gnu.org/software/emacs/manual/html_node/emacs/Copyright-Assignment.html 
and I guess I should contact emacs-devel@gnu.org 
<mailto:emacs-devel@gnu.org> to better understand what is the process to 
get it.

Le 11/02/2024 à 04:02, Dmitry Gutov a écrit :
> Hi!
>
> On 11/02/2024 01:38, Loïc Lemaître wrote:
>> A similar patch is also needed for Typescript/TSX in relation to this 
>> closed bug in Javascript :
>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68879
>>
>> The attached patch should do the job.
>
> Thanks for the patch! Pushed to emacs-29.
>
> It probably doesn't exhaust our capability to accept your patches 
> without copyright assignment, but it would help if you can get started 
> on it, to contribute more in the future.

[-- Attachment #2: Type: text/html, Size: 1669 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69024: [PATCH] Breaking change in tree-sitter-typescript/tsx starting version 0.20.4
  2024-02-11 10:37   ` Loïc Lemaître
@ 2024-02-11 11:38     ` Eli Zaretskii
  0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2024-02-11 11:38 UTC (permalink / raw)
  To: Loïc Lemaître; +Cc: 69024, dmitry

> Date: Sun, 11 Feb 2024 11:37:29 +0100
> From: Loïc Lemaître
>  <loic.lemaitre@gmail.com>
> 
> For the copyright assignment, I have read this page
> https://www.gnu.org/software/emacs/manual/html_node/emacs/Copyright-Assignment.html and I guess I
> should contact emacs-devel@gnu.org to better understand what is the process to get it.

No need, I've sent the form off-list.

Thanks.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#69024: [PATCH] Breaking change in tree-sitter-typescript/tsx starting version 0.20.4
  2024-02-11  6:50   ` Eli Zaretskii
@ 2024-02-11 12:27     ` Dmitry Gutov
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Gutov @ 2024-02-11 12:27 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 69024-done, loic.lemaitre

On 11/02/2024 08:50, Eli Zaretskii wrote:
>> Date: Sun, 11 Feb 2024 05:02:17 +0200
>> From: Dmitry Gutov<dmitry@gutov.dev>
>>
>> On 11/02/2024 01:38, Loïc Lemaître wrote:
>>> A similar patch is also needed for Typescript/TSX in relation to this
>>> closed bug in Javascript :
>>> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=68879
>>>
>>> The attached patch should do the job.
>> Thanks for the patch! Pushed to emacs-29.
> Should this bug be closed now?
> 
> And what about bug#68924 -- does this solve that one as well?

Yep, closing.





^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-02-11 12:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-10 23:38 bug#69024: [PATCH] Breaking change in tree-sitter-typescript/tsx starting version 0.20.4 Loïc Lemaître
2024-02-11  3:02 ` Dmitry Gutov
2024-02-11  6:50   ` Eli Zaretskii
2024-02-11 12:27     ` Dmitry Gutov
2024-02-11 10:37   ` Loïc Lemaître
2024-02-11 11:38     ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.