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 */
function build(item) {
switch (item.type) {
case 'element': {
if (item.type === 'text') {
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 attributes = b.object([]);
@ -47,23 +53,10 @@ function build(item) {
if (item.name === 'pre' || item.name === 'textarea') {
const first = children[0];
if (first?.type === 'Literal') {
first.value = /** @type {string} */ (first.value).replace(
regex_starts_with_newline,
''
);
first.value = /** @type {string} */ (first.value).replace(regex_starts_with_newline, '');
}
}
}
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