emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master aa711e0: Fix JS regexp literal syntax propertizatio


From: Tom Tromey
Subject: [Emacs-diffs] master aa711e0: Fix JS regexp literal syntax propertization in expressions
Date: Tue, 17 Jan 2017 22:35:27 +0000 (UTC)

branch: master
commit aa711e0a92c30914e1c68cf39251638d4faee22d
Author: Tom Tromey <address@hidden>
Commit: Tom Tromey <address@hidden>

    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 54df391..2e5c6ae 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.
-    ("\\(?:^\\|[=([{,:;]\\|\\_<return\\_>\\)\\(?:[ \t]\\)*\\(/\\)[^/*]"
+    ("\\(?:^\\|[=([{,:;|&!]\\|\\_<return\\_>\\)\\(?:[ \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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]