MCPcopy
hub / github.com/ampproject/worker-dom / replaceWith

Function replaceWith

src/worker-thread/dom/Node.ts:366–391  ·  view source on GitHub ↗

* 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>)

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 1

createTextNodeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…