fix: visit expression node in directives ()

* 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 <rich.harris@vercel.com>
pull/10528/head
Ahmad 1 year ago committed by GitHub
parent 4d8d2928d8
commit 06e1d86091
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: visit expression node in directives

@ -331,10 +331,14 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
}
/**
* @type {import('zimmerframe').Visitor<import('#compiler').Directive, State, import('#compiler').SvelteNode>}
* @type {import('zimmerframe').Visitor<import('#compiler').AnimateDirective | import('#compiler').TransitionDirective | import('#compiler').UseDirective, State, import('#compiler').SvelteNode>}
*/
const SvelteDirective = (node, context) => {
context.state.scope.reference(b.id(node.name), context.path);
const SvelteDirective = (node, { state, path, visit }) => {
state.scope.reference(b.id(node.name), path);
if (node.expression) {
visit(node.expression);
}
};
walk(ast, state, {

@ -1,9 +1,11 @@
<script>
import { writable } from 'svelte/store';
let action = writable((node) => {
node.textContent = 'mounted';
let action = writable((node, text) => {
node.textContent = text;
});
let text = writable('mounted')
</script>
<div use:$action>hello</div>
<div use:$action={$text}>hello</div>

Loading…
Cancel
Save