about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-09-14 12:09:29 +0200
committerbptato <nincsnevem662@gmail.com>2023-09-14 12:09:29 +0200
commitf2930dad3e29e71a446bfcf2d04078af02fdedd0 (patch)
tree5a12237bd5d8809559c210fd02fca450946ecf15
parent15c722c013c209e72a277908276c3d851943ecdd (diff)
downloadchawan-f2930dad3e29e71a446bfcf2d04078af02fdedd0.tar.gz
dom: fix incorrect iteration in descendants
-rw-r--r--src/html/dom.nim5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index 7843a424..7e2d967b 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -883,11 +883,12 @@ iterator branch*(node: Node): Node {.inline.} =
 # Returns the node's descendants
 iterator descendants*(node: Node): Node {.inline.} =
   var stack: seq[Node]
-  stack.add(node)
+  for i in countdown(node.childList.high, 0):
+    stack.add(node.childList[i])
   while stack.len > 0:
     let node = stack.pop()
+    yield node
     for i in countdown(node.childList.high, 0):
-      yield node.childList[i]
       stack.add(node.childList[i])
 
 iterator elements*(node: Node): Element {.inline.} =