fix: correctly apply scope on component children (#9824)

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/9825/head
Rich Harris 2 years ago committed by GitHub
parent 5797bb34ce
commit 481df0e64a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: correctly apply scope on component children

@ -370,7 +370,6 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
} }
const scope = analyze_let_directives(node, state.scope); const scope = analyze_let_directives(node, state.scope);
scopes.set(node, scope);
for (const child of node.fragment.nodes) { for (const child of node.fragment.nodes) {
if ( if (
@ -382,9 +381,15 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
// <div slot="..."> inherits the scope above the component, because slots are hella weird // <div slot="..."> inherits the scope above the component, because slots are hella weird
scopes.set(child, state.scope); scopes.set(child, state.scope);
visit(child); visit(child);
} else if (child.type === 'SnippetBlock') {
visit(child, { scope });
} else { } else {
if (child.type === 'ExpressionTag') {
// expression tag is a special case — we don't visit it directly, but via process_children,
// so we need to set the scope on the expression rather than the tag itself
scopes.set(child.expression, scope);
} else {
scopes.set(child, scope);
}
visit(child, { scope }); visit(child, { scope });
} }
} }

@ -0,0 +1,5 @@
<script>
let { message } = $props();
</script>
<slot {message} />

@ -0,0 +1,5 @@
import { test } from '../../test';
export default test({
html: `<p>message: hello</p>`
});

@ -0,0 +1,9 @@
<script>
import Child from './Child.svelte';
let message = 'hello';
</script>
<Child message={message} let:message>
<p>message: {message}</p>
</Child>
Loading…
Cancel
Save