]> code.delx.au - gnu-emacs-elpa/commitdiff
Special-case unary + and -
authorDmitry Gutov <dgutov@yandex.ru>
Sat, 2 Apr 2016 00:32:07 +0000 (03:32 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sat, 2 Apr 2016 00:32:07 +0000 (03:32 +0300)
Fixes #322

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

index d855b9e2561ffa0005051f8a8c311204fc293a88..d8932d60cc387e54e823e3587a658f00901c83af 100644 (file)
@@ -239,20 +239,16 @@ and comments have been removed."
   "Return non-nil if the current line continues an expression."
   (save-excursion
     (back-to-indentation)
-    (or (js2-looking-at-operator-p)
-        (when (catch 'found
-                (while (and (re-search-backward "\n" nil t)
-                            (let ((state (syntax-ppss)))
-                              (when (nth 4 state)
-                                (goto-char (nth 8 state))) ;; skip comments
-                              (skip-chars-backward " \t")
-                              (if (bolp)
-                                  t
-                                (throw 'found t))))))
-          (backward-char)
-          (when (js2-looking-at-operator-p)
-            (backward-char)
-            (not (looking-at "\\*\\|\\+\\+\\|--\\|/[/*]")))))))
+    (if (js2-looking-at-operator-p)
+        (or (not (memq (char-after) '(?- ?+)))
+            (progn
+              (forward-comment (- (point)))
+              (not (memq (char-before) '(?, ?\[ ?\()))))
+      (forward-comment (- (point)))
+      (or (bobp) (backward-char))
+      (when (js2-looking-at-operator-p)
+        (backward-char)
+        (not (looking-at "\\*\\|\\+\\+\\|--\\|/[/*]"))))))
 
 (defun js2-end-of-do-while-loop-p ()
   "Return non-nil if word after point is `while' of a do-while
index b0235fffc15c40d0e73a52f31c39ca9440cbb306..91b86565feca3478e23ab5774a0c14ecbb77a9c3 100644 (file)
   |}"
   :bind ((js2-indent-switch-body t)))
 
+(js2-deftest-indent continued-expression-vs-unary-minus
+  "var arr = [
+  |  -1, 2,
+  |  -3, 4 +
+  |    -5
+  |];")
+
 (js2-deftest-indent jsx-one-line
   "var foo = <div></div>;")