commit f76d42b87e8531d21072a51ac86c91ffae5ee36f Author: Tom Tromey Date: Mon Jan 16 14:02:45 2017 -0700 Fix JS regexp literal syntax propertization in expressions * 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. diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 54df391..2e5c6ae 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1720,10 +1720,10 @@ js-syntax-propertize ;; 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. - ("\\(?:^\\|[=([{,:;]\\|\\_\\)\\(?:[ \t]\\)*\\(/\\)[^/*]" + ("\\(?:^\\|[=([{,:;|&!]\\|\\_\\)\\(?:[ \t]\\)*\\(/\\)[^/*]" (1 (ignore (forward-char -1) (when (or (not (memq (char-after (match-beginning 0)) '(?\s ?\t))) diff --git a/test/lisp/progmodes/js-tests.el b/test/lisp/progmodes/js-tests.el index 9bf7258..84749ef 100644 --- a/test/lisp/progmodes/js-tests.el +++ b/test/lisp/progmodes/js-tests.el @@ -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