Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/warm-waves-reply.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'svelte': patch
---

fix: ensure component always returns an object
fix: ensure `bind:this` works with component with no return value
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ export default function Bind_component_snippet($$anchor) {

$.template_effect(() => $.set_text(text, ` value: ${$.get(value) ?? ""}`));
$.append($$anchor, fragment_1);
return {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ export default function Main($$anchor) {
});

$.append($$anchor, fragment);
return {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ export default function Each_string_template($$anchor) {
});

$.append($$anchor, fragment);
return {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@ export default function Function_prop_no_getter($$anchor) {
},
$$slots: { default: true }
});

return {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export default function Hello_world($$anchor) {
var h1 = root();

$.append($$anchor, h1);
return {};
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function Hmr($$anchor) {
var h1 = root();

$.append($$anchor, h1);
return {};
}

if (import.meta.hot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ export default function Svelte_element($$anchor, $$props) {

$.element(node, tag, false);
$.append($$anchor, fragment);
return {};
}
Loading