Skip to content

Commit c8ebc16

Browse files
committed
fix: ensure visit is called with correct state
Some of our `visit` calls have the wrong current state associated with it. To fix it, we need to pass the real current one. fixes #11722
1 parent 6e8131d commit c8ebc16

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

.changeset/flat-olives-live.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: set correct scope for `@const` tags within slots

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ function create_block(parent, name, nodes, context) {
10601060
/** @type {import('../types').ComponentClientTransformState} */
10611061
const state = {
10621062
...context.state,
1063+
scope: context.state.scopes.get(parent) ?? context.state.scope,
10631064
before_init: [],
10641065
init: [],
10651066
update: [],
@@ -1616,7 +1617,7 @@ function serialize_attribute_value(attribute_value, context) {
16161617

16171618
/**
16181619
* @param {Array<import('#compiler').Text | import('#compiler').ExpressionTag>} values
1619-
* @param {(node: import('#compiler').SvelteNode) => any} visit
1620+
* @param {(node: import('#compiler').SvelteNode, state: any) => any} visit
16201621
* @param {import("../types.js").ComponentClientTransformState} state
16211622
* @returns {[boolean, import('estree').TemplateLiteral]}
16221623
*/
@@ -1661,13 +1662,13 @@ function serialize_template_literal(values, visit, state) {
16611662
id,
16621663
create_derived(
16631664
state,
1664-
b.thunk(/** @type {import('estree').Expression} */ (visit(node.expression)))
1665+
b.thunk(/** @type {import('estree').Expression} */ (visit(node.expression, state)))
16651666
)
16661667
)
16671668
);
16681669
expressions.push(b.call('$.get', id));
16691670
} else {
1670-
expressions.push(b.call('$.stringify', visit(node.expression)));
1671+
expressions.push(b.call('$.stringify', visit(node.expression, state)));
16711672
}
16721673
quasis.push(b.quasi('', i + 1 === values.length));
16731674
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<slot name="inner" text="hello" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<slot name="footer" />
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `
5+
<div slot="footer">hello hello</div>
6+
`
7+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<script>
2+
import Nested from "./Nested.svelte"
3+
import Nested2 from "./Nested2.svelte"
4+
</script>
5+
6+
<Nested>
7+
<Nested2 slot="inner" let:text>
8+
<div slot="footer">
9+
{@const text2 = text}
10+
{text} {text2}
11+
</div>
12+
</Nested2>
13+
</Nested>

0 commit comments

Comments
 (0)