]> code.delx.au - gnu-emacs/commitdiff
Don't misindent computed property generator methods
authorDmitry Gutov <dgutov@yandex.ru>
Sat, 5 Mar 2016 12:35:10 +0000 (14:35 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 5 Mar 2016 12:35:35 +0000 (14:35 +0200)
* 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
test/indent/js.js

index d59e7679b478cd69ee5a6902a8d98d5d79d38398..15a52ba8cdc9a0b1a2f2c3e9e1c8981454a0a044 100644 (file)
@@ -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."
index 9a1e0dc7ad5b3e141a75a787866d2232aa70f5e8..d843f615fd8ec313d8ea70922c83e70c849c71f0 100644 (file)
@@ -72,7 +72,12 @@ baz(`http://foo.bar/${tee}`)
 class A {
   * x() {
     return 1
-      * 2;
+      * a(2);
+  }
+
+  *[Symbol.iterator]() {
+    yield "Foo";
+    yield "Bar";
   }
 }