chore: improve code generation for `bind:this` in SSR mode (#10524)

* chore: improve code generation for `bind:this` in SSR mode

* test

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/10531/head
Rich Harris 2 years ago committed by GitHub
parent b5628af72e
commit 3da6cef29b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: improve code generation for `bind:this` in SSR mode

@ -1060,7 +1060,9 @@ const common_visitors = {
parent.type === 'SvelteComponent' ||
parent.type === 'SvelteSelf'
) {
context.state.analysis.uses_component_bindings = true;
if (node.name !== 'this') {
context.state.analysis.uses_component_bindings = true;
}
break;
} else if (is_element_node(parent)) {
break;

@ -853,7 +853,7 @@ function serialize_inline_component(node, component_name, context) {
const value = serialize_attribute_value(attribute.value, context, false, true);
push_prop(b.prop('init', b.key(attribute.name), value));
} else if (attribute.type === 'BindDirective') {
} else if (attribute.type === 'BindDirective' && attribute.name !== 'this') {
// TODO this needs to turn the whole thing into a while loop because the binding could be mutated eagerly in the child
push_prop(
b.get(attribute.name, [

@ -0,0 +1,3 @@
import { test } from '../../test';
export default test({});

@ -0,0 +1,17 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import "svelte/internal/disclose-version";
import * as $ from "svelte/internal";
export default function Bind_this($$anchor, $$props) {
$.push($$props, false);
$.init();
/* Init */
var fragment = $.comment($$anchor);
var node = $.child_frag(fragment);
$.bind_this(Foo(node, {}), ($$value) => foo = $$value, foo);
$.close_frag($$anchor, fragment);
$.pop();
}

@ -0,0 +1,14 @@
// index.svelte (Svelte VERSION)
// Note: compiler output will change before 5.0 is released!
import * as $ from "svelte/internal/server";
export default function Bind_this($$payload, $$props) {
$.push(false);
const anchor = $.create_anchor($$payload);
$$payload.out += `${anchor}`;
Foo($$payload, {});
$$payload.out += `${anchor}`;
$.pop();
}
Loading…
Cancel
Save