branch: master
commit 60f7a2b5b79696aae732811df3c530daa3bd55ac
Author: Dmitry Gutov <[email protected]>
Commit: Dmitry Gutov <[email protected]>

    Fix computed property generator methods indentation
    
    Closes #317
---
 js2-old-indent.el |   13 ++++++++-----
 tests/indent.el   |   10 +++++++++-
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/js2-old-indent.el b/js2-old-indent.el
index 82a00b4..9768d1e 100644
--- a/js2-old-indent.el
+++ b/js2-old-indent.el
@@ -225,12 +225,15 @@ and comments have been removed."
                   (eq (char-after) ??))))
        (not (and
              (eq (char-after) ?*)
-             (looking-at (concat "\\* *" js2-mode-identifier-re " *("))
+             ;; Generator method (possibly using computed property).
+             (looking-at (concat "\\* *\\(?:\\[\\|"
+                                 js2-mode-identifier-re
+                                 " *(\\)"))
              (save-excursion
-               (goto-char (1- (match-end 0)))
-               (let (forward-sexp-function) (forward-sexp))
-               (js2-forward-sws)
-               (eq (char-after) ?{))))))
+               (js2-backward-sws)
+               ;; We might misindent some expressions that would
+               ;; return NaN anyway.  Shouldn't be a problem.
+               (memq (char-before) '(?, ?} ?{)))))))
 
 (defun js2-continued-expression-p ()
   "Return non-nil if the current line continues an expression."
diff --git a/tests/indent.el b/tests/indent.el
index bacb614..b0235ff 100644
--- a/tests/indent.el
+++ b/tests/indent.el
@@ -146,7 +146,15 @@
   "class A {
   |  * x() {
   |    return 1
-  |      * 2;
+  |      * a(2);
+  |  }
+  |}")
+
+(js2-deftest-indent indent-generator-computed-method
+  "class A {
+  |  *[Symbol.iterator]() {
+  |    yield 'Foo';
+  |    yield 'Bar';
   |  }
   |}")
 

Reply via email to