Return an array of ancestor nodes. The first element of this array is the same as this.parent() and the last element is the root node. If we are currently at the root node, the the returned array will be empty. This method makes a copy of the internal state, so modifications to the returned array have no effect on the traversal.
Return a new TraversalState object that is a copy of this one. This method is useful in conjunction with the mutating methods goToParent() and goToPreviousSibling().
Return the current node in the traversal. Any time the traversal callback is called, this method will return the name value as the first argument to the callback.
Returns true if this TraversalState object is equal to that TraversalState object, or false otherwise. This method exists primarily for use by our unit tests.
Modify this object to look like it will look when we (later) visit the parent node of this node. You should not modify the instance passed to the tree traversal callback. Instead, make a copy with the clone() method and modify that. This mutator method is not typically used during ordinary tree traversals, but is used by the Selector class for matching multi-node selectors that involve parent and ancestor selectors.
Modify this traversal state object to have the state it would have had when visiting the previous sibling. Note that you may want to use clone() to make a copy before modifying the state object like this. This mutator method is not typically used during ordinary tree traversals, but is used by the Selector class for matching multi-node selectors.
Returns true if the current node has an ancestor and false otherwise. If this method returns false, then the parent() method will return null and goToParent() will throw an error
Returns true if the current node has a previous sibling and false otherwise. If this method returns false, then previousSibling() will return null, and goToPreviousSibling() will throw an error.
Return the next sibling of this node, if it has one, or null otherwise.
Return the parent of the current node, if there is one, or null.
Return the previous sibling of this node, if it has one, or null otherwise.
Remove the next sibling node (if there is one) from the tree. Returns the removed sibling or null. This method makes it easy to traverse a tree and concatenate adjacent text nodes into a single node.
Replace the current node in the tree with the specified nodes. If no nodes are passed, this is a node deletion. If one node (or array) is passed, this is a 1-for-1 replacement. If more than one node is passed then this is a combination of deletion and insertion. The new node or nodes will not be traversed, so this method can safely be used to reparent the current node node beneath a new parent.
This method throws an error if you attempt to replace the root node of the tree.
This class represents the state of a tree traversal. An instance is created by the traverse() method of the TreeTransformer class to maintain the state for that traversal, and the instance is passed to the traversal callback function for each node that is traversed. This class is not intended to be instantiated directly, but is exported so that its type can be used for type annotaions.