emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs-26 e562356: Fix two js indentation problems


From: Dmitry Gutov
Subject: [Emacs-diffs] emacs-26 e562356: Fix two js indentation problems
Date: Wed, 25 Oct 2017 19:43:59 -0400 (EDT)

branch: emacs-26
commit e562356c3f31bf96250bd3e8a7c50e8322b15d68
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Fix two js indentation problems
    
    Fix intentation problems reported in
    https://github.com/mooz/js2-mode/issues/463.
    * lisp/progmodes/js.el (js--continued-expression-p):
    Check syntax state after /.
    (js--multi-line-declaration-indentation):
    Check syntax state before "const".
---
 lisp/progmodes/js.el     | 21 +++++++++++++++------
 test/manual/indent/js.js |  9 +++++++++
 2 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 2bbacf7..1f86909 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1834,10 +1834,15 @@ This performs fontification according to 
`js--class-styles'."
   (save-excursion
     (back-to-indentation)
     (if (js--looking-at-operator-p)
-        (or (not (memq (char-after) '(?- ?+)))
-            (progn
-              (forward-comment (- (point)))
-              (not (memq (char-before) '(?, ?\[ ?\()))))
+        (if (eq (char-after) ?/)
+            (prog1
+                (not (nth 3 (syntax-ppss (1+ (point)))))
+              (forward-char -1))
+          (or
+           (not (memq (char-after) '(?- ?+)))
+           (progn
+             (forward-comment (- (point)))
+             (not (memq (char-before) '(?, ?\[ ?\())))))
       (and (js--find-newline-backward)
            (progn
              (skip-chars-backward " \t")
@@ -1972,8 +1977,12 @@ statement spanning multiple lines; otherwise, return 
nil."
     (save-excursion
       (back-to-indentation)
       (when (not (looking-at js--declaration-keyword-re))
-        (when (looking-at js--indent-operator-re)
-          (goto-char (match-end 0)))
+        (let ((pt (point)))
+          (when (looking-at js--indent-operator-re)
+            (goto-char (match-end 0)))
+          ;; The "operator" is probably a regexp literal opener.
+          (when (nth 3 (syntax-ppss))
+            (goto-char pt)))
         (while (and (not at-opening-bracket)
                     (not (bobp))
                     (let ((pos (point)))
diff --git a/test/manual/indent/js.js b/test/manual/indent/js.js
index 1ad76a8..b0d8bca 100644
--- a/test/manual/indent/js.js
+++ b/test/manual/indent/js.js
@@ -7,6 +7,9 @@ let c = 1,
 var e = 100500,
     + 1;
 
+// Don't misinterpret "const"
+/const/
+
 function test ()
 {
   return /[/]/.test ('/')     // (bug#19397)
@@ -135,6 +138,12 @@ if (1) {
     : 4
 }
 
+// Regexp is not a continuation
+bar(
+  "string arg1",
+  /abc/
+)
+
 // Local Variables:
 // indent-tabs-mode: nil
 // js-indent-level: 2



reply via email to

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