Skip to content

Commit

Permalink
chore: better SSR output for <svelte:element> (#14493)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris authored Dec 2, 2024
1 parent 1f25bd4 commit 83cec2f
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import { build_template } from './shared/utils.js';
*/
export function SvelteElement(node, context) {
let tag = /** @type {Expression} */ (context.visit(node.tag));
if (tag.type !== 'Identifier') {
const tag_id = context.state.scope.generate('$$tag');
context.state.init.push(b.const(tag_id, tag));
tag = b.id(tag_id);
}

if (dev) {
// Ensure getters/function calls aren't called multiple times.
// If we ever start referencing `tag` more than once in prod, move this out of the if block.
if (tag.type !== 'Identifier') {
const tag_id = context.state.scope.generate('$$tag');
context.state.init.push(b.const(tag_id, tag));
tag = b.id(tag_id);
}

if (node.fragment.nodes.length > 0) {
context.state.init.push(b.stmt(b.call('$.validate_void_dynamic_element', b.thunk(tag))));
}
Expand Down

0 comments on commit 83cec2f

Please sign in to comment.