From aa711e0a92c30914e1c68cf39251638d4faee22d Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 16 Jan 2017 14:02:45 -0700 Subject: [PATCH] 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. --- lisp/progmodes/js.el | 4 ++-- test/lisp/progmodes/js-tests.el | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 54df3913fc6..2e5c6ae119b 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -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. - ("\\(?:^\\|[=([{,:;]\\|\\_\\)\\(?:[ \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 9bf7258eebe..84749efa45b 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 -- 2.39.5