emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 00629c0396 2/2: Fix errors in fontification of JavaScript impor


From: Theodor Thornhill
Subject: emacs-29 00629c0396 2/2: Fix errors in fontification of JavaScript import-statements (bug#61083)
Date: Fri, 27 Jan 2023 07:52:07 -0500 (EST)

branch: emacs-29
commit 00629c039643a0471143205c70e8a078fc3a9d86
Author: Jostein Kjønigsen <jostein@kjonigsen.net>
Commit: Theodor Thornhill <theo@thornhill.no>

    Fix errors in fontification of JavaScript import-statements (bug#61083)
    
    Currently js-ts-mode handles imports with aliases incorrectly. To be
    consistent with how we otherwise do things, we should only highlight
    the variable which is new and/or introduced, in this case "someAlias".
    
    Attached is a patch which fontifies import-declarations somewhat more
    correctly.
    
    The following cases have been tested and all fontify properly:
    
    import gnu from "fsf";              // highlights gnu
    import { gnu2 } from "fsf2";        // highlights gnu2
    import { gnu as gnu3 } from "fsf3"; // highlights gnu3
    import * as gnu4 from "fsf4";       // highlights gnu4
    
    * lisp/progmodes/js.el (js--treesit-font-lock-settings): Add new
    import_clause rules that adhere to the comment above.
---
 lisp/progmodes/js.el | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index b5c912b8b0..05d69c314b 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -3546,9 +3546,18 @@ This function is intended for use in 
`after-change-functions'."
              (identifier)
              @font-lock-function-name-face)
       value: (array (number) (function)))
+     ;; full module imports
      (import_clause (identifier) @font-lock-variable-name-face)
-     (import_clause (named_imports (import_specifier (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 'javascript
    :feature 'property



reply via email to

[Prev in Thread] Current Thread [Next in Thread]