   if pass then return node else return null
 
 
-# Return the next Node in a first-to-last-child post-order traversal.
-postFirst = (node) ->
-  if node.nextSibling?
-    return firstLeaf(node.nextSibling)
-  return node.parentNode
-
-
-# Return the next Node in a last-to-first-child post-order traversal.
-postLast = (node) ->
-  if node.previousSibling?
-    return lastLeaf(node.previousSibling)
-  return node.parentNode
+# Return the next Node in a first-to-last-child pre-order traversal.
+preFirst = (node) ->
+  if node.firstChild?
+    return node.firstChild
+
+  while not node.nextSibling?
+    node = node.parentNode
+    if node is null then return null
+
+  return node.nextSibling
+
+
+# Return the next Node in a last-to-first-child pre-order traversal.
+preLast = (node) ->
+  if node.lastChild?
+    return node.lastChild
+
+  while not node.previousSibling?
+    node = node.parentNode
+    if node is null then return null
+
+  return node.previousSibling
 
 
 # Find the first leaf node.

# Get all the text Nodes within a Node.
getTextNodes = (root) ->
  text = []
  node = firstLeaf(root)
  while node = findNode(node, root, isTextNode, postFirst)
    text.push(node)
    if node is root then break
    node = postFirst(node)
  return text



      endContainer = firstLeaf(endContainer.childNodes[endOffset])
      endOffset = 0

    # The above implies that a pre-order traversal visits every Node in the
    # Range before visiting the last leaf of the end container.
    first = firstLeaf(startContainer)

    # Similarly, a pre-order traversal that reverses the children visits every
    # Node in the Range before visiting the first leaf of the start container.
    last = lastLeaf(endContainer)

    # Any TextNode in the traversal is valid unless excluded by the offset.
    checkNode = (node) ->
