emacs-diffs
[Top][All Lists]
Advanced

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

emacs-29 fd145499bb 1/2: Fix fontification TypeScript of import-statemen


From: Theodor Thornhill
Subject: emacs-29 fd145499bb 1/2: Fix fontification TypeScript of import-statements (bug#61081)
Date: Fri, 27 Jan 2023 07:52:06 -0500 (EST)

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

    Fix fontification TypeScript of import-statements (bug#61081)
    
    Currently typescript-ts-mode and tsx-ts-mode handles imports with
    aliases incorrectly.
    
    Consider the following case:
    
    import { someFunc as someAlias } from "module";
    
    In this case the entire import ("someFunc as someAlias") will be
    highlighted as a variable name. "as" is also highlighted as a
    variable, rather than a reserved keyword.
    
    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/typescript-ts-mode.el
    (typescript-ts-mode--font-lock-settings): Tweak import_clause rules to
    adhere to the comment above.
---
 lisp/progmodes/typescript-ts-mode.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/typescript-ts-mode.el 
b/lisp/progmodes/typescript-ts-mode.el
index 25cc327d05..561b90deed 100644
--- a/lisp/progmodes/typescript-ts-mode.el
+++ b/lisp/progmodes/typescript-ts-mode.el
@@ -196,8 +196,18 @@ Argument LANGUAGE is either `typescript' or `tsx'."
      (catch_clause
       parameter: (identifier) @font-lock-variable-name-face)
 
+     ;; 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 language
    :feature 'identifier



reply via email to

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