[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ba564b7 38/45: Handle arrowfun empty-args in js2-parse-par
From: |
Dmitry Gutov |
Subject: |
[elpa] master ba564b7 38/45: Handle arrowfun empty-args in js2-parse-paren-expr-or-generator-comp |
Date: |
Mon, 02 Feb 2015 03:18:49 +0000 |
branch: master
commit ba564b775788bd679311c68949a25d68e0dc81e5
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Handle arrowfun empty-args in js2-parse-paren-expr-or-generator-comp
Fixes #206
Doing `js2-unget-token' when handling a spurious right paren got us
into infloop.
---
js2-mode.el | 31 ++++++++++++++++---------------
tests/parser.el | 3 +++
2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 9802005..096f985 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -9238,9 +9238,21 @@ If NODE is non-nil, it is the AST node associated with
the symbol."
(defun js2-parse-paren-expr-or-generator-comp ()
(let ((px-pos (js2-current-token-beg)))
- (if (and (>= js2-language-version 200)
- (js2-match-token js2-FOR))
- (js2-parse-generator-comp px-pos)
+ (cond
+ ((and (>= js2-language-version 200)
+ (js2-match-token js2-FOR))
+ (js2-parse-generator-comp px-pos))
+ ((and (>= js2-language-version 200)
+ (js2-match-token js2-RP))
+ ;; Not valid expression syntax, but this is valid in an arrow
+ ;; function with no params: () => body.
+ (if (eq (js2-peek-token) js2-ARROW)
+ ;; Return whatever, it will hopefully be rewinded and
+ ;; reparsed when we reach the =>.
+ (make-js2-keyword-node :type js2-NULL)
+ (js2-report-error "msg.syntax")
+ (make-js2-error-node)))
+ (t
(let* ((js2-in-for-init nil)
(expr (js2-parse-expr))
(pn (make-js2-paren-node :pos px-pos
@@ -9249,7 +9261,7 @@ If NODE is non-nil, it is the AST node associated with
the symbol."
px-pos))))
(js2-node-add-children pn (js2-paren-node-expr pn))
(js2-must-match js2-RP "msg.no.paren")
- pn))))
+ pn)))))
(defun js2-parse-expr (&optional oneshot)
(let* ((pn (js2-parse-assign-expr))
@@ -9968,17 +9980,6 @@ array-literals, array comprehensions and regular
expressions."
(= tt js2-FALSE)
(= tt js2-TRUE))
(make-js2-keyword-node :type tt))
- ((= tt js2-RP)
- ;; Not valid expression syntax, but this is valid in an arrow
- ;; function with no params: () => body.
- (if (eq (js2-peek-token) js2-ARROW)
- (progn
- (js2-unget-token) ; Put back the right paren.
- ;; Return whatever, it will hopefully be rewinded and
- ;; reparsed when we reach the =>.
- (make-js2-keyword-node :type js2-NULL))
- (js2-report-error "msg.syntax")
- (make-js2-error-node)))
((= tt js2-TRIPLEDOT)
;; Likewise, only valid in an arrow function with a rest param.
(if (and (js2-match-token js2-NAME)
diff --git a/tests/parser.el b/tests/parser.el
index 7b9b8b9..553200e 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -260,6 +260,9 @@ the test."
(js2-deftest-parse parenless-arrow-function-prohibits-destructuring
"[a, b] => {a + b;};" :syntax-error "=>" :errors-count 4)
+(js2-deftest-parse arrow-function-recovers-from-error
+ "[(,foo) => 1];" :syntax-error "=>" :errors-count 6)
+
;;; Automatic semicolon insertion
(js2-deftest-parse no-auto-semi-insertion-after-if
- [elpa] master e6dc986 24/45: Limit the scope of `with-silent-modifications', (continued)
- [elpa] master e6dc986 24/45: Limit the scope of `with-silent-modifications', Dmitry Gutov, 2015/02/01
- [elpa] master 6a4e84b 26/45: js2-parse-for: Reword docstring and comments, Dmitry Gutov, 2015/02/01
- [elpa] master 8088e75 21/45: Add js2-language-version check for template literals, Dmitry Gutov, 2015/02/01
- [elpa] master 395d4ae 29/45: Highlight methods with font-lock-function-name-face, Dmitry Gutov, 2015/02/01
- [elpa] master a117465 32/45: Handle "arguments" specially, Dmitry Gutov, 2015/02/01
- [elpa] master 3c4367f 25/45: Make catch-node inherit from scope, Dmitry Gutov, 2015/02/01
- [elpa] master 65bd910 35/45: `js2-time' remove unused variable., Dmitry Gutov, 2015/02/01
- [elpa] master e109213 36/45: Merge pull request #203 from cheunghy/master, Dmitry Gutov, 2015/02/01
- [elpa] master b0ea681 33/45: Add animationFrame functions, Dmitry Gutov, 2015/02/01
- [elpa] master 590db34 37/45: js2-parse-class-stmt: Define the class in the current scope, Dmitry Gutov, 2015/02/01
- [elpa] master ba564b7 38/45: Handle arrowfun empty-args in js2-parse-paren-expr-or-generator-comp,
Dmitry Gutov <=
- [elpa] master 874cf77 31/45: js2-get-token-internal-1: Reindent, Dmitry Gutov, 2015/02/01
- [elpa] master 58c6636 27/45: Support ES6 module syntax, Dmitry Gutov, 2015/02/01
- [elpa] master b91f874 34/45: Merge pull request #202 from brianloveswords/add-browser-externs, Dmitry Gutov, 2015/02/01
- [elpa] master f0935fa 42/45: Add top-level heading, Dmitry Gutov, 2015/02/01
- [elpa] master 7558a96 44/45: Bump the version and update NEWS, Dmitry Gutov, 2015/02/01
- [elpa] master bc42697 40/45: Fix free variable references, Dmitry Gutov, 2015/02/01
- [elpa] master a018a79 43/45: Highlight JS snippets, Dmitry Gutov, 2015/02/01
- [elpa] master 66d69cb 39/45: js2-test-parse-string: Compare the first syntax error, Dmitry Gutov, 2015/02/01
- [elpa] master b67d97b 41/45: Move the news from the wiki to the repo, Dmitry Gutov, 2015/02/01
- [elpa] master dedfa35 28/45: Replace usage of 'cl with 'cl-lib, Dmitry Gutov, 2015/02/01