Skip to content

Commit 35f01b3

Browse files
authored
Merge pull request #173 from Fuco1/fix/keywords-in-interfaces
fix(fontlock): do not fontify builtins in object/interface key context
2 parents 83bf47e + 9bd226b commit 35f01b3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

typescript-mode-general-tests.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,19 @@ a severity set to WARNING, no rule name."
287287
" * @param {Something} bar A parameter. References [[moo]] and [[foo]].
288288
* @param second May hold ``x`` or ``y``.")
289289

290+
(ert-deftest font-lock/interface-builtin-key-context-unfontify ()
291+
"Builtins should not be fontified when they are in object or
292+
interface key context."
293+
(test-with-fontified-buffer
294+
"interface Foo { type: number; unknown: string; foo: boolean }"
295+
(should (eq (get-face-at "type") 'default))
296+
(should (eq (get-face-at "unknown") 'default)))
297+
298+
(test-with-fontified-buffer
299+
"const x = { type: 4; unknown: 'bar'; foo: true }"
300+
(should (eq (get-face-at "type") 'default))
301+
(should (eq (get-face-at "unknown") 'default))))
302+
290303
(ert-deftest font-lock/documentation-in-documentation-comments ()
291304
"Documentation in documentation comments should be fontified as
292305
documentation."

typescript-mode.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,14 @@ and searches for the next token to be highlighted."
17371737
`(
17381738
,@typescript--font-lock-keywords-2
17391739

1740+
;; Remove the fontification of keywords and built-ins when they
1741+
;; are keys in an interface, object or class.
1742+
(,(rx "{")
1743+
(,(concat "\\(" typescript--keyword-re "\\):")
1744+
(save-excursion (ignore-errors (up-list)) (point))
1745+
nil
1746+
(1 'default t t)))
1747+
17401748
(typescript--jsdoc-param-matcher (1 'typescript-jsdoc-tag t t)
17411749
(2 'typescript-jsdoc-type t t)
17421750
(3 'typescript-jsdoc-value t t))

0 commit comments

Comments
 (0)