[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/js2-mode fc323ad 02/61: Fix issue #515 by improving the
From: |
Dmitry Gutov |
Subject: |
[elpa] externals/js2-mode fc323ad 02/61: Fix issue #515 by improving the detection of destructured function params |
Date: |
Sun, 20 Dec 2020 12:19:56 -0500 (EST) |
branch: externals/js2-mode
commit fc323ad412a51309789b6d693c69afc98adb9020
Author: Lele Gaifax <lele@metapensiero.it>
Commit: Lele Gaifax <lele@metapensiero.it>
Fix issue #515 by improving the detection of destructured function params
---
js2-mode.el | 40 ++++++++++++++++++++++++++++++++++++----
1 file changed, 36 insertions(+), 4 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index fb5d6d5..567d629 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -7168,7 +7168,8 @@ key of a literal object."
;; ignore later
(when (and (not declared)
(js2-object-prop-node-p parent)
- (eq node (js2-object-prop-node-left parent)))
+ (eq node (js2-object-prop-node-left parent))
+ (not (eq node (js2-object-prop-node-right parent))))
(setq object-key t)))
;; Maybe this is a for loop and the variable is one of its iterators?
(unless assigned
@@ -7188,10 +7189,41 @@ key of a literal object."
finally return syms))))))
(list declared assigned object-key)))
+(defun js2--is-param (var-node params)
+ "Recursively determine whether VAR-NODE is contained in PARAMS."
+ (cond ((js2-object-prop-node-p params)
+ (eq var-node (js2-object-prop-node-left params)))
+ ((js2-name-node-p params)
+ (eq var-node params))
+ (t
+ (let ((isparam (if (listp params)
+ (memq var-node params)
+ (cl-loop with found = nil
+ for p in (js2-node-child-list params)
+ while (null found)
+ do (setq found (eq var-node p))))))
+ (unless isparam
+ (let ((kids (if (listp params)
+ params
+ (js2-node-child-list params))))
+ (cl-loop for p in kids
+ while (null isparam)
+ do (setq isparam (js2--is-param var-node p)))))
+ isparam))))
+
+(defun js2--is-function-param (parent var-node)
+ "Determine whether VAR-NODE is a function parameter."
+ (while (and parent (not (js2-function-node-p parent)))
+ (if (or (js2-var-init-node-p parent)
+ (js2-assign-node-p parent))
+ (setq parent nil)
+ (setq parent (js2-node-parent parent))))
+ (when parent
+ (js2--is-param var-node (js2-function-node-params parent))))
+
(defun js2--classify-variable (parent node vars)
- "Classify the single variable NODE, a js2-name-node."
- (let ((function-param (and (js2-function-node-p parent)
- (memq node (js2-function-node-params parent)))))
+ "Classify the single variable NODE, a js2-name-node, updating the VARS
collection."
+ (let ((function-param (js2--is-function-param parent node)))
(if (js2-prop-get-node-p parent)
;; If we are within a prop-get, e.g. the "bar" in "foo.bar",
;; just mark "foo" as used
- [elpa] externals/js2-mode updated (474c396 -> 29979e5), Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode fc323ad 02/61: Fix issue #515 by improving the detection of destructured function params,
Dmitry Gutov <=
- [elpa] externals/js2-mode 392492e 03/61: Merge pull request #517 from lelit/issue515, Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode f3c75fd 01/61: Add failing tests on issue #515, Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode fec511d 04/61: Add failing test on issue #518, Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode e8da0b4 05/61: Fix issue #518, considering class definition as initialization, Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode 7db4871 06/61: Merge pull request #519 from lelit/issue518, Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode 5434da3 10/61: [ci skip] Link to INSTALL.REPO, Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode 46aed6d 11/61: Extend explanation to disclaim key issue but provide an alternative, Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode ae9fea8 07/61: Make js2-minor-mode avoid changing the syntax-table text property, Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode bf7191c 08/61: Recommend js-mode + js2-minor-mode and Emacs 27 for JSX, Dmitry Gutov, 2020/12/20
- [elpa] externals/js2-mode 2ce4985 09/61: [ci skip] Stop mentioning Emacs 22 and 23, Dmitry Gutov, 2020/12/20