Skip to content

Commit 06e1d86

Browse files
fix: visit expression node in directives (#10527)
* fix: visit child nodes in directives * test * cleanup * small change * lint * err * types * define the set locally, limit the blast radius --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 4d8d292 commit 06e1d86

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

.changeset/weak-terms-destroy.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: visit expression node in directives

packages/svelte/src/compiler/phases/scope.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,14 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
331331
}
332332

333333
/**
334-
* @type {import('zimmerframe').Visitor<import('#compiler').Directive, State, import('#compiler').SvelteNode>}
334+
* @type {import('zimmerframe').Visitor<import('#compiler').AnimateDirective | import('#compiler').TransitionDirective | import('#compiler').UseDirective, State, import('#compiler').SvelteNode>}
335335
*/
336-
const SvelteDirective = (node, context) => {
337-
context.state.scope.reference(b.id(node.name), context.path);
336+
const SvelteDirective = (node, { state, path, visit }) => {
337+
state.scope.reference(b.id(node.name), path);
338+
339+
if (node.expression) {
340+
visit(node.expression);
341+
}
338342
};
339343

340344
walk(ast, state, {
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<script>
22
import { writable } from 'svelte/store';
33
4-
let action = writable((node) => {
5-
node.textContent = 'mounted';
4+
let action = writable((node, text) => {
5+
node.textContent = text;
66
});
7+
8+
let text = writable('mounted')
79
</script>
810

9-
<div use:$action>hello</div>
11+
<div use:$action={$text}>hello</div>

0 commit comments

Comments
 (0)