fix, different approach without needing symbol

pull/10800/head
Simon Holthausen 2 years ago
parent daf8a70d73
commit 1bdf919904

@ -840,6 +840,9 @@ function serialize_inline_component(node, component_name, context) {
push_prop(
b.init('children', context.state.options.dev ? b.call('$.wrap_snippet', slot_fn) : slot_fn)
);
// We additionally add the default slot as a boolean, so that the slot render function on the other
// side knows it should get the content to render from $$props.children
serialized_slots.push(b.init(slot_name, b.true));
} else {
serialized_slots.push(b.init(slot_name, slot_fn));
}

@ -1084,7 +1084,16 @@ function serialize_inline_component(node, component_name, context) {
);
if (slot_name === 'default' && !has_children_prop) {
push_prop(b.prop('init', b.id('children'), b.call('$.add_snippet_symbol', slot_fn)));
push_prop(
b.prop(
'init',
b.id('children'),
context.state.options.dev ? b.call('$.add_snippet_symbol', slot_fn) : slot_fn
)
);
// We additionally add the default slot as a boolean, so that the slot render function on the other
// side knows it should get the content to render from $$props.children
serialized_slots.push(b.init('default', b.true));
} else {
const slot = b.prop('init', b.literal(slot_name), slot_fn);
serialized_slots.push(slot);
@ -1619,7 +1628,9 @@ const template_visitors = {
// TODO hoist where possible
context.state.init.push(fn);
if (context.state.options.dev) {
context.state.init.push(b.stmt(b.call('$.add_snippet_symbol', node.expression)));
}
},
Component(node, context) {
const state = context.state;

@ -1,6 +1,5 @@
import { createClassComponent } from '../../../../legacy/legacy-client.js';
import { destroy_effect, render_effect } from '../../reactivity/effects.js';
import { add_snippet_symbol } from '../blocks/snippet.js';
import { append } from '../template.js';
import { define_property, object_keys } from '../../utils.js';
@ -111,7 +110,8 @@ if (typeof HTMLElement === 'function') {
for (const name of this.$$s) {
if (name in existing_slots) {
if (name === 'default' && !this.$$d.children) {
this.$$d.children = add_snippet_symbol(create_slot(name));
this.$$d.children = create_slot(name);
$$slots.default = true;
} else {
$$slots[name] = create_slot(name);
}

@ -1,4 +1,3 @@
import { is_snippet } from './dom/blocks/snippet.js';
import { untrack } from './runtime.js';
import { get_descriptor, is_array } from './utils.js';
import * as e from './errors.js';

@ -10,10 +10,6 @@ import {
} from '../../constants.js';
import { escape_html } from '../../escaping.js';
import { DEV } from 'esm-env';
export * from '../client/validate.js';
export { add_snippet_symbol } from '../client/dom/blocks/snippet.js';
export { default_slot } from '../client/dom/legacy/misc.js';
import { current_component, pop, push } from './context.js';
import { BLOCK_CLOSE, BLOCK_OPEN } from './hydration.js';
import { validate_store } from '../shared/validate.js';
@ -280,8 +276,9 @@ export function spread_attributes(attrs, lowercase_attributes, is_html, class_ha
for (let i = 0; i < attrs.length; i++) {
const obj = attrs[i];
for (key in obj) {
// omit functions
if (typeof obj[key] !== 'function') {
// omit functions and internal svelte properties
const prefix = key[0] + key[1]; // this is faster than key.slice(0, 2)
if (typeof obj[key] !== 'function' && prefix !== '$$') {
merged_attrs[key] = obj[key];
}
}
@ -626,6 +623,7 @@ export function once(get_value) {
export { push, pop } from './context.js';
export {
add_snippet_symbol,
validate_component,
validate_dynamic_element_tag,
validate_snippet,
@ -633,3 +631,5 @@ export {
} from '../shared/validate.js';
export { escape_html as escape };
export { default_slot } from '../client/dom/legacy/misc.js';

@ -16,12 +16,13 @@ export default function Function_prop_no_getter($$anchor) {
onmousedown: () => $.set(count, $.get(count) + 1),
onmouseup,
onmouseenter: () => $.set(count, $.proxy(plusOne($.get(count)))),
children: $.add_snippet_symbol(($$anchor, $$slotProps) => {
children: ($$anchor, $$slotProps) => {
var text = $.text($$anchor);
$.template_effect(() => $.set_text(text, `clicks: ${$.stringify($.get(count))}`));
$.append($$anchor, text);
})
},
$$slots: { default: true }
});
$.append($$anchor, fragment);

@ -17,9 +17,10 @@ export default function Function_prop_no_getter($$payload, $$props) {
onmousedown: () => count += 1,
onmouseup,
onmouseenter: () => count = plusOne(count),
children: $.add_snippet_symbol(($$payload, $$slotProps) => {
children: ($$payload, $$slotProps) => {
$$payload.out += `clicks: ${$.escape(count)}`;
})
},
$$slots: { default: true }
});
$$payload.out += `<!--]-->`;

Loading…
Cancel
Save