[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/typescript-mode 333a7c5f1a 2/3: feat(fontlock): fontify th
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/typescript-mode 333a7c5f1a 2/3: feat(fontlock): fontify the variable and type in typeguard |
Date: |
Sun, 3 Jul 2022 06:58:55 -0400 (EDT) |
branch: elpa/typescript-mode
commit 333a7c5f1a4364ee7d4bf46f490fd40ef8048385
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>
feat(fontlock): fontify the variable and type in typeguard
---
typescript-mode-general-tests.el | 13 +++++++++++++
typescript-mode.el | 7 +++++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/typescript-mode-general-tests.el b/typescript-mode-general-tests.el
index ae3478f34d..62c4847205 100644
--- a/typescript-mode-general-tests.el
+++ b/typescript-mode-general-tests.el
@@ -506,6 +506,19 @@ function foo<Z, Y, Z & Y, Z | Y | Z, Y<X<X, Y>>>()\n"
"type Thing = number;"
(should (eq (get-face-at "Thing") 'font-lock-type-face))))
+(ert-deftest font-lock/fontify-type-guard ()
+ "The type guard syntax
+
+ var is Type
+
+should be fontified as variable, keyword and type."
+ (test-with-fontified-buffer
+ "function test(var: unknown): var is RetType {\n}"
+ (should (eq (get-face-at 30) 'font-lock-variable-name-face))
+ (should (eq (get-face-at "is") 'font-lock-keyword-face))
+ (should (eq (get-face-at "RetType") 'font-lock-type-face))))
+
+
(ert-deftest font-lock/type-names-level4 ()
"Typenames should be highlighted in declarations"
diff --git a/typescript-mode.el b/typescript-mode.el
index d419890aff..2037bfd9bb 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -2013,10 +2013,13 @@ This performs fontification according to
`typescript--class-styles'."
;; - private generic: SomeType<Foo>
;; - private genericArray: SomeType<Foo>[]
;; - function testFunc(): SomeType<> {
+ ;; - function testFunc(a): a is SomeType<> {
;; TODO: namespaced classes!
,(list
- (concat ":\\s-\\(" typescript--type-name-re "\\)\\(<"
typescript--type-name-re ">\\)?\\(\[\]\\)?\\([,;]\\)?\\s-*{?")
- '(1 'font-lock-type-face))
+ (concat ":\\s-\\(?:\\s-*\\(" typescript--name-re
"\\)\\s-*\\(is\\)\\s-*\\)?" "\\(" typescript--type-name-re "\\)\\(<"
typescript--type-name-re ">\\)?\\(\[\]\\)?\\([,;]\\)?\\s-*{?")
+ '(1 'font-lock-variable-name-face nil t)
+ '(2 'font-lock-keyword-face nil t)
+ '(3 'font-lock-type-face))
;; type-casts
,(list