fix: add props to state_referenced_locally (#17266)

* add props to state_referenced_locally

* changeset
hydratable-thenable
adiGuba 1 week ago committed by GitHub
parent a72167bb38
commit 570f64963b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
add props to state_referenced_locally

@ -114,7 +114,8 @@ export function Identifier(node, context) {
binding.initial.arguments[0].type !== 'SpreadElement' &&
!should_proxy(binding.initial.arguments[0], context.state.scope)))) ||
binding.kind === 'raw_state' ||
binding.kind === 'derived') &&
binding.kind === 'derived' ||
binding.kind === 'prop') &&
// We're only concerned with reads here
(parent.type !== 'AssignmentExpression' || parent.left !== node) &&
parent.type !== 'UpdateExpression'

@ -8,11 +8,21 @@
console.log(count);
console.log(doubled);
let {
prop
} = $props();
let prop_state = $state(prop);
let prop_derived = $derived(prop);
console.log(prop);
console.log(prop_derived);
// writes are okay
count++;
count = 1;
obj.a++;
obj.a = 1;
prop_state = 1;
prop_derived = 1;
// `count` here is correctly identified as a non-reference
let typed: { count: number } | null = null;

@ -34,5 +34,41 @@
"column": 20,
"line": 9
}
},
{
"code": "state_referenced_locally",
"end": {
"column": 29,
"line": 14
},
"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
}
},
{
"code": "state_referenced_locally",
"end": {
"column": 17,
"line": 16
},
"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
}
},
{
"code": "state_referenced_locally",
"end": {
"column": 25,
"line": 17
},
"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
}
}
]

Loading…
Cancel
Save