* Replaces the current node with the provided Array . * @param nodes * @see https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/replaceWith
(...nodes: Array<Node | string>)
| 364 | * @see https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/replaceWith |
| 365 | */ |
| 366 | public replaceWith(...nodes: Array<Node | string>): void { |
| 367 | const parent: Node | null = this.parentNode; |
| 368 | let nodeIterator: number = nodes.length; |
| 369 | let currentNode: Node | string; |
| 370 | if (!parent) { |
| 371 | return; |
| 372 | } |
| 373 | if (!nodeIterator) { |
| 374 | parent.removeChild(this); |
| 375 | } |
| 376 | while (nodeIterator--) { |
| 377 | currentNode = nodes[nodeIterator]; |
| 378 | |
| 379 | if (typeof currentNode !== 'object') { |
| 380 | currentNode = this.ownerDocument.createTextNode(currentNode); |
| 381 | } |
| 382 | |
| 383 | // TODO: Investigate inserting all new nodes in a single operation. |
| 384 | if (!nodeIterator) { |
| 385 | // currentNode is the first argument (currentNode === arguments[0]) |
| 386 | parent.replaceChild(currentNode as Node, this); |
| 387 | } else { |
| 388 | parent.insertBefore(currentNode as Node, this.nextSibling); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /** |
| 394 | * Removes this Node from the tree it belogs too. |
nothing calls this directly
no test coverage detected
searching dependent graphs…