[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 37/46: Support object destructuring inside arrow function args
From: |
Dmitry Gutov |
Subject: |
[elpa] 37/46: Support object destructuring inside arrow function args |
Date: |
Sat, 15 Nov 2014 20:58:10 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit 87cfd408316d1e6712f167e74dde9832624fb709
Author: Dmitry Gutov <address@hidden>
Date: Wed Nov 5 11:45:15 2014 +0200
Support object destructuring inside arrow function args
* js2-mode.el (js2-parse-plain-property): Don't move too far when
there's no colon.
(js2-parse-assign-expr): Restore the previous value of
`js2-parsed-errors' after arrow token is found.
Fixes #167
---
js2-mode.el | 40 ++++++++++++++++++++++------------------
tests/parser.el | 7 +++++--
2 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index ba0ba4e..0141eb4 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -8571,13 +8571,14 @@ If NODE is non-nil, it is the AST node associated with
the symbol."
(let ((tt (js2-get-token))
(pos (js2-current-token-beg))
pn left right op-pos
- ts-state recorded-identifiers)
+ ts-state recorded-identifiers parsed-errors)
(if (= tt js2-YIELD)
(js2-parse-return-or-yield tt t)
;; Save the tokenizer state in case we find an arrow function
;; and have to rewind.
(setq ts-state (make-js2-ts-state)
- recorded-identifiers js2-recorded-identifiers)
+ recorded-identifiers js2-recorded-identifiers
+ parsed-errors js2-parsed-errors)
;; not yield - parse assignment expression
(setq pn (js2-parse-cond-expr)
tt (js2-get-token))
@@ -8602,7 +8603,8 @@ If NODE is non-nil, it is the AST node associated with
the symbol."
((and (= tt js2-ARROW)
(>= js2-language-version 200))
(js2-ts-seek ts-state)
- (setq js2-recorded-identifiers recorded-identifiers)
+ (setq js2-recorded-identifiers recorded-identifiers
+ js2-parsed-errors parsed-errors)
(setq pn (js2-parse-function 'FUNCTION_ARROW (js2-current-token-beg)
nil)))
(t
(js2-unget-token)))
@@ -9600,21 +9602,23 @@ When `js2-is-in-destructuring' is t, forms like {a, b,
c} will be permitted."
(defun js2-parse-plain-property (prop)
"Parse a non-getter/setter property in an object literal.
PROP is the node representing the property: a number, name or string."
- (js2-must-match js2-COLON "msg.no.colon.prop")
- (let* ((pos (js2-node-pos prop))
- (colon (- (js2-current-token-beg) pos))
- (expr (js2-parse-assign-expr))
- (result (make-js2-object-prop-node
- :pos pos
- ;; don't include last consumed token in length
- :len (- (+ (js2-node-pos expr)
- (js2-node-len expr))
- pos)
- :left prop
- :right expr
- :op-pos colon)))
- (js2-node-add-children result prop expr)
- result))
+ (let ((pos (js2-node-pos prop))
+ colon expr)
+ (if (js2-must-match js2-COLON "msg.no.colon.prop")
+ (setq colon (- (js2-current-token-beg) pos)
+ expr (js2-parse-assign-expr))
+ (setq expr (make-js2-error-node)))
+ (let ((result (make-js2-object-prop-node
+ :pos pos
+ ;; don't include last consumed token in length
+ :len (- (+ (js2-node-pos expr)
+ (js2-node-len expr))
+ pos)
+ :left prop
+ :right expr
+ :op-pos colon)))
+ (js2-node-add-children result prop expr)
+ result)))
(defun js2-parse-getter-setter-prop (pos prop get-p)
"Parse getter or setter property in an object literal.
diff --git a/tests/parser.el b/tests/parser.el
index 1df9603..ffda856 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -222,11 +222,14 @@ the test."
(js2-deftest-parse arrow-function-with-args-and-curlies
"(a, b = 1, ...c) => { c;\n};")
+(js2-deftest-parse arrow-function-with-destructuring
+ "([{a}, b]) => { a + b;\n};")
+
(js2-deftest-parse parenless-arrow-function-prohibits-rest
- "...b => {b + 1;};" :syntax-error "=>" :errors-count 2)
+ "...b => {b + 1;};" :syntax-error "=>" :errors-count 1)
(js2-deftest-parse parenless-arrow-function-prohibits-destructuring
- "[a, b] => {a + b;};" :syntax-error "=>" :errors-count 5)
+ "[a, b] => {a + b;};" :syntax-error "=>" :errors-count 4)
;;; Automatic semicolon insertion
- [elpa] 22/46: Support ES6 number literals, (continued)
- [elpa] 22/46: Support ES6 number literals, Dmitry Gutov, 2014/11/15
- [elpa] 21/46: js2-get-token-internal-1: add a FIXME, Dmitry Gutov, 2014/11/15
- [elpa] 20/46: js2-read-unicode-escape: use a stricter regexp, Dmitry Gutov, 2014/11/15
- [elpa] 29/46: Fontify negation operator, Dmitry Gutov, 2014/11/15
- [elpa] 32/46: Fix #171, Dmitry Gutov, 2014/11/15
- [elpa] 31/46: js2-mode-find-enclosing-node: Make docstring and impl consistent with name, Dmitry Gutov, 2014/11/15
- [elpa] 33/46: js2-parse-primary-expr: Make some vars "more" local, Dmitry Gutov, 2014/11/15
- [elpa] 34/46: Add imenu support for the Sencha framework, Dmitry Gutov, 2014/11/15
- [elpa] 36/46: Indent before inequality operator at bol, Dmitry Gutov, 2014/11/15
- [elpa] 38/46: Indent after `+=', Dmitry Gutov, 2014/11/15
- [elpa] 37/46: Support object destructuring inside arrow function args,
Dmitry Gutov <=
- [elpa] 30/46: js2-imenu-extras.el: Use Unix-style EOL, Dmitry Gutov, 2014/11/15
- [elpa] 42/46: js2-imenu-walk-ast: Look up js2-imenu-show-module-pattern in v-i-n case, too, Dmitry Gutov, 2014/11/15
- [elpa] 40/46: Support orphan functions on the right side of assignments, Dmitry Gutov, 2014/11/15
- [elpa] 35/46: Merge pull request #173 from lelit/master, Dmitry Gutov, 2014/11/15
- [elpa] 43/46: Fix toggling single-line comments, Dmitry Gutov, 2014/11/15
- [elpa] 41/46: js2-imenu-record-module-pattern: Support `js2-var-init-node', Dmitry Gutov, 2014/11/15
- [elpa] 46/46: Merge commit '2c744815cf9e4653625dd25f2e7f8b59c152782d' from js2-mode, Dmitry Gutov, 2014/11/15
- [elpa] 45/46: Bump the version, Dmitry Gutov, 2014/11/15
- [elpa] 44/46: Merge pull request #180 from simenheg/master, Dmitry Gutov, 2014/11/15
- [elpa] 39/46: Check in LICENSE, Dmitry Gutov, 2014/11/15