From e29ec988bb77693bc3a93143bbf4ec5c3f8d0aeb Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 22 Nov 2023 16:18:09 -0500 Subject: [PATCH] shuffle code around a bit --- .../3-transform/client/visitors/template.js | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js index 207bc6faf0..9dba85b41a 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js @@ -1028,40 +1028,40 @@ function create_block(parent, name, nodes, context) { } else if (is_single_child_not_needing_template) { context.visit(trimmed[0], state); body.push(...state.init); - } else { + } else if (trimmed.length > 0) { id = b.id(context.state.scope.generate('fragment')); + body.push( + b.var( + id, + b.call( + '$.open_frag', + b.id('$$anchor'), + b.literal(!state.metadata.template_needs_import_node), + template_name + ) + ) + ); + process_children(trimmed, b.call('$.child_frag', id), { ...context, state }); - if (state.template.length > 0) { - const callee = namespace === 'svg' ? '$.svg_template' : '$.template'; + const callee = namespace === 'svg' ? '$.svg_template' : '$.template'; - state.hoisted.push( - b.var( - template_name, - b.call(callee, b.template([b.quasi(state.template.join(''), true)], []), b.true) - ) - ); + state.hoisted.push( + b.var( + template_name, + b.call(callee, b.template([b.quasi(state.template.join(''), true)], []), b.true) + ) + ); - body.push( - b.var( - id.name, - b.call( - '$.open_frag', - b.id('$$anchor'), - b.literal(!state.metadata.template_needs_import_node), - template_name - ) - ), - ...state.init - ); - close = b.stmt(b.call('$.close_frag', b.id('$$anchor'), id)); - } else { - body.push(...state.init); - } + body.push(...state.init); + + close = b.stmt(b.call('$.close_frag', b.id('$$anchor'), id)); + } else { + body.push(...state.init); } if (state.update.length > 0 || state.update_effects.length > 0) {