]> code.delx.au - gnu-emacs-elpa/commitdiff
Fix js2-node-get-enclosing-scope
authorJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sun, 1 Mar 2015 07:23:23 +0000 (23:23 -0800)
committerJackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Sun, 1 Mar 2015 07:31:25 +0000 (23:31 -0800)
Previously this function discriminated against nodes that did not have
parents.  For such nodes, nil should have been returned, but instead an
error was emitted because a parentless node would produce the initial
parent nil, which would cause js2-node-parent to blow up.  This fixes
that.

js2-mode.el

index 5424ff00a961d0905579ed2c21c8247aaecf9d15..41bc507920febd6c5683c080e7b9dff7602465a6 100644 (file)
@@ -2307,10 +2307,9 @@ If any given node in NODES is nil, doesn't record that link."
 (defun js2-node-get-enclosing-scope (node)
   "Return the innermost `js2-scope' node surrounding NODE.
 Returns nil if there is no enclosing scope node."
-  (let ((parent (js2-node-parent node)))
-    (while (not (js2-scope-p parent))
-      (setq parent (js2-node-parent parent)))
-    parent))
+  (while (and (setq node (js2-node-parent node))
+              (not (js2-scope-p node))))
+  node)
 
 (defun js2-get-defining-scope (scope name &optional point)
   "Search up scope chain from SCOPE looking for NAME, a string or symbol.