From 98fa3c0c7a987b7ba2f068b57d2064eef11ea9e0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 21 May 2025 18:16:43 -0400 Subject: [PATCH] simplify --- .../client/transform-template/index.js | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js b/packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js index a8d1c3250f..7b7c36b4b7 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/transform-template/index.js @@ -53,34 +53,25 @@ function build_locations(locations) { * @param {number} [flags] */ export function transform_template(state, context, namespace, template_name, flags) { - /** - * @param {Identifier} template_name - * @param {Expression[]} args - */ - const add_template = (template_name, args) => { - let call = b.call(get_template_function(namespace, state), ...args); - if (dev) { - call = b.call( - '$.add_locations', - call, - b.member(b.id(context.state.analysis.name), '$.FILENAME', true), - build_locations(state.locations) - ); - } - - context.state.hoisted.push(b.var(template_name, call)); - }; - - /** @type {Expression[]} */ - const args = [ + const expression = state.options.templatingMode === 'functional' ? template_to_functions(state.template.nodes) - : template_to_string(state.template.nodes) - ]; + : template_to_string(state.template.nodes); + + let call = b.call( + get_template_function(namespace, state), + expression, + flags ? b.literal(flags) : undefined + ); - if (flags) { - args.push(b.literal(flags)); + if (dev) { + call = b.call( + '$.add_locations', + call, + b.member(b.id(context.state.analysis.name), '$.FILENAME', true), + build_locations(state.locations) + ); } - add_template(template_name, args); + context.state.hoisted.push(b.var(template_name, call)); }