Commit aa711e0a authored by Tom Tromey's avatar Tom Tromey
Browse files

Fix JS regexp literal syntax propertization in expressions

Bug#25465:
* lisp/progmodes/js.el (js-syntax-propertize): Recognize a regexp
literal after "!", "&", and "|".
test/lisp/progmodes/js-tests.el (js-mode-regexp-syntax): New test.
parent 14c7d3a6
......@@ -1720,10 +1720,10 @@ This performs fontification according to `js--class-styles'."
;; Distinguish /-division from /-regexp chars (and from /-comment-starter).
;; FIXME: Allow regexps after infix ops like + ...
;; https://developer.mozilla.org/en/JavaScript/Reference/Operators
;; We can probably just add +, -, !, <, >, %, ^, ~, |, &, ?, : at which
;; We can probably just add +, -, <, >, %, ^, ~, ?, : at which
;; point I think only * and / would be missing which could also be added,
;; but need care to avoid affecting the // and */ comment markers.
("\\(?:^\\|[=([{,:;]\\|\\_<return\\_>\\)\\(?:[ \t]\\)*\\(/\\)[^/*]"
("\\(?:^\\|[=([{,:;|&!]\\|\\_<return\\_>\\)\\(?:[ \t]\\)*\\(/\\)[^/*]"
(1 (ignore
(forward-char -1)
(when (or (not (memq (char-after (match-beginning 0)) '(?\s ?\t)))
......
......@@ -59,6 +59,32 @@
* Load the inspector's shared head.js for use by tests that need to
* open the something or other"))))
(ert-deftest js-mode-regexp-syntax ()
(with-temp-buffer
;; Normally indentation tests are done in manual/indent, but in
;; this case we are specifically testing a case where the bug
;; caused the indenter not to do anything, and manual/indent can
;; only be used for already-correct files.
(insert "function f(start, value) {
if (start - 1 === 0 || /[ (:,='\"]/.test(value)) {
--start;
}
if (start - 1 === 0 && /[ (:,='\"]/.test(value)) {
--start;
}
if (!/[ (:,='\"]/.test(value)) {
--start;
}
}
")
(js-mode)
(indent-region (point-min) (point-max))
(goto-char (point-min))
(dolist (x '(0 4 8 4 4 8 4 4 8 4 0))
(back-to-indentation)
(should (= (current-column) x))
(forward-line))))
(provide 'js-tests)
;;; js-tests.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment