pull/15538/head
Rich Harris 4 months ago
parent 84f15d005c
commit 1be912071d

@ -14,33 +14,29 @@ export function template_to_string(items) {
* @param {Node} node * @param {Node} node
*/ */
function stringify(node) { function stringify(node) {
switch (node.type) { if (node.type === 'text') {
case 'element': { return node.nodes.map((node) => node.raw).join('');
let str = `<${node.name}`; }
for (const key in node.attributes) {
const value = node.attributes[key];
str += ` ${key}`; if (node.type === 'anchor') {
if (value !== undefined) str += `="${escape_html(value, true)}"`; return node.data ? `<!--${node.data}-->` : '<!>';
} }
str += `>`; let str = `<${node.name}`;
str += node.children.map(stringify).join('');
if (!is_void(node.name)) { for (const key in node.attributes) {
str += `</${node.name}>`; const value = node.attributes[key];
}
return str; str += ` ${key}`;
} if (value !== undefined) str += `="${escape_html(value, true)}"`;
}
case 'text': { str += `>`;
return node.nodes.map((node) => node.raw).join(''); str += node.children.map(stringify).join('');
}
case 'anchor': { if (!is_void(node.name)) {
return node.data ? `<!--${node.data}-->` : '<!>'; str += `</${node.name}>`;
}
} }
return str;
} }

Loading…
Cancel
Save