fix: prevent erroneous `state_referenced_locally` warnings on prop fallbacks (#17329)

* failing test

* fix: prevent erroneous `state_referenced_locally` warnings on prop fallbacks
pull/17331/head
Rich Harris 2 days ago committed by GitHub
parent ebf7d94a71
commit 7ec9e4b3b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: prevent erroneous `state_referenced_locally` warnings on prop fallbacks

@ -146,5 +146,15 @@ export function VariableDeclarator(node, context) {
}
}
context.next();
if (node.init && get_rune(node.init, context.state.scope) === '$props') {
// prevent erroneous `state_referenced_locally` warnings on prop fallbacks
context.visit(node.id, {
...context.state,
function_depth: context.state.function_depth + 1
});
context.visit(node.init);
} else {
context.next();
}
}

@ -9,7 +9,8 @@
console.log(doubled);
let {
prop
prop,
other_prop = prop
} = $props();
let prop_state = $state(prop);
let prop_derived = $derived(prop);

@ -39,36 +39,36 @@
"code": "state_referenced_locally",
"end": {
"column": 29,
"line": 14
"line": 15
},
"message": "This reference only captures the initial value of `prop`. Did you mean to reference it inside a closure instead?",
"start": {
"column": 25,
"line": 14
"line": 15
}
},
{
"code": "state_referenced_locally",
"end": {
"column": 17,
"line": 16
"line": 17
},
"message": "This reference only captures the initial value of `prop`. Did you mean to reference it inside a closure instead?",
"start": {
"column": 13,
"line": 16
"line": 17
}
},
{
"code": "state_referenced_locally",
"end": {
"column": 25,
"line": 17
"line": 18
},
"message": "This reference only captures the initial value of `prop_derived`. Did you mean to reference it inside a closure instead?",
"start": {
"column": 13,
"line": 17
"line": 18
}
}
]

Loading…
Cancel
Save