From a84c78b9a14d3d9de56fd2c3d7bed585b5816c63 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 16 Sep 2025 08:13:37 -0400 Subject: [PATCH] chore: simplify build_template (#16780) --- .../server/visitors/shared/utils.js | 38 ++++++------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/utils.js b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/utils.js index db708b7a6b..166845b62f 100644 --- a/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/utils.js +++ b/packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/utils.js @@ -103,11 +103,9 @@ function is_statement(node) { /** * @param {Array} template - * @param {Identifier} out - * @param {AssignmentOperator | 'push'} operator * @returns {Statement[]} */ -export function build_template(template, out = b.id('$$payload'), operator = 'push') { +export function build_template(template) { /** @type {string[]} */ let strings = []; @@ -118,32 +116,18 @@ export function build_template(template, out = b.id('$$payload'), operator = 'pu const statements = []; const flush = () => { - if (operator === 'push') { - statements.push( - b.stmt( - b.call( - b.member(out, b.id('push')), - b.template( - strings.map((cooked, i) => b.quasi(cooked, i === strings.length - 1)), - expressions - ) - ) - ) - ); - } else { - statements.push( - b.stmt( - b.assignment( - operator, - out, - b.template( - strings.map((cooked, i) => b.quasi(cooked, i === strings.length - 1)), - expressions - ) + statements.push( + b.stmt( + b.call( + b.id('$$payload.push'), + b.template( + strings.map((cooked, i) => b.quasi(cooked, i === strings.length - 1)), + expressions ) ) - ); - } + ) + ); + strings = []; expressions = []; };