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/rude-points-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: prevent erroneous `state_referenced_locally` warnings on prop fallbacks
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
console.log(doubled);

let {
prop
prop,
other_prop = prop
} = $props();
let prop_state = $state(prop);
let prop_derived = $derived(prop);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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