]> code.delx.au - gnu-emacs-elpa/commitdiff
Fix computed property generator methods indentation
authorDmitry Gutov <dgutov@yandex.ru>
Sat, 5 Mar 2016 12:52:14 +0000 (14:52 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 5 Mar 2016 12:52:45 +0000 (14:52 +0200)
Closes #317

js2-old-indent.el
tests/indent.el

index 82a00b4a28599b44a76f3d9f17c645b59936f228..9768d1e513037d9b68f2effd2f992746587f562f 100644 (file)
@@ -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."
index bacb614859f1c8c80775de99041ea12f37d3c30d..b0235fffc15c40d0e73a52f31c39ca9440cbb306 100644 (file)
   "class A {
   |  * x() {
   |    return 1
-  |      * 2;
+  |      * a(2);
+  |  }
+  |}")
+
+(js2-deftest-indent indent-generator-computed-method
+  "class A {
+  |  *[Symbol.iterator]() {
+  |    yield 'Foo';
+  |    yield 'Bar';
   |  }
   |}")