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

@ -17,8 +17,14 @@ export function template_to_functions(items) {
/** @param {Node} item */ /** @param {Node} item */
function build(item) { function build(item) {
switch (item.type) { if (item.type === 'text') {
case 'element': { return b.literal(item.nodes.map((node) => node.data).join(''));
}
if (item.type === 'anchor') {
return item.data ? b.array([b.literal(`// ${item.data}`)]) : null;
}
const element = b.array([b.literal(item.name)]); const element = b.array([b.literal(item.name)]);
const attributes = b.object([]); const attributes = b.object([]);
@ -47,23 +53,10 @@ function build(item) {
if (item.name === 'pre' || item.name === 'textarea') { if (item.name === 'pre' || item.name === 'textarea') {
const first = children[0]; const first = children[0];
if (first?.type === 'Literal') { if (first?.type === 'Literal') {
first.value = /** @type {string} */ (first.value).replace( first.value = /** @type {string} */ (first.value).replace(regex_starts_with_newline, '');
regex_starts_with_newline,
''
);
} }
} }
} }
return element; return element;
}
case 'anchor': {
return item.data ? b.array([b.literal(`// ${item.data}`)]) : null;
}
case 'text': {
return b.literal(item.nodes.map((node) => node.data).join(''));
}
}
} }

Loading…
Cancel
Save