snippet-work-cont
Simon Holthausen 1 year ago
parent 9be0fdd753
commit be3b08cbe5

@ -69,11 +69,13 @@ export function set_text(dom, value) {
* @param {null | ((anchor: Comment) => void)} fallback_fn * @param {null | ((anchor: Comment) => void)} fallback_fn
*/ */
export function slot(anchor, $$props, slot_name, slot_props, fallback_fn) { export function slot(anchor, $$props, slot_name, slot_props, fallback_fn) {
var is_snippet = false;
var slot_fn = $$props.$$slots?.[slot_name]; var slot_fn = $$props.$$slots?.[slot_name];
if (slot_fn === true) { if (slot_fn === true) {
if (slot_name === 'default') { if (slot_name === 'default') {
slot_fn = $$props.children; slot_fn = $$props.children;
} else { } else {
is_snippet = true;
slot_fn = $$props[slot_name]; slot_fn = $$props[slot_name];
} }
} }
@ -83,7 +85,7 @@ export function slot(anchor, $$props, slot_name, slot_props, fallback_fn) {
fallback_fn(anchor); fallback_fn(anchor);
} }
} else { } else {
slot_fn(anchor, slot_props); slot_fn(anchor, is_snippet ? () => slot_props : slot_props);
} }
} }

@ -1,2 +1,2 @@
<p><slot /></p> <p><slot /></p>
<p><slot name="named" /></p> <p><slot name="named" foo="foo" /></p>

@ -1,5 +1,5 @@
import { test } from '../../test'; import { test } from '../../test';
export default test({ export default test({
html: `<p>Default</p> <p>Named</p>` html: `<p>Default</p> <p>Named foo</p>`
}); });

@ -4,7 +4,7 @@
<Child> <Child>
Default Default
{#snippet named()} {#snippet named({ foo })}
Named Named {foo}
{/snippet} {/snippet}
</Child> </Child>

Loading…
Cancel
Save