From 9bd226b3860540f39887cf8f062a2dfc172f62b9 Mon Sep 17 00:00:00 2001 From: Matus Goljer Date: Sat, 9 Jul 2022 16:04:58 +0200 Subject: [PATCH] fix(fontlock): do not fontify builtins in object/interface key context --- typescript-mode-general-tests.el | 13 +++++++++++++ typescript-mode.el | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/typescript-mode-general-tests.el b/typescript-mode-general-tests.el index 9c1102b..ad5ed62 100644 --- a/typescript-mode-general-tests.el +++ b/typescript-mode-general-tests.el @@ -287,6 +287,19 @@ a severity set to WARNING, no rule name." " * @param {Something} bar A parameter. References [[moo]] and [[foo]]. * @param second May hold ``x`` or ``y``.") +(ert-deftest font-lock/interface-builtin-key-context-unfontify () + "Builtins should not be fontified when they are in object or +interface key context." + (test-with-fontified-buffer + "interface Foo { type: number; unknown: string; foo: boolean }" + (should (eq (get-face-at "type") 'default)) + (should (eq (get-face-at "unknown") 'default))) + + (test-with-fontified-buffer + "const x = { type: 4; unknown: 'bar'; foo: true }" + (should (eq (get-face-at "type") 'default)) + (should (eq (get-face-at "unknown") 'default)))) + (ert-deftest font-lock/documentation-in-documentation-comments () "Documentation in documentation comments should be fontified as documentation." diff --git a/typescript-mode.el b/typescript-mode.el index 268df97..215a5d8 100644 --- a/typescript-mode.el +++ b/typescript-mode.el @@ -1737,6 +1737,14 @@ and searches for the next token to be highlighted." `( ,@typescript--font-lock-keywords-2 + ;; Remove the fontification of keywords and built-ins when they + ;; are keys in an interface, object or class. + (,(rx "{") + (,(concat "\\(" typescript--keyword-re "\\):") + (save-excursion (ignore-errors (up-list)) (point)) + nil + (1 'default t t))) + (typescript--jsdoc-param-matcher (1 'typescript-jsdoc-tag t t) (2 'typescript-jsdoc-type t t) (3 'typescript-jsdoc-value t t))