emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/typescript-mode 5b0487aae8 085/222: Fix the Emacs regex us


From: ELPA Syncer
Subject: [nongnu] elpa/typescript-mode 5b0487aae8 085/222: Fix the Emacs regex used for highlighting TS regexes.
Date: Sun, 6 Feb 2022 16:59:20 -0500 (EST)

branch: elpa/typescript-mode
commit 5b0487aae890e7e9f7105a679deecc50428e912d
Author: Louis-Dominique Dubeau <ldd@lddubeau.com>
Commit: Louis-Dominique Dubeau <ldd@lddubeau.com>

    Fix the Emacs regex used for highlighting TS regexes.
    
    The previous regex would treat // as a regex, which is wrong. In JS
    (which TS follows to the letter, in this case), // is never a regular
    expression. It *looks* like an empty regular expression, but if it
    appears outside a string or comment, then it is the start of a single
    line comment, not an empty regular expression. The old regex also had
    trouble dealing with an escaped forward slash appearing in a
    regex. The commit fixes both problems, and it adds tests to check for
    such issues.
---
 typescript-mode-tests.el | 29 ++++++++++++++++++++---------
 typescript-mode.el       |  2 +-
 2 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/typescript-mode-tests.el b/typescript-mode-tests.el
index 4a9e4f0f4c..4974819416 100644
--- a/typescript-mode-tests.el
+++ b/typescript-mode-tests.el
@@ -284,22 +284,33 @@ declare function declareFunctionDefn(x3: xty3, y3: yty3): 
ret3;"
                     '(("=" . nil) ("/foo/" . font-lock-string-face)
                       ("(" . nil) ("/bar/" . font-lock-string-face)
                       ("," . nil) ("/baz/" . font-lock-string-face)
-                      (":" . nil) ("/buzz/" . font-lock-string-face)))))
+                      (":" . nil) ("/buzz/" . font-lock-string-face))))
+  ;; Make sure that escaped forward slashes are handled too.
+  (font-lock-test "var a = /flip\\/flop/;"
+                  '(("=" . nil)
+                    (("/flip" "\\\\" "/" "flop/") . font-lock-string-face)
+                    (";" . nil)))
+  ;; A sequence of two forward slashes is never a regex, so there is
+  ;; no such thing as an \"empty regex\" when we use the forward slash
+  ;; notation.
+  (font-lock-test "=//g something // comment"
+                  '(("g something" . font-lock-comment-face))))
 
 (ert-deftest 
font-lock/text-after-trailing-regexp-delim-should-not-be-fontified ()
   "Text after trailing regular expression delimiter should not be fontified."
   (test-with-temp-buffer
-      "=/foo/g something // comment"
-    (should (eq (get-face-at "g something") nil)))
+   "=/foo/g something // comment"
+   (should (eq (get-face-at "g something") nil)))
   (test-with-temp-buffer
-      "=/foo\\bar/g something // comment"
-    (should (eq (get-face-at "g something") nil)))
+   "=/foo\\bar/g something // comment"
+   (should (eq (get-face-at "g something") nil)))
   (test-with-temp-buffer
-      "=/foo\\\\bar/g something // comment"
-    (should (eq (get-face-at "g something") nil)))
+   "=/foo\\\\bar/g something // comment"
+   (should (eq (get-face-at "g something") nil)))
   (test-with-temp-buffer
-      "=/foo\\\\/g something // comment"
-    (should (eq (get-face-at "g something") nil))))
+   "=/foo\\\\/g something // comment"
+   (should (eq (get-face-at "g something") nil))))
+
 
 (defun flyspell-predicate-test (search-for)
   "This function runs a test on
diff --git a/typescript-mode.el b/typescript-mode.el
index 25918105a0..6497d3b7cd 100644
--- a/typescript-mode.el
+++ b/typescript-mode.el
@@ -1871,7 +1871,7 @@ This performs fontification according to 
`typescript--class-styles'."
 ;; as the newline is escaped with \. Account for that in the regexp
 ;; below.
 (defconst typescript--regexp-literal
-  "[=(,:]\\(?:\\s-\\|\n\\)*\\(/\\)[^/]*\\(/\\)"
+  "[=(,:]\\(?:\\s-\\|\n\\)*\\(/\\)\\(?:\\\\.\\|[^/]\\)+\\(/\\)"
   "Regexp matching a typescript regular expression literal.
 Match groups 1 and 2 are the characters forming the beginning and
 end of the literal.")



reply via email to

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