Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
output += `Node: ${node.nodeName}`;
if (node.nodeType === NodeType.Text) {
output += ` "${node.textContent}"`;
}
if (node.nodeType === NodeType.Element) {
let i = 0;
let attr;
const attributes = (node as HTMLElement).attributes;
const len = attributes.length;
for (; i < len; ++i) {
attr = attributes[i];
output += ` ${attr.name}=${attr.value}`;
}
}
output += '\n';
if (node.nodeType === NodeType.Element) {
let i = 0;
let childNodes = node.childNodes;
let len = childNodes.length;
for (; i < len; ++i) {
output += stringifyDOM(childNodes[i], depth + 1);
}
if (node.nodeName === 'TEMPLATE') {
i = 0;
childNodes = (node as HTMLTemplateElement).content.childNodes;
len = childNodes.length;
for (; i < len; ++i) {
output += stringifyDOM(childNodes[i], depth + 1);
}
}
}
return output;
export function stringifyDOM(node: Node, depth: number): string {
const indent = ' '.repeat(depth);
let output = indent;
output += `Node: ${node.nodeName}`;
if (node.nodeType === NodeType.Text) {
output += ` "${node.textContent}"`;
}
if (node.nodeType === NodeType.Element) {
let i = 0;
let attr;
const attributes = (node as HTMLElement).attributes;
const len = attributes.length;
for (; i < len; ++i) {
attr = attributes[i];
output += ` ${attr.name}=${attr.value}`;
}
}
output += '\n';
if (node.nodeType === NodeType.Element) {
let i = 0;
let childNodes = node.childNodes;
let len = childNodes.length;
for (; i < len; ++i) {
output += stringifyDOM(childNodes[i], depth + 1);
output += `Node: ${node.nodeName}`;
if (node.nodeType === NodeType.Text) {
output += ` "${node.textContent}"`;
}
if (node.nodeType === NodeType.Element) {
let i = 0;
let attr;
const attributes = (node as HTMLElement).attributes;
const len = attributes.length;
for (; i < len; ++i) {
attr = attributes[i];
output += ` ${attr.name}=${attr.value}`;
}
}
output += '\n';
if (node.nodeType === NodeType.Element) {
let i = 0;
let childNodes = node.childNodes;
let len = childNodes.length;
for (; i < len; ++i) {
output += stringifyDOM(childNodes[i], depth + 1);
}
if (node.nodeName === 'TEMPLATE') {
i = 0;
childNodes = (node as HTMLTemplateElement).content.childNodes;
len = childNodes.length;
for (; i < len; ++i) {
output += stringifyDOM(childNodes[i], depth + 1);
}
}
}
return output;
private bindChildNodes(node: HTMLTemplateElement | HTMLElement): void {
let childNode: ChildNode;
if (node.nodeName === 'TEMPLATE') {
childNode = (node as HTMLTemplateElement).content.firstChild!;
} else {
childNode = node.firstChild!;
}
let nextChild: ChildNode;
while (childNode != null) {
switch (childNode.nodeType) {
case NodeType.Element:
nextChild = childNode.nextSibling as ChildNode;
this.bindManifest(this.manifest!, childNode as HTMLElement);
childNode = nextChild;
break;
case NodeType.Text:
childNode = this.bindText(childNode as Text).nextSibling as ChildNode;
break;
case NodeType.CDATASection:
case NodeType.ProcessingInstruction:
case NodeType.Comment:
case NodeType.DocumentType:
childNode = childNode.nextSibling as ChildNode;
break;
case NodeType.Document:
case NodeType.DocumentFragment:
childNode = childNode.firstChild!;
export function stringifyDOM(node: Node, depth: number): string {
const indent = ' '.repeat(depth);
let output = indent;
output += `Node: ${node.nodeName}`;
if (node.nodeType === NodeType.Text) {
output += ` "${node.textContent}"`;
}
if (node.nodeType === NodeType.Element) {
let i = 0;
let attr;
const attributes = (node as HTMLElement).attributes;
const len = attributes.length;
for (; i < len; ++i) {
attr = attributes[i];
output += ` ${attr.name}=${attr.value}`;
}
}
output += '\n';
if (node.nodeType === NodeType.Element) {
let i = 0;
let childNodes = node.childNodes;
let len = childNodes.length;
for (; i < len; ++i) {
output += stringifyDOM(childNodes[i], depth + 1);