replaceWith method
Replaces this node with another node.
Implementation
Node replaceWith(Node otherNode) {
  if (parentNode == null) {
    throw UnsupportedError('Node must have a parent to replace it.');
  }
  parentNode!.nodes[parentNode!.nodes.indexOf(this)] = otherNode;
  return this;
}