Skip to content

Commit 333a7c5

Browse files
committed
feat(fontlock): fontify the variable and type in typeguard
1 parent d223ae4 commit 333a7c5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

typescript-mode-general-tests.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,19 @@ function foo<Z, Y, Z & Y, Z | Y | Z, Y<X<X, Y>>>()\n"
506506
"type Thing = number;"
507507
(should (eq (get-face-at "Thing") 'font-lock-type-face))))
508508

509+
(ert-deftest font-lock/fontify-type-guard ()
510+
"The type guard syntax
511+
512+
var is Type
513+
514+
should be fontified as variable, keyword and type."
515+
(test-with-fontified-buffer
516+
"function test(var: unknown): var is RetType {\n}"
517+
(should (eq (get-face-at 30) 'font-lock-variable-name-face))
518+
(should (eq (get-face-at "is") 'font-lock-keyword-face))
519+
(should (eq (get-face-at "RetType") 'font-lock-type-face))))
520+
521+
509522
(ert-deftest font-lock/type-names-level4 ()
510523
"Typenames should be highlighted in declarations"
511524

typescript-mode.el

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,10 +2013,13 @@ This performs fontification according to `typescript--class-styles'."
20132013
;; - private generic: SomeType<Foo>
20142014
;; - private genericArray: SomeType<Foo>[]
20152015
;; - function testFunc(): SomeType<> {
2016+
;; - function testFunc(a): a is SomeType<> {
20162017
;; TODO: namespaced classes!
20172018
,(list
2018-
(concat ":\\s-\\(" typescript--type-name-re "\\)\\(<" typescript--type-name-re ">\\)?\\(\[\]\\)?\\([,;]\\)?\\s-*{?")
2019-
'(1 'font-lock-type-face))
2019+
(concat ":\\s-\\(?:\\s-*\\(" typescript--name-re "\\)\\s-*\\(is\\)\\s-*\\)?" "\\(" typescript--type-name-re "\\)\\(<" typescript--type-name-re ">\\)?\\(\[\]\\)?\\([,;]\\)?\\s-*{?")
2020+
'(1 'font-lock-variable-name-face nil t)
2021+
'(2 'font-lock-keyword-face nil t)
2022+
'(3 'font-lock-type-face))
20202023

20212024
;; type-casts
20222025
,(list

0 commit comments

Comments
 (0)