diff options
| author | Dmitry Gutov | 2016-04-28 02:00:23 +0300 |
|---|---|---|
| committer | Dmitry Gutov | 2016-04-28 02:00:48 +0300 |
| commit | 0255a70c8ae22e259e8938ac3840c7b6687edec8 (patch) | |
| tree | 7e300091da3bedac669c525b3131d798ffd1b633 | |
| parent | ff7e201ed87d206334afedd4366deebba440efde (diff) | |
| download | emacs-0255a70c8ae22e259e8938ac3840c7b6687edec8.tar.gz emacs-0255a70c8ae22e259e8938ac3840c7b6687edec8.zip | |
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.
| -rw-r--r-- | lisp/progmodes/js.el | 6 | ||||
| -rw-r--r-- | 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." | |||
| 1892 | ;; To skip arbitrary expressions we need the parser, | 1892 | ;; To skip arbitrary expressions we need the parser, |
| 1893 | ;; so we'll just guess at it. | 1893 | ;; so we'll just guess at it. |
| 1894 | (if (and (> end (point)) ; Not empty literal. | 1894 | (if (and (> end (point)) ; Not empty literal. |
| 1895 | (re-search-forward "[^,]]* \\(for\\) " end t) | 1895 | (re-search-forward "[^,]]* \\(for\\_>\\)" end t) |
| 1896 | ;; Not inside comment or string literal. | 1896 | ;; Not inside comment or string literal. |
| 1897 | (not (nth 8 (parse-partial-sexp bracket (point))))) | 1897 | (let ((status (parse-partial-sexp bracket (point)))) |
| 1898 | (and (= 1 (car status)) | ||
| 1899 | (not (nth 8 status))))) | ||
| 1898 | (match-beginning 1))))))) | 1900 | (match-beginning 1))))))) |
| 1899 | 1901 | ||
| 1900 | (defun js--array-comp-indentation (bracket for-kwd) | 1902 | (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 = { | |||
| 53 | var evens = [e for each (e in range(0, 21)) | 53 | var evens = [e for each (e in range(0, 21)) |
| 54 | if (ed % 2 == 0)]; | 54 | if (ed % 2 == 0)]; |
| 55 | 55 | ||
| 56 | var funs = [ | ||
| 57 | function() { | ||
| 58 | for (;;) { | ||
| 59 | } | ||
| 60 | }, | ||
| 61 | function(){}, | ||
| 62 | ]; | ||
| 63 | |||
| 56 | !b | 64 | !b |
| 57 | !=b | 65 | !=b |
| 58 | !==b | 66 | !==b |