From faf18220e069f5a8765ce51f325620bd9da43b44 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 21 May 2025 21:16:52 -0400 Subject: [PATCH] optimise for the common case --- .../client/transform-template/to-functions.js | 14 +- .../src/internal/client/dom/template.js | 31 ++-- .../svelte/src/internal/client/dom/types.d.ts | 4 + .../client-functional/index.svelte.js | 2 +- .../client-functional/main.svelte.js | 12 +- .../client-functional/index.svelte.js | 2 +- .../client-functional/index.svelte.js | 2 +- .../client-functional/index.svelte.js | 2 +- .../client-functional/index.svelte.js | 8 +- .../client-functional/index.svelte.js | 2 +- .../client-functional/index.svelte.js | 139 ++++++++---------- .../client-functional/index.svelte.js | 6 +- .../client-functional/index.svelte.js | 2 +- 13 files changed, 107 insertions(+), 119 deletions(-) create mode 100644 packages/svelte/src/internal/client/dom/types.d.ts 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 c9128591cd..176a4ddf2f 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 @@ -19,14 +19,14 @@ export function template_to_functions(items) { function build(item) { switch (item.type) { case 'element': { - const element = b.object([b.prop('init', b.id('e'), b.literal(item.name))]); + const element = b.array([b.literal(item.name)]); - const attributes = b.prop('init', b.id('p'), b.object([])); + const attributes = b.object([]); for (const key in item.attributes) { const value = item.attributes[key]; - attributes.value.properties.push( + attributes.properties.push( b.prop( 'init', b.key(fix_attribute_casing(key)), @@ -35,13 +35,13 @@ function build(item) { ); } - if (attributes.value.properties.length > 0) { - element.properties.push(attributes); + if (attributes.properties.length > 0 || item.children.length > 0) { + element.elements.push(attributes.properties.length > 0 ? attributes : b.null); } if (item.children.length > 0) { const children = item.children.map(build); - element.properties.push(b.prop('init', b.id('c'), b.array(children))); + element.elements.push(...children); // special case — strip leading newline from `
` and `