MCPcopy
hub / github.com/jsdom/jsdom / _insert

Method _insert

lib/jsdom/living/nodes/Node-impl.js:781–877  ·  view source on GitHub ↗
(nodeImpl, childImpl, suppressObservers)

Source from the content-addressed store, hash-verified

779
780 // https://dom.spec.whatwg.org/#concept-node-insert
781 _insert(nodeImpl, childImpl, suppressObservers) {
782 const count = nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE ?
783 domSymbolTree.childrenCount(nodeImpl) :
784 1;
785
786 if (childImpl) {
787 const childIndex = domSymbolTree.index(childImpl);
788
789 for (const range of this._liveRanges()) {
790 const { _start, _end } = range;
791
792 if (_start.offset > childIndex) {
793 range._setLiveRangeStart(this, _start.offset + count);
794 }
795
796 if (_end.offset > childIndex) {
797 range._setLiveRangeEnd(this, _end.offset + count);
798 }
799 }
800 }
801
802 const nodesImpl = nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE ?
803 domSymbolTree.childrenToArray(nodeImpl) :
804 [nodeImpl];
805
806 if (nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE) {
807 let grandChildImpl;
808 while ((grandChildImpl = domSymbolTree.firstChild(nodeImpl))) {
809 nodeImpl._remove(grandChildImpl, true);
810 }
811 }
812
813 if (nodeImpl.nodeType === NODE_TYPE.DOCUMENT_FRAGMENT_NODE) {
814 queueTreeMutationRecord(nodeImpl, [], nodesImpl, null, null);
815 }
816
817 const previousChildImpl = childImpl ?
818 domSymbolTree.previousSibling(childImpl) :
819 domSymbolTree.lastChild(this);
820
821 let isConnected;
822
823 for (const node of nodesImpl) {
824 if (!childImpl) {
825 domSymbolTree.appendChild(this, node);
826 } else {
827 domSymbolTree.insertBefore(childImpl, node);
828 }
829
830 if (
831 (this.nodeType === NODE_TYPE.ELEMENT_NODE && this._shadowRoot !== null) &&
832 (node.nodeType === NODE_TYPE.ELEMENT_NODE || node.nodeType === NODE_TYPE.TEXT_NODE)
833 ) {
834 assignSlot(node);
835 }
836
837 this._modified();
838

Callers 10

_preInsertMethod · 0.95
_replaceMethod · 0.95
_replaceAllMethod · 0.95
appendChildFunction · 0.45
insertBeforeMethod · 0.45
titleMethod · 0.45
insertAdjacentHTMLMethod · 0.45
insertRowMethod · 0.45
splitTextMethod · 0.45
insertCellMethod · 0.45

Calls 15

_liveRangesMethod · 0.95
_modifiedMethod · 0.95
_descendantAddedMethod · 0.95
queueTreeMutationRecordFunction · 0.85
assignSlotFunction · 0.85
isSlotFunction · 0.85
isShadowRootFunction · 0.85
nodeRootFunction · 0.85
signalSlotChangeFunction · 0.85
assignSlotableForTreeFunction · 0.85

Tested by

no test coverage detected