From 0255a70c8ae22e259e8938ac3840c7b6687edec8 Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Thu, 28 Apr 2016 02:00:23 +0300 Subject: [PATCH] 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. --- lisp/progmodes/js.el | 6 ++++-- test/indent/js.js | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 8c93ffa8731..48eb3e778e1 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -1892,9 +1892,11 @@ In particular, return the buffer position of the first `for' kwd." ;; To skip arbitrary expressions we need the parser, ;; so we'll just guess at it. (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 (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))))))) (defun js--array-comp-indentation (bracket for-kwd) diff --git a/test/indent/js.js b/test/indent/js.js index 61c7b440ea3..23fae17b3ce 100644 --- a/test/indent/js.js +++ b/test/indent/js.js @@ -53,6 +53,14 @@ var p = { var evens = [e for each (e in range(0, 21)) if (ed % 2 == 0)]; +var funs = [ + function() { + for (;;) { + } + }, + function(){}, +]; + !b !=b !==b -- 2.39.2