[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master bc5cdb4 23/38: Simplified property name matching
From: |
Dmitry Gutov |
Subject: |
[elpa] master bc5cdb4 23/38: Simplified property name matching |
Date: |
Wed, 09 Sep 2015 18:41:46 +0000 |
branch: master
commit bc5cdb412d34b3b441f2c817e7e2dd0f9865e5ad
Author: ScottyB <address@hidden>
Commit: ScottyB <address@hidden>
Simplified property name matching
---
js2-mode.el | 43 ++++++++++++++++++++-----------------------
tests/navigation.el | 15 ++++++++++-----
2 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 5b4ddc5..ce95353 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -12354,17 +12354,15 @@ Supports navigation to 'foo.bar = 3' and 'foo = {bar:
3}'."
(let ((parent (js2-node-parent node))
matching-node)
(unless endp
- (if (or (and (js2-prop-get-node-p node)
- (not (or (js2-elem-get-node-p parent) (js2-call-node-p
parent)))
- (setq matching-node (js2-build-prop-name-list node
list-names)))
- (and (js2-name-node-p node)
- (js2-object-prop-node-p parent)
- (string= (js2-name-node-name node)
- (first list-names))))
+ (if (and (js2-name-node-p node)(setq matching-node (or
+ (js2-build-prop-name-list node list-names)
+ (and (js2-object-prop-node-p parent)
+ (string= (js2-name-node-name node)
+ (first list-names))
+ node))))
(throw 'prop-found matching-node))
t))))))
-
(defun js2-name-declaration (name)
"Return the declaration node for node named NAME."
(let* ((node (js2-root-or-node))
@@ -12392,22 +12390,21 @@ the function."
node
(js2-node-get-enclosing-scope node))))
-(defun js2-build-prop-name-list (prop-node list-names)
- "Compare the names in PROP-NODE to the ones in LIST-NAMES.
+(defun js2-build-prop-name-list (name-node list-names)
+ "Compare the names in NAME-NODE to the ones in LIST-NAMES.
Returns the matching node to jump to or nil."
- (let* (temp-node
- match-node)
- (unless (js2-prop-get-node-p prop-node)
- (error "Node is not a property prop-node"))
- (catch 'not-a-match
- (while (js2-prop-get-node-p prop-node)
- (setq temp-node (js2-prop-get-node-right prop-node))
- (unless (string= (car list-names) (js2-name-node-name temp-node))
- (throw 'not-a-match match-node))
- (unless match-node
- (setq match-node temp-node))
- (pop list-names)
- (setq prop-node (js2-node-parent prop-node))))))
+ (let ((list-names (reverse list-names))
+ (next-prop (js2-node-parent name-node)))
+ ;; check right side properties
+ (when (string= (pop list-names)
+ (js2-name-node-name name-node))
+ ;; check left side properties
+ (while (and list-names
+ (js2-prop-get-node-p next-prop)
+ (string= (pop list-names)
+ (js2-name-node-name
+ (setq next-prop (js2-prop-get-node-right
next-prop)))))))
+ (unless list-names name-node)))
(defun js2-get-function-node (name scope)
"Return node of function named NAME in SCOPE."
diff --git a/tests/navigation.el b/tests/navigation.el
index bbd4861..78b61f2 100644
--- a/tests/navigation.el
+++ b/tests/navigation.el
@@ -22,13 +22,15 @@
(require 'ert)
(require 'js2-mode)
-(cl-defun js2-navigation-helper (buffer-content expected-point &optional
(point-offset 1))
+(cl-defun js2-navigation-helper (buffer-content &optional expected-point
(point-offset 1))
(with-temp-buffer
(insert buffer-content)
- (js2-mode)
- (goto-char (or (- (point) point-offset)))
- (js2-jump-to-definition)
- (should (= (point) expected-point))))
+ (let ((start-point (or (- (point) point-offset))))
+ (js2-mode)
+ (goto-char start-point)
+ (js2-jump-to-definition)
+ (print (format "%d %d" (point) start-point))
+ (should (= (point) (or expected-point start-point))))))
(ert-deftest js2-jump-to-var ()
(js2-navigation-helper "var soup = 2; soup" 5))
@@ -41,3 +43,6 @@
(ert-deftest js2-jump-to-object-property ()
(js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"};
aObject.prop1" 16))
+
+;; (ert-deftest js2-jump-to-object-property ()
+;; (js2-navigation-helper "var aObject = {prop1: 3, prop2: \"hello\"};
anotherObject.dprop1"))
- [elpa] master 242af01 14/38: Handle @property like @param, and handle aliases, (continued)
- [elpa] master 242af01 14/38: Handle @property like @param, and handle aliases, Dmitry Gutov, 2015/09/09
- [elpa] master c68646a 12/38: Never enable js2-minor-mode in js2-mode, Dmitry Gutov, 2015/09/09
- [elpa] master 5beb8ea 13/38: Define js2-re-search-forward as an alias as well, Dmitry Gutov, 2015/09/09
- [elpa] master fc56c58 16/38: js2-define-destruct-symbols-internal: Anticipate js2-getter-setter-node, Dmitry Gutov, 2015/09/09
- [elpa] master c8b8e11 19/38: js2-define-destruct-symbols: Speed up, theoretically, Dmitry Gutov, 2015/09/09
- [elpa] master a6f2a94 15/38: Allow plain parameters after default, Dmitry Gutov, 2015/09/09
- [elpa] master d0686a0 18/38: js2-define-destruct-symbols-internal: Remove, don't need it anymore, Dmitry Gutov, 2015/09/09
- [elpa] master f146f13 17/38: js2-define-destruct-symbols-internal: Stop growing NAME-NODES exponentially, Dmitry Gutov, 2015/09/09
- [elpa] master eba59c5 21/38: Added missing etags dependency, Dmitry Gutov, 2015/09/09
- [elpa] master 7184664 20/38: Add a jump to definition command bound to M-., Dmitry Gutov, 2015/09/09
- [elpa] master bc5cdb4 23/38: Simplified property name matching,
Dmitry Gutov <=
- [elpa] master 1ee5c45 22/38: Return correct node when searching for the definition of a property., Dmitry Gutov, 2015/09/09
- [elpa] master 579aacb 24/38: Simplified method of searching for nodes based on scope, Dmitry Gutov, 2015/09/09
- [elpa] master f942b83 26/38: Support jumping to buffers of the same major mode, Dmitry Gutov, 2015/09/09
- [elpa] master 145c5d6 25/38: Fixed jumping to object properties, Dmitry Gutov, 2015/09/09
- [elpa] master bb0476c 29/38: Clarified js2-search-scope doc string, Dmitry Gutov, 2015/09/09
- [elpa] master c4f4095 28/38: Only jump if not already at var or function definition, Dmitry Gutov, 2015/09/09
- [elpa] master af85699 30/38: Clean up todo in js2-search-scope and fix year typo, Dmitry Gutov, 2015/09/09
- [elpa] master aaf218a 27/38: Find definition by locating assignment nodes, Dmitry Gutov, 2015/09/09
- [elpa] master e236923 31/38: Removed functions: js2-build-prop-name-list and js2-names-left., Dmitry Gutov, 2015/09/09
- [elpa] master 75129c1 33/38: Use cl-assert instead of error, Dmitry Gutov, 2015/09/09