]> git.eshelyaron.com Git - emacs.git/commitdiff
fix two js-mode syntax propertization bugs
authorTom Tromey <tom@tromey.com>
Mon, 13 Mar 2017 20:53:59 +0000 (21:53 +0100)
committerTom Tromey <tom@tromey.com>
Sat, 1 Apr 2017 21:03:46 +0000 (15:03 -0600)
Bug#26070:
* lisp/progmodes/js.el (js--syntax-propertize-regexp-regexp): Add
zero-or-one to regular expression.
(js-syntax-propertize-regexp): Update.  Propertize body of regexp
literal up to END.
* test/lisp/progmodes/js-tests.el (js-mode-propertize-bug-1)
(js-mode-propertize-bug-2): New tests.

lisp/progmodes/js.el
test/lisp/progmodes/js-tests.el

index aed42a8507624e2b7490ee7cfe0ad3bd2d8fb861..3c720c05610dac810aaeb9b62c2fb5e6416b9c43 100644 (file)
@@ -1713,7 +1713,7 @@ This performs fontification according to `js--class-styles'."
               (not (any ?\] ?\\))
               (and "\\" not-newline)))
          "]")))
-   (group "/"))
+   (group (zero-or-one "/")))
   "Regular expression matching a JavaScript regexp literal.")
 
 (defun js-syntax-propertize-regexp (end)
@@ -1721,12 +1721,13 @@ This performs fontification according to `js--class-styles'."
     (when (eq (nth 3 ppss) ?/)
       ;; A /.../ regexp.
       (goto-char (nth 8 ppss))
-      (when (and (looking-at js--syntax-propertize-regexp-regexp)
-                 ;; Don't touch text after END.
-                 (<= (match-end 1) end))
-        (put-text-property (match-beginning 1) (match-end 1)
+      (when (looking-at js--syntax-propertize-regexp-regexp)
+        ;; Don't touch text after END.
+        (when (> end (match-end 1))
+          (setq end (match-end 1)))
+        (put-text-property (match-beginning 1) end
                            'syntax-table (string-to-syntax "\"/"))
-        (goto-char (match-end 0))))))
+        (goto-char end)))))
 
 (defun js-syntax-propertize (start end)
   ;; JavaScript allows immediate regular expression objects, written /.../.
index e030675e07c91b182281eb89707f4881890fb940..8e1bac10cd196a94a8c00dc19df01ee1ad08fbc4 100644 (file)
@@ -140,6 +140,43 @@ if (!/[ (:,='\"]/.test(value)) {
       (font-lock-ensure)
       (should (eq (get-text-property (point) 'face) (caddr test))))))
 
+(ert-deftest js-mode-propertize-bug-1 ()
+  (with-temp-buffer
+    (js-mode)
+    (save-excursion (insert "x"))
+    (insert "/")
+    ;; The bug was a hang.
+    (should t)))
+
+(ert-deftest js-mode-propertize-bug-2 ()
+  (with-temp-buffer
+    (js-mode)
+    (insert "function f() {
+    function g()
+    {
+        1 / 2;
+    }
+
+    function h() {
+")
+    (save-excursion
+      (insert "
+        00000000000000000000000000000000000000000000000000;
+        00000000000000000000000000000000000000000000000000;
+        00000000000000000000000000000000000000000000000000;
+        00000000000000000000000000000000000000000000000000;
+        00000000000000000000000000000000000000000000000000;
+        00000000000000000000000000000000000000000000000000;
+        00000000000000000000000000000000000000000000000000;
+        00000000000000000000000000000000000000000000000000;
+        00;
+    }
+}
+"))
+    (insert "/")
+    ;; The bug was a hang.
+    (should t)))
+
 (provide 'js-tests)
 
 ;;; js-tests.el ends here