aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tromey2017-02-24 00:24:17 -0700
committerTom Tromey2017-02-24 20:33:41 -0700
commite52287ca3e974ed9f658315288060f638081abb0 (patch)
tree5c4f57067ae60c95a45bff71edeae03efe18f604
parent7b49bd44b70d0583e7e5989513b38e6f77e1c559 (diff)
downloademacs-e52287ca3e974ed9f658315288060f638081abb0.tar.gz
emacs-e52287ca3e974ed9f658315288060f638081abb0.zip
Fix indentation error in js.el
* lisp/progmodes/js.el (js--indent-in-array-comp): Wrap forward-sexp call in condition-case. * test/lisp/progmodes/js-tests.el (js-mode-indentation-error): New test.
-rw-r--r--lisp/progmodes/js.el15
-rw-r--r--test/lisp/progmodes/js-tests.el10
2 files changed, 20 insertions, 5 deletions
diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el
index 6e313dc51b7..65325a8ffad 100644
--- a/lisp/progmodes/js.el
+++ b/lisp/progmodes/js.el
@@ -1986,11 +1986,16 @@ In particular, return the buffer position of the first `for' kwd."
1986 (js--forward-syntactic-ws) 1986 (js--forward-syntactic-ws)
1987 (if (looking-at "[[{]") 1987 (if (looking-at "[[{]")
1988 (let (forward-sexp-function) ; Use Lisp version. 1988 (let (forward-sexp-function) ; Use Lisp version.
1989 (forward-sexp) ; Skip destructuring form. 1989 (condition-case nil
1990 (js--forward-syntactic-ws) 1990 (progn
1991 (if (and (/= (char-after) ?,) ; Regular array. 1991 (forward-sexp) ; Skip destructuring form.
1992 (looking-at "for")) 1992 (js--forward-syntactic-ws)
1993 (match-beginning 0))) 1993 (if (and (/= (char-after) ?,) ; Regular array.
1994 (looking-at "for"))
1995 (match-beginning 0)))
1996 (scan-error
1997 ;; Nothing to do here.
1998 nil)))
1994 ;; To skip arbitrary expressions we need the parser, 1999 ;; To skip arbitrary expressions we need the parser,
1995 ;; so we'll just guess at it. 2000 ;; so we'll just guess at it.
1996 (if (and (> end (point)) ; Not empty literal. 2001 (if (and (> end (point)) ; Not empty literal.
diff --git a/test/lisp/progmodes/js-tests.el b/test/lisp/progmodes/js-tests.el
index 99f5898525b..07e659af605 100644
--- a/test/lisp/progmodes/js-tests.el
+++ b/test/lisp/progmodes/js-tests.el
@@ -118,6 +118,16 @@ if (!/[ (:,='\"]/.test(value)) {
118 ;; implementation not recognizing the comment example. 118 ;; implementation not recognizing the comment example.
119 (should-not (syntax-ppss-context (syntax-ppss)))))) 119 (should-not (syntax-ppss-context (syntax-ppss))))))
120 120
121(ert-deftest js-mode-indentation-error ()
122 (with-temp-buffer
123 (js-mode)
124 ;; The bug previously was that requesting re-indentation on the
125 ;; "{" line here threw an exception.
126 (insert "const TESTS = [\n{")
127 (js-indent-line)
128 ;; Any success is ok here.
129 (should t)))
130
121(provide 'js-tests) 131(provide 'js-tests)
122 132
123;;; js-tests.el ends here 133;;; js-tests.el ends here