]> git.eshelyaron.com Git - emacs.git/commitdiff
js-ts-mode: Highlight property shorthands in assignments
authorDmitry Gutov <dmitry@gutov.dev>
Fri, 8 Dec 2023 02:12:21 +0000 (04:12 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 9 Dec 2023 19:12:35 +0000 (20:12 +0100)
* lisp/progmodes/js.el (js--treesit-lhs-identifier-query): Match
property shorthands (which turn into variable reference).
(js--treesit-fontify-assignment-lhs): Use the matches.

lisp/progmodes/js.el

index 7b0fcb508531bf76d2f36f5aef195d2cdbbb1494..5570cca42c675ec039f896ebaf047721b8aea6a0 100644 (file)
@@ -3655,7 +3655,8 @@ OVERRIDE is the override flag described in
 (defvar js--treesit-lhs-identifier-query
   (when (treesit-available-p)
     (treesit-query-compile 'javascript '((identifier) @id
-                                         (property_identifier) @id)))
+                                         (property_identifier) @id
+                                         (shorthand_property_identifier_pattern) @id)))
   "Query that captures identifier and query_identifier.")
 
 (defun js--treesit-fontify-assignment-lhs (node override start end &rest _)
@@ -3667,7 +3668,8 @@ For OVERRIDE, START, END, see `treesit-font-lock-rules'."
      (treesit-node-start node) (treesit-node-end node)
      (pcase (treesit-node-type node)
        ("identifier" 'font-lock-variable-use-face)
-       ("property_identifier" 'font-lock-property-use-face))
+       ("property_identifier" 'font-lock-property-use-face)
+       ("shorthand_property_identifier_pattern" 'font-lock-variable-use-face))
      override start end)))
 
 (defun js--treesit-defun-name (node)