Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curly-phones-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

add props to state_referenced_locally
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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