Commit 0255a70c authored by Dmitry Gutov's avatar Dmitry Gutov

Don't mistake `for' inside a function for a part of array comprehension

* lisp/progmodes/js.el (js--indent-in-array-comp): Also check the
depth in parens between the bracket and `for' (bug#23391).

* test/indent/js.js: Add a corresponding example.
parent ff7e201e
...@@ -1892,9 +1892,11 @@ In particular, return the buffer position of the first `for' kwd." ...@@ -1892,9 +1892,11 @@ In particular, return the buffer position of the first `for' kwd."
;; To skip arbitrary expressions we need the parser, ;; To skip arbitrary expressions we need the parser,
;; so we'll just guess at it. ;; so we'll just guess at it.
(if (and (> end (point)) ; Not empty literal. (if (and (> end (point)) ; Not empty literal.
(re-search-forward "[^,]]* \\(for\\) " end t) (re-search-forward "[^,]]* \\(for\\_>\\)" end t)
;; Not inside comment or string literal. ;; Not inside comment or string literal.
(not (nth 8 (parse-partial-sexp bracket (point))))) (let ((status (parse-partial-sexp bracket (point))))
(and (= 1 (car status))
(not (nth 8 status)))))
(match-beginning 1))))))) (match-beginning 1)))))))
(defun js--array-comp-indentation (bracket for-kwd) (defun js--array-comp-indentation (bracket for-kwd)
......
...@@ -53,6 +53,14 @@ var p = { ...@@ -53,6 +53,14 @@ var p = {
var evens = [e for each (e in range(0, 21)) var evens = [e for each (e in range(0, 21))
if (ed % 2 == 0)]; if (ed % 2 == 0)];
var funs = [
function() {
for (;;) {
}
},
function(){},
];
!b !b
!=b !=b
!==b !==b
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment