A subtree is a representation of part of the syntax tree. It may either be the tree root, or a tagged node.
abstract parent: Subtree | null
The subtree's parent. Will be
null for the root node
abstract tag: Tag
The node's tag. Will be
Tag.empty for the root
abstract start: number
The start source offset of this subtree
abstract end: number
The end source offset
readonly depth: number
The depth (number of parent nodes) of this subtree
readonly root: Tree
The root of the tree that this subtree is part of
abstract iterate<T = any>(from: number, to: number, enter: EnterFunc<T>, leave?: LeaveFunc) → undefined | T
Iterate over all nodes in this subtree. Will iterate through the tree in, calling
enter for each node it enters and, if given,
leave when it leaves a node.
resolve(pos: number, side?: -1 | 0 | 1 = 0) → Subtree
Find the node at a given position. By default, this will return the lowest-depth subtree that covers the position from both sides, meaning that nodes starting or ending at the position aren't entered. You can pass a
-1 to enter nodes that end at the position, or
1 to enter nodes that start there.
abstract childBefore(pos: number) → null | Subtree
Find the child tree before the given position, if any.
abstract childAfter(pos: number) → null | Subtree
Find the child tree after the given position, if any.
readonly firstChild: null | Subtree
Get the first child of this subtree.
readonly lastChild: null | Subtree
Find the last child of this subtree.