diff options
| -rw-r--r-- | lisp/progmodes/js.el | 13 | ||||
| -rw-r--r-- | test/lisp/progmodes/js-tests.el | 37 |
2 files changed, 44 insertions, 6 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index aed42a85076..3c720c05610 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el | |||
| @@ -1713,7 +1713,7 @@ This performs fontification according to `js--class-styles'." | |||
| 1713 | (not (any ?\] ?\\)) | 1713 | (not (any ?\] ?\\)) |
| 1714 | (and "\\" not-newline))) | 1714 | (and "\\" not-newline))) |
| 1715 | "]"))) | 1715 | "]"))) |
| 1716 | (group "/")) | 1716 | (group (zero-or-one "/"))) |
| 1717 | "Regular expression matching a JavaScript regexp literal.") | 1717 | "Regular expression matching a JavaScript regexp literal.") |
| 1718 | 1718 | ||
| 1719 | (defun js-syntax-propertize-regexp (end) | 1719 | (defun js-syntax-propertize-regexp (end) |
| @@ -1721,12 +1721,13 @@ This performs fontification according to `js--class-styles'." | |||
| 1721 | (when (eq (nth 3 ppss) ?/) | 1721 | (when (eq (nth 3 ppss) ?/) |
| 1722 | ;; A /.../ regexp. | 1722 | ;; A /.../ regexp. |
| 1723 | (goto-char (nth 8 ppss)) | 1723 | (goto-char (nth 8 ppss)) |
| 1724 | (when (and (looking-at js--syntax-propertize-regexp-regexp) | 1724 | (when (looking-at js--syntax-propertize-regexp-regexp) |
| 1725 | ;; Don't touch text after END. | 1725 | ;; Don't touch text after END. |
| 1726 | (<= (match-end 1) end)) | 1726 | (when (> end (match-end 1)) |
| 1727 | (put-text-property (match-beginning 1) (match-end 1) | 1727 | (setq end (match-end 1))) |
| 1728 | (put-text-property (match-beginning 1) end | ||
| 1728 | 'syntax-table (string-to-syntax "\"/")) | 1729 | 'syntax-table (string-to-syntax "\"/")) |
| 1729 | (goto-char (match-end 0)))))) | 1730 | (goto-char end))))) |
| 1730 | 1731 | ||
| 1731 | (defun js-syntax-propertize (start end) | 1732 | (defun js-syntax-propertize (start end) |
| 1732 | ;; JavaScript allows immediate regular expression objects, written /.../. | 1733 | ;; JavaScript allows immediate regular expression objects, written /.../. |
diff --git a/test/lisp/progmodes/js-tests.el b/test/lisp/progmodes/js-tests.el index e030675e07c..8e1bac10cd1 100644 --- a/test/lisp/progmodes/js-tests.el +++ b/test/lisp/progmodes/js-tests.el | |||
| @@ -140,6 +140,43 @@ if (!/[ (:,='\"]/.test(value)) { | |||
| 140 | (font-lock-ensure) | 140 | (font-lock-ensure) |
| 141 | (should (eq (get-text-property (point) 'face) (caddr test)))))) | 141 | (should (eq (get-text-property (point) 'face) (caddr test)))))) |
| 142 | 142 | ||
| 143 | (ert-deftest js-mode-propertize-bug-1 () | ||
| 144 | (with-temp-buffer | ||
| 145 | (js-mode) | ||
| 146 | (save-excursion (insert "x")) | ||
| 147 | (insert "/") | ||
| 148 | ;; The bug was a hang. | ||
| 149 | (should t))) | ||
| 150 | |||
| 151 | (ert-deftest js-mode-propertize-bug-2 () | ||
| 152 | (with-temp-buffer | ||
| 153 | (js-mode) | ||
| 154 | (insert "function f() { | ||
| 155 | function g() | ||
| 156 | { | ||
| 157 | 1 / 2; | ||
| 158 | } | ||
| 159 | |||
| 160 | function h() { | ||
| 161 | ") | ||
| 162 | (save-excursion | ||
| 163 | (insert " | ||
| 164 | 00000000000000000000000000000000000000000000000000; | ||
| 165 | 00000000000000000000000000000000000000000000000000; | ||
| 166 | 00000000000000000000000000000000000000000000000000; | ||
| 167 | 00000000000000000000000000000000000000000000000000; | ||
| 168 | 00000000000000000000000000000000000000000000000000; | ||
| 169 | 00000000000000000000000000000000000000000000000000; | ||
| 170 | 00000000000000000000000000000000000000000000000000; | ||
| 171 | 00000000000000000000000000000000000000000000000000; | ||
| 172 | 00; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | ")) | ||
| 176 | (insert "/") | ||
| 177 | ;; The bug was a hang. | ||
| 178 | (should t))) | ||
| 179 | |||
| 143 | (provide 'js-tests) | 180 | (provide 'js-tests) |
| 144 | 181 | ||
| 145 | ;;; js-tests.el ends here | 182 | ;;; js-tests.el ends here |