All files / src/virtual-dom MarkupParsingResult.ts

83.33% Statements 10/12
50% Branches 2/4
66.67% Functions 2/3
83.33% Lines 10/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77        12x                     105x               30x     30x       10x   10x           20x   20x   20x   20x                                                                
// import ElementNode from "./nodes/ElementNode";
// import FragmentNode from "./nodes/FragmentNode";
// import TextNode from "./nodes/TextNode";
 
export default class MarkupParsingResult {
 
    constructor(
        /**
         * The virtual node extracted from the node parsed from the markup
         */
        //public vnode?: ElementNode | TextNode | FragmentNode | null,
 
        /**
         * The DOM node parsed from the markup
         */
        public node?: Node | DocumentFragment
    ) { }
 
    appendSibling(result: MarkupParsingResult): MarkupParsingResult {
 
        const {
            //vnode,
            node
        } = this;
 
        //if ((vnode.constructor as any).isFragment) {
        if (node instanceof DocumentFragment) {
 
            //(vnode as FragmentNode).children.push(result.vnode as any);
 
            node.insertBefore(result.node, null);
 
            return this;
        }
        else { // Wrap it in a fragment
 
            //const wrapperVNode = new FragmentNode([ vnode as ElementNode, result.vnode as ElementNode]);
 
            const wrapperNode = new DocumentFragment();
 
            wrapperNode.insertBefore(node, null);
 
            wrapperNode.insertBefore(result.node, null);
 
            return new MarkupParsingResult(/*wrapperVNode,*/ wrapperNode);
        }
    }
 
    patch(result: MarkupParsingResult, container: HTMLElement): void {
 
        const {
            node
        } = result;
 
        container = node instanceof DocumentFragment ?
            container :
            node as any;
 
 
            
 
        //(this.vnode as ElementNode).patchDom(container);
 
        // newResult.$node = this._oldResult.$node; // Set the existing DOM node to be patched
 
        // if (newResult.tag === null) { // Document fragment
 
        //     (this.document as HTMLElement).replaceChildren(...Array.from(patchNode(newResult, this.document).childNodes));
 
        // }
        // else {
 
        //     this.document.replaceChild(patchNode(newResult, this.document), this._oldResult.$node);
        // }
    }
}