function cloneNode(node, recursive = false) {
    let result;
    if (isText(node)) {
        result = new Text(node.data);
    }
    else if (isComment(node)) {
        result = new Comment(node.data);
    }
    else if (isTag(node)) {
        const children = recursive ? cloneChildren(node.children) : [];
        const clone = new Element(node.name, { ...node.attribs }, children);
        children.forEach((child) => (child.parent = clone));
        if (node.namespace != null) {
            clone.namespace = node.namespace;
        }
        if (node["x-attribsNamespace"]) {
            clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
        }
        if (node["x-attribsPrefix"]) {
            clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
        }
        result = clone;
    }
    else if (isCDATA(node)) {
        const children = recursive ? cloneChildren(node.children) : [];
        const clone = new CDATA(children);
        children.forEach((child) => (child.parent = clone));
        result = clone;
    }
    else if (isDocument(node)) {
        const children = recursive ? cloneChildren(node.children) : [];
        const clone = new Document(children);
        children.forEach((child) => (child.parent = clone));
        if (node["x-mode"]) {
            clone["x-mode"] = node["x-mode"];
        }
        result = clone;
    }
    else if (isDirective(node)) {
        const instruction = new ProcessingInstruction(node.name, node.data);
        if (node["x-name"] != null) {
            instruction["x-name"] = node["x-name"];
            instruction["x-publicId"] = node["x-publicId"];
            instruction["x-systemId"] = node["x-systemId"];
        }
        result = instruction;
    }
    else {
        throw new Error(`Not implemented yet: ${node.type}`);
    }
    result.startIndex = node.startIndex;
    result.endIndex = node.endIndex;
    if (node.sourceCodeLocation != null) {
        result.sourceCodeLocation = node.sourceCodeLocation;
    }
    return result;
}
/**
 * Clone a node, and optionally its children.
 *
 * @param recursive Clone child nodes as well.
 * @returns A clone of the node.
 */
Clone a node, and optionally its children.
@param recursive Clone child nodes as well.
@returns A clone of the node.
Clone a node and optionally its children . @param recursive Clone child nodes as well . @returns A clone of the node .
function cloneNode(node, recursive = false) {
    let result;
    if (isText(node)) {
        result = new Text(node.data);
    }
    else if (isComment(node)) {
        result = new Comment(node.data);
    }
    else if (isTag(node)) {
        const children = recursive ? cloneChildren(node.children) : [];
        const clone = new Element(node.name, { ...node.attribs }, children);
        children.forEach((child) => (child.parent = clone));
        if (node.namespace != null) {
            clone.namespace = node.namespace;
        }
        if (node["x-attribsNamespace"]) {
            clone["x-attribsNamespace"] = { ...node["x-attribsNamespace"] };
        }
        if (node["x-attribsPrefix"]) {
            clone["x-attribsPrefix"] = { ...node["x-attribsPrefix"] };
        }
        result = clone;
    }
    else if (isCDATA(node)) {
        const children = recursive ? cloneChildren(node.children) : [];
        const clone = new CDATA(children);
        children.forEach((child) => (child.parent = clone));
        result = clone;
    }
    else if (isDocument(node)) {
        const children = recursive ? cloneChildren(node.children) : [];
        const clone = new Document(children);
        children.forEach((child) => (child.parent = clone));
        if (node["x-mode"]) {
            clone["x-mode"] = node["x-mode"];
        }
        result = clone;
    }
    else if (isDirective(node)) {
        const instruction = new ProcessingInstruction(node.name, node.data);
        if (node["x-name"] != null) {
            instruction["x-name"] = node["x-name"];
            instruction["x-publicId"] = node["x-publicId"];
            instruction["x-systemId"] = node["x-systemId"];
        }
        result = instruction;
    }
    else {
        throw new Error(`Not implemented yet: ${node.type}`);
    }
    result.startIndex = node.startIndex;
    result.endIndex = node.endIndex;
    if (node.sourceCodeLocation != null) {
        result.sourceCodeLocation = node.sourceCodeLocation;
    }
    return result;
}
function cloneNode ( node , recursive = false ) { let result ; if ( isText ( node ) ) { result = new Text ( node . data ) ; } else if ( isComment ( node ) ) { result = new Comment ( node . data ) ; } else if ( isTag ( node ) ) { const children = recursive ? cloneChildren ( node . children ) : [ ] ; const clone = new Element ( node . name , { ... node . attribs } , children ) ; children . forEach ( ( child ) => ( child . parent = clone ) ) ; if ( node . namespace != null ) { clone . namespace = node . namespace ; } if ( node [ "x-attribsNamespace" ] ) { clone [ "x-attribsNamespace" ] = { ... node [ "x-attribsNamespace" ] } ; } if ( node [ "x-attribsPrefix" ] ) { clone [ "x-attribsPrefix" ] = { ... node [ "x-attribsPrefix" ] } ; } result = clone ; } else if ( isCDATA ( node ) ) { const children = recursive ? cloneChildren ( node . children ) : [ ] ; const clone = new CDATA ( children ) ; children . forEach ( ( child ) => ( child . parent = clone ) ) ; result = clone ; } else if ( isDocument ( node ) ) { const children = recursive ? cloneChildren ( node . children ) : [ ] ; const clone = new Document ( children ) ; children . forEach ( ( child ) => ( child . parent = clone ) ) ; if ( node [ "x-mode" ] ) { clone [ "x-mode" ] = node [ "x-mode" ] ; } result = clone ; } else if ( isDirective ( node ) ) { const instruction = new ProcessingInstruction ( node . name , node . data ) ; if ( node [ "x-name" ] != null ) { instruction [ "x-name" ] = node [ "x-name" ] ; instruction [ "x-publicId" ] = node [ "x-publicId" ] ; instruction [ "x-systemId" ] = node [ "x-systemId" ] ; } result = instruction ; } else { throw new Error ( ` ${ node . type } ` ) ; } result . startIndex = node . startIndex ; result . endIndex = node . endIndex ; if ( node . sourceCodeLocation != null ) { result . sourceCodeLocation = node . sourceCodeLocation ; } return result ; }
Clone a node, and optionally its children.
Clone a node and optionally its children .