fix: ensure `bind:this` works with component with no return value (#12308)

pull/12307/head
Rich Harris 6 months ago committed by GitHub
parent e42bb61296
commit b2448dcc5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2,4 +2,4 @@
'svelte': patch
---
fix: ensure component always returns an object
fix: ensure `bind:this` works with component with no return value

@ -339,9 +339,6 @@ export function client_component(source, analysis, options) {
? b.return(b.call('$.pop', b.object(component_returned_object)))
: b.stmt(b.call('$.pop'))
);
} else {
// Always return an object, so that `bind:this` on this component will not be falsy
component_block.body.push(b.return(b.object(component_returned_object)));
}
if (analysis.uses_rest_props) {

@ -15,14 +15,14 @@ function is_bound_this(bound_value, element_or_component) {
}
/**
* @param {Element} element_or_component
* @param {any} element_or_component
* @param {(value: unknown, ...parts: unknown[]) => void} update
* @param {(...parts: unknown[]) => unknown} get_value
* @param {() => unknown[]} [get_parts] Set if the this binding is used inside an each block,
* returns all the parts of the each block context that are used in the expression
* @returns {void}
*/
export function bind_this(element_or_component, update, get_value, get_parts) {
export function bind_this(element_or_component = {}, update, get_value, get_parts) {
effect(() => {
/** @type {unknown[]} */
var old_parts;

@ -30,5 +30,4 @@ export default function Bind_component_snippet($$anchor) {
$.template_effect(() => $.set_text(text, ` value: ${$.get(value) ?? ""}`));
$.append($$anchor, fragment_1);
return {};
}

@ -3,5 +3,4 @@ import * as $ from "svelte/internal/client";
export default function Bind_this($$anchor) {
$.bind_this(Foo($$anchor, { $$legacy: true }), ($$value) => foo = $$value, () => foo);
return {};
}

@ -30,5 +30,4 @@ export default function Main($$anchor) {
});
$.append($$anchor, fragment);
return {};
}

@ -13,5 +13,4 @@ export default function Each_string_template($$anchor) {
});
$.append($$anchor, fragment);
return {};
}

@ -22,6 +22,4 @@ export default function Function_prop_no_getter($$anchor) {
},
$$slots: { default: true }
});
return {};
}

@ -7,5 +7,4 @@ export default function Hello_world($$anchor) {
var h1 = root();
$.append($$anchor, h1);
return {};
}

@ -7,7 +7,6 @@ function Hmr($$anchor) {
var h1 = root();
$.append($$anchor, h1);
return {};
}
if (import.meta.hot) {

@ -28,7 +28,6 @@ export default function State_proxy_literal($$anchor) {
$.bind_value(input, () => $.get(str), ($$value) => $.set(str, $$value));
$.bind_value(input_1, () => $.get(tpl), ($$value) => $.set(tpl, $$value));
$.append($$anchor, fragment);
return {};
}
$.delegate(["click"]);

@ -8,5 +8,4 @@ export default function Svelte_element($$anchor, $$props) {
$.element(node, tag, false);
$.append($$anchor, fragment);
return {};
}
Loading…
Cancel
Save