mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 09:21:21 +01:00
feat: better <svelte:element>
SSR output (#12339)
This commit is contained in:
parent
a59bc99782
commit
bbf489504d
5
.changeset/plenty-clouds-reply.md
Normal file
5
.changeset/plenty-clouds-reply.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: better `<svelte:element>` SSR output
|
@ -1338,12 +1338,18 @@ const template_visitors = {
|
|||||||
context.visit(node.fragment, state)
|
context.visit(node.fragment, state)
|
||||||
);
|
);
|
||||||
|
|
||||||
const body = b.stmt(
|
context.state.template.push(
|
||||||
b.call('$.element', b.id('$$payload'), tag, b.thunk(attributes), b.thunk(children))
|
b.stmt(
|
||||||
|
b.call(
|
||||||
|
'$.element',
|
||||||
|
b.id('$$payload'),
|
||||||
|
tag,
|
||||||
|
attributes.body.length > 0 && b.thunk(attributes),
|
||||||
|
children.body.length > 0 && b.thunk(children)
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
context.state.template.push(b.if(tag, body), block_anchor);
|
|
||||||
|
|
||||||
if (context.state.options.dev) {
|
if (context.state.options.dev) {
|
||||||
context.state.template.push(b.stmt(b.call('$.pop_element')));
|
context.state.template.push(b.stmt(b.call('$.pop_element')));
|
||||||
}
|
}
|
||||||
|
@ -72,18 +72,22 @@ export function assign_payload(p1, p2) {
|
|||||||
* @param {() => void} children_fn
|
* @param {() => void} children_fn
|
||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
export function element(payload, tag, attributes_fn, children_fn) {
|
export function element(payload, tag, attributes_fn = noop, children_fn = noop) {
|
||||||
payload.out += `<${tag} `;
|
if (tag) {
|
||||||
attributes_fn();
|
payload.out += `<${tag} `;
|
||||||
payload.out += `>`;
|
attributes_fn();
|
||||||
|
payload.out += `>`;
|
||||||
|
|
||||||
if (!VoidElements.has(tag)) {
|
if (!VoidElements.has(tag)) {
|
||||||
children_fn();
|
children_fn();
|
||||||
if (!RawTextElements.includes(tag)) {
|
if (!RawTextElements.includes(tag)) {
|
||||||
payload.out += BLOCK_ANCHOR;
|
payload.out += BLOCK_ANCHOR;
|
||||||
|
}
|
||||||
|
payload.out += `</${tag}>`;
|
||||||
}
|
}
|
||||||
payload.out += `</${tag}>`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
payload.out += '<!---->';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,5 @@ import * as $ from "svelte/internal/server";
|
|||||||
export default function Svelte_element($$payload, $$props) {
|
export default function Svelte_element($$payload, $$props) {
|
||||||
let { tag = 'hr' } = $$props;
|
let { tag = 'hr' } = $$props;
|
||||||
|
|
||||||
if (tag) $.element($$payload, tag, () => {}, () => {});
|
$.element($$payload, tag);
|
||||||
$$payload.out += `<!---->`;
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user