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
*/
function stringify(node) {
switch (node.type) {
case 'element': {
let str = `<${node.name}`;
for (const key in node.attributes) {
const value = node.attributes[key];
if (node.type === 'text') {
return node.nodes.map((node) => node.raw).join('');
}
str += ` ${key}`;
if (value !== undefined) str += `="${escape_html(value, true)}"`;
}
if (node.type === 'anchor') {
return node.data ? `<!--${node.data}-->` : '<!>';
}
str += `>`;
str += node.children.map(stringify).join('');
let str = `<${node.name}`;
if (!is_void(node.name)) {
str += `</${node.name}>`;
}
for (const key in node.attributes) {
const value = node.attributes[key];
return str;
}
str += ` ${key}`;
if (value !== undefined) str += `="${escape_html(value, true)}"`;
}
case 'text': {
return node.nodes.map((node) => node.raw).join('');
}
str += `>`;
str += node.children.map(stringify).join('');
case 'anchor': {
return node.data ? `<!--${node.data}-->` : '<!>';
}
if (!is_void(node.name)) {
str += `</${node.name}>`;
}
return str;
}

Loading…
Cancel
Save