branch: elpa/clojure-ts-mode
commit afc3c96c7180fa98cddb8bb54b395a3478296874
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>

    Guard against nil nodes in named-node-text and node-namespace-text
    
    treesit-node-text errors on nil input. These functions can receive
    nil when a node has no children (e.g. an empty list), so guard with
    when-let* to return nil instead of erroring.
---
 clojure-ts-mode.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/clojure-ts-mode.el b/clojure-ts-mode.el
index 8dd5b28235..e85a289545 100644
--- a/clojure-ts-mode.el
+++ b/clojure-ts-mode.el
@@ -985,13 +985,15 @@ literals with regex grammar."
 (defun clojure-ts--named-node-text (node)
   "Gets the name of a symbol or keyword NODE.
 This does not include the NODE's namespace."
-  (treesit-node-text (treesit-node-child-by-field-name node "name")))
+  (when-let* ((name-node (treesit-node-child-by-field-name node "name")))
+    (treesit-node-text name-node)))
 
 (defun clojure-ts--node-namespace-text (node)
   "Gets the namespace of a symbol or keyword NODE.
 
 If there is no namespace, returns nil."
-  (treesit-node-text (treesit-node-child-by-field-name node "namespace")))
+  (when-let* ((ns-node (treesit-node-child-by-field-name node "namespace")))
+    (treesit-node-text ns-node)))
 
 (defun clojure-ts--symbol-named-p (expected-symbol-name node)
   "Return non-nil if NODE is a symbol with text matching EXPECTED-SYMBOL-NAME."

Reply via email to