emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] emacs-25 dc9d837: Don't misindent computed property genera


From: Dmitry Gutov
Subject: [Emacs-diffs] emacs-25 dc9d837: Don't misindent computed property generator methods
Date: Sat, 05 Mar 2016 12:35:48 +0000

branch: emacs-25
commit dc9d837d02edd665f2c9468de51bb4a1dda7ef6d
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Don't misindent computed property generator methods
    
    * lisp/progmodes/js.el (js--looking-at-operator-p):
    Don't misindent computed property generator methods
    (https://github.com/mooz/js2-mode/issues/317).
---
 lisp/progmodes/js.el |   11 ++++++-----
 test/indent/js.js    |    7 ++++++-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index d59e767..15a52ba 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1758,12 +1758,13 @@ This performs fontification according to 
`js--class-styles'."
                     (eq (char-after) ??))))
          (not (and
                (eq (char-after) ?*)
-               (looking-at (concat "\\* *" js--name-re " *("))
+               ;; Generator method (possibly using computed property).
+               (looking-at (concat "\\* *\\(?:\\[\\|" js--name-re " *(\\)"))
                (save-excursion
-                 (goto-char (1- (match-end 0)))
-                 (let (forward-sexp-function) (forward-sexp))
-                 (js--forward-syntactic-ws)
-                 (eq (char-after) ?{)))))))
+                 (js--backward-syntactic-ws)
+                 ;; We might misindent some expressions that would
+                 ;; return NaN anyway.  Shouldn't be a problem.
+                 (memq (char-before) '(?, ?} ?{))))))))
 
 (defun js--continued-expression-p ()
   "Return non-nil if the current line continues an expression."
diff --git a/test/indent/js.js b/test/indent/js.js
index 9a1e0dc..d843f61 100644
--- a/test/indent/js.js
+++ b/test/indent/js.js
@@ -72,7 +72,12 @@ baz(`http://foo.bar/${tee}`)
 class A {
   * x() {
     return 1
-      * 2;
+      * a(2);
+  }
+
+  *[Symbol.iterator]() {
+    yield "Foo";
+    yield "Bar";
   }
 }
 



reply via email to

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