[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 58857dc 103/110: Merge branch 'dgreensp-object-rest-spread
From: |
Dmitry Gutov |
Subject: |
[elpa] master 58857dc 103/110: Merge branch 'dgreensp-object-rest-spread' |
Date: |
Thu, 23 Jun 2016 01:13:03 +0000 (UTC) |
branch: master
commit 58857dc01d4de5196f39f02afd12151ac4d0d349
Merge: ae3ed93 2a904e0
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Merge branch 'dgreensp-object-rest-spread'
---
js2-mode.el | 98 +++++++++++++++++++++++++++++++------------------------
tests/parser.el | 6 ++++
2 files changed, 62 insertions(+), 42 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 238440c..4d9bbf8 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -7456,22 +7456,23 @@ We do a depth-first traversal of NODE. For any
functions we find,
we append the property name to QNAME, then call `js2-record-imenu-entry'."
(let (right)
(dolist (e (js2-object-node-elems node)) ; e is a `js2-object-prop-node'
- (let ((left (js2-infix-node-left e))
- ;; Element positions are relative to the parent position.
- (pos (+ pos (js2-node-pos e))))
- (cond
- ;; foo: function() {...}
- ((js2-function-node-p (setq right (js2-infix-node-right e)))
- (when (js2-prop-node-name left)
- ;; As a policy decision, we record the position of the property,
- ;; not the position of the `function' keyword, since the property
- ;; is effectively the name of the function.
- (js2-record-imenu-entry right (append qname (list left)) pos)))
- ;; foo: {object-literal} -- add foo to qname, offset position, and
recurse
- ((js2-object-node-p right)
- (js2-record-object-literal right
- (append qname (list (js2-infix-node-left
e)))
- (+ pos (js2-node-pos right)))))))))
+ (when (js2-infix-node-p e)
+ (let ((left (js2-infix-node-left e))
+ ;; Element positions are relative to the parent position.
+ (pos (+ pos (js2-node-pos e))))
+ (cond
+ ;; foo: function() {...}
+ ((js2-function-node-p (setq right (js2-infix-node-right e)))
+ (when (js2-prop-node-name left)
+ ;; As a policy decision, we record the position of the property,
+ ;; not the position of the `function' keyword, since the property
+ ;; is effectively the name of the function.
+ (js2-record-imenu-entry right (append qname (list left)) pos)))
+ ;; foo: {object-literal} -- add foo to qname, offset position, and
recurse
+ ((js2-object-node-p right)
+ (js2-record-object-literal right
+ (append qname (list
(js2-infix-node-left e)))
+ (+ pos (js2-node-pos right))))))))))
(defun js2-node-top-level-decl-p (node)
"Return t if NODE's name is defined in the top-level scope.
@@ -8098,21 +8099,25 @@ declared; probably to check them for errors."
(list node)))
((js2-object-node-p node)
(dolist (elem (js2-object-node-elems node))
- ;; js2-infix-node-p catches both object prop node and initialized
- ;; binding element (which is directly an infix node).
- (cond
- ((js2-object-prop-node-p elem)
- (push (js2-define-destruct-symbols
- ;; In abbreviated destructuring {a, b}, right == left.
- (js2-object-prop-node-right elem)
- decl-type face ignore-not-in-block)
- name-nodes))
- ;; Destructuring with default argument.
- ((js2-infix-node-p elem)
- (push (js2-define-destruct-symbols
- (js2-infix-node-left elem)
- decl-type face ignore-not-in-block)
- name-nodes))))
+ (let ((subexpr (cond
+ ((and (js2-infix-node-p elem)
+ (= js2-ASSIGN (js2-infix-node-type elem)))
+ ;; Destructuring with default argument.
+ (js2-infix-node-left elem))
+ ((and (js2-infix-node-p elem)
+ (= js2-COLON (js2-infix-node-type elem)))
+ ;; In regular destructuring {a: aa, b: bb},
+ ;; the var is on the right. In abbreviated
+ ;; destructuring {a, b}, right == left.
+ (js2-infix-node-right elem))
+ ((and (js2-unary-node-p elem)
+ (= js2-TRIPLEDOT (js2-unary-node-type elem)))
+ ;; Destructuring with spread.
+ (js2-unary-node-operand elem)))))
+ (when subexpr
+ (push (js2-define-destruct-symbols
+ subexpr decl-type face ignore-not-in-block)
+ name-nodes))))
(apply #'append (nreverse name-nodes)))
((js2-array-node-p node)
(dolist (elem (js2-array-node-elems node))
@@ -10738,16 +10743,19 @@ If ONLY-OF-P is non-nil, only the 'for (foo of bar)'
form is allowed."
`js2-method-node') as a string, or nil if it can't be
represented as a string (e.g., the key is computed by an
expression)."
- (let ((key (js2-infix-node-left property-node)))
- (when (js2-computed-prop-name-node-p key)
- (setq key (js2-computed-prop-name-node-expr key)))
- (cond
- ((js2-name-node-p key)
- (js2-name-node-name key))
- ((js2-string-node-p key)
- (js2-string-node-value key))
- ((js2-number-node-p key)
- (js2-number-node-value key)))))
+ (cond
+ ((js2-unary-node-p property-node) nil) ;; {...foo}
+ (t
+ (let ((key (js2-infix-node-left property-node)))
+ (when (js2-computed-prop-name-node-p key)
+ (setq key (js2-computed-prop-name-node-expr key)))
+ (cond
+ ((js2-name-node-p key)
+ (js2-name-node-name key))
+ ((js2-string-node-p key)
+ (js2-string-node-value key))
+ ((js2-number-node-p key)
+ (js2-number-node-value key)))))))
(defun js2-parse-object-literal-elems (&optional class-p)
(let ((pos (js2-current-token-beg))
@@ -10782,7 +10790,13 @@ expression)."
(setq previous-token (js2-current-token)
tt (js2-get-prop-name-token))))
(cond
- ;; Found a property (of any sort)
+ ;; Rest/spread (...expr)
+ ((and (>= js2-language-version 200)
+ (not class-p) (not static) (not previous-token)
+ (= js2-TRIPLEDOT tt))
+ (setq after-comma nil
+ elem (js2-make-unary js2-TRIPLEDOT 'js2-parse-assign-expr)))
+ ;; Found a key/value property (of any sort)
((member tt (list js2-NAME js2-STRING js2-NUMBER js2-LB))
(setq after-comma nil
elem (js2-parse-named-prop tt previous-token))
diff --git a/tests/parser.el b/tests/parser.el
index b546c1c..9667e56 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -390,6 +390,12 @@ the test."
(js2-deftest-parse array-destructure-expr-default
"let [[x] = [3]] = y;")
+(js2-deftest-parse spread-in-object-literal
+ "f({x, y, ...z});")
+
+(js2-deftest-parse rest-in-object-literal
+ "const {x, y, ...z} = f();")
+
;;; Arrow functions
(js2-deftest-parse arrow-function-with-empty-args-and-no-curlies
- [elpa] master 502c14a 003/110: Use = instead of eq; Refs #185, (continued)
- [elpa] master 502c14a 003/110: Use = instead of eq; Refs #185, Dmitry Gutov, 2016/06/22
- [elpa] master 73c0348 062/110: Merge pull request #297 from Christoph-D/master, Dmitry Gutov, 2016/06/22
- [elpa] master 49954ea 084/110: Use idle timer to reparse, even when the buffer's just been opened, Dmitry Gutov, 2016/06/22
- [elpa] master 1e1e410 082/110: Merge pull request #289 from dgreensp/fix-array-rest, Dmitry Gutov, 2016/06/22
- [elpa] master 16c42ce 087/110: Run all tests on 'make test', Dmitry Gutov, 2016/06/22
- [elpa] master e265b69 090/110: Fix a byte compilation warning on Emacs 25, Dmitry Gutov, 2016/06/22
- [elpa] master 87f43f3 089/110: Fix more remaining failures, Dmitry Gutov, 2016/06/22
- [elpa] master 6d22df2 094/110: Colorize imported names as variables, Dmitry Gutov, 2016/06/22
- [elpa] master bc46db5 104/110: Add a test for #335 as well, Dmitry Gutov, 2016/06/22
- [elpa] master 92f5479 108/110: Parse generator methods better, Dmitry Gutov, 2016/06/22
- [elpa] master 58857dc 103/110: Merge branch 'dgreensp-object-rest-spread',
Dmitry Gutov <=
- [elpa] master 0cda392 109/110: Make a new release, Dmitry Gutov, 2016/06/22
- [elpa] master be0b00d 063/110: js2-mode-extend-comment: Don't check that the next line is also commented, Dmitry Gutov, 2016/06/22
- [elpa] master 757f91d 065/110: And move its definition below, Dmitry Gutov, 2016/06/22
- [elpa] master 7e0b11f 071/110: Add tests for of parsing, Dmitry Gutov, 2016/06/22
- [elpa] master 83d9890 070/110: Fix await parsing, Dmitry Gutov, 2016/06/22
- [elpa] master bacb022 074/110: Refactor async arrow function matching, Dmitry Gutov, 2016/06/22
- [elpa] master 57dca37 073/110: Refactor await parsing to only parse once, Dmitry Gutov, 2016/06/22
- [elpa] master 60f7a2b 080/110: Fix computed property generator methods indentation, Dmitry Gutov, 2016/06/22
- [elpa] master de6df33 049/110: Fix semicolons and scoping in exported decls, Dmitry Gutov, 2016/06/22
- [elpa] master dbf4fe9 038/110: Adapt async/await changes to latest master, Dmitry Gutov, 2016/06/22