Perseus
    Preparing search index...

    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.

    Index

    Constructors

    Properties

    _ancestors: Stack<TreeNode>
    _containers: Stack<TreeNode | TreeNode[]>
    _currentNode: TreeNode | null | undefined
    _indexes: Stack<string | number>
    root: TreeNode

    Methods

    • 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.

      Returns readonly TreeNode[]

    • 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.

      Returns void

    • 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 void

    • 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 boolean

    • 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.

      Returns boolean

    • 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.

      Returns TreeNode | null | undefined

    • 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.

      Parameters

      Returns void