From: Dmitry Gutov Date: Sat, 5 Mar 2016 12:52:14 +0000 (+0200) Subject: Fix computed property generator methods indentation X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/60f7a2b5b79696aae732811df3c530daa3bd55ac Fix computed property generator methods indentation Closes #317 --- diff --git a/js2-old-indent.el b/js2-old-indent.el index 82a00b4a2..9768d1e51 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 bacb61485..b0235fffc 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'; | } |}")