Skip to content

Commit b2448dc

Browse files
authored
fix: ensure bind:this works with component with no return value (#12308)
1 parent e42bb61 commit b2448dc

File tree

12 files changed

+3
-16
lines changed

12 files changed

+3
-16
lines changed

.changeset/warm-waves-reply.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
'svelte': patch
33
---
44

5-
fix: ensure component always returns an object
5+
fix: ensure `bind:this` works with component with no return value

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,6 @@ export function client_component(source, analysis, options) {
339339
? b.return(b.call('$.pop', b.object(component_returned_object)))
340340
: b.stmt(b.call('$.pop'))
341341
);
342-
} else {
343-
// Always return an object, so that `bind:this` on this component will not be falsy
344-
component_block.body.push(b.return(b.object(component_returned_object)));
345342
}
346343

347344
if (analysis.uses_rest_props) {

packages/svelte/src/internal/client/dom/elements/bindings/this.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ function is_bound_this(bound_value, element_or_component) {
1515
}
1616

1717
/**
18-
* @param {Element} element_or_component
18+
* @param {any} element_or_component
1919
* @param {(value: unknown, ...parts: unknown[]) => void} update
2020
* @param {(...parts: unknown[]) => unknown} get_value
2121
* @param {() => unknown[]} [get_parts] Set if the this binding is used inside an each block,
2222
* returns all the parts of the each block context that are used in the expression
2323
* @returns {void}
2424
*/
25-
export function bind_this(element_or_component, update, get_value, get_parts) {
25+
export function bind_this(element_or_component = {}, update, get_value, get_parts) {
2626
effect(() => {
2727
/** @type {unknown[]} */
2828
var old_parts;

packages/svelte/tests/snapshot/samples/bind-component-snippet/_expected/client/index.svelte.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ export default function Bind_component_snippet($$anchor) {
3030

3131
$.template_effect(() => $.set_text(text, ` value: ${$.get(value) ?? ""}`));
3232
$.append($$anchor, fragment_1);
33-
return {};
3433
}

packages/svelte/tests/snapshot/samples/bind-this/_expected/client/index.svelte.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ import * as $ from "svelte/internal/client";
33

44
export default function Bind_this($$anchor) {
55
$.bind_this(Foo($$anchor, { $$legacy: true }), ($$value) => foo = $$value, () => foo);
6-
return {};
76
}

packages/svelte/tests/snapshot/samples/dynamic-attributes-casing/_expected/client/main.svelte.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ export default function Main($$anchor) {
3030
});
3131

3232
$.append($$anchor, fragment);
33-
return {};
3433
}

packages/svelte/tests/snapshot/samples/each-string-template/_expected/client/index.svelte.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ export default function Each_string_template($$anchor) {
1313
});
1414

1515
$.append($$anchor, fragment);
16-
return {};
1716
}

packages/svelte/tests/snapshot/samples/function-prop-no-getter/_expected/client/index.svelte.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,4 @@ export default function Function_prop_no_getter($$anchor) {
2222
},
2323
$$slots: { default: true }
2424
});
25-
26-
return {};
2725
}

packages/svelte/tests/snapshot/samples/hello-world/_expected/client/index.svelte.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@ export default function Hello_world($$anchor) {
77
var h1 = root();
88

99
$.append($$anchor, h1);
10-
return {};
1110
}

packages/svelte/tests/snapshot/samples/hmr/_expected/client/index.svelte.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ function Hmr($$anchor) {
77
var h1 = root();
88

99
$.append($$anchor, h1);
10-
return {};
1110
}
1211

1312
if (import.meta.hot) {

0 commit comments

Comments
 (0)