From 84f15d005c7d85ba1ebda377d2186205775bd79a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 21 May 2025 21:28:21 -0400 Subject: [PATCH] tweak --- .../client/transform-template/to-functions.js | 71 +++++++++---------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/transform-template/to-functions.js b/packages/svelte/src/compiler/phases/3-transform/client/transform-template/to-functions.js index 176a4ddf2f..b9d1f5d916 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/transform-template/to-functions.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/transform-template/to-functions.js @@ -17,53 +17,46 @@ export function template_to_functions(items) { /** @param {Node} item */ function build(item) { - switch (item.type) { - case 'element': { - const element = b.array([b.literal(item.name)]); - - const attributes = b.object([]); + if (item.type === 'text') { + return b.literal(item.nodes.map((node) => node.data).join('')); + } - for (const key in item.attributes) { - const value = item.attributes[key]; + if (item.type === 'anchor') { + return item.data ? b.array([b.literal(`// ${item.data}`)]) : null; + } - attributes.properties.push( - b.prop( - 'init', - b.key(fix_attribute_casing(key)), - value === undefined ? b.void0 : b.literal(value) - ) - ); - } + const element = b.array([b.literal(item.name)]); - if (attributes.properties.length > 0 || item.children.length > 0) { - element.elements.push(attributes.properties.length > 0 ? attributes : b.null); - } + const attributes = b.object([]); - if (item.children.length > 0) { - const children = item.children.map(build); - element.elements.push(...children); + for (const key in item.attributes) { + const value = item.attributes[key]; - // special case — strip leading newline from `
` and `