fix: exclude local declarations from non-reactive property warnings (#12909)

* fix: exclude local declarations from non-reactive property warnings

* copypasta fail
pull/12907/head
Rich Harris 3 months ago committed by GitHub
parent 0da4116b9d
commit 78b55c4130
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: exclude local declarations from non-reactive property warnings

@ -39,7 +39,8 @@ export function MemberExpression(node, context) {
binding.declaration_kind === 'import' ||
(binding.initial &&
binding.initial.type !== 'ArrayExpression' &&
binding.initial.type !== 'ObjectExpression')
binding.initial.type !== 'ObjectExpression' &&
binding.scope.function_depth <= 1)
) {
if (parent.type !== 'MemberExpression' && parent.type !== 'CallExpression') {
w.reactive_declaration_non_reactive_property(node);

@ -0,0 +1,8 @@
<script>
import { obj } from './data.js';
$: prop = obj.prop;
obj.foo = 'a different prop';
</script>
<p>{prop}</p>

@ -0,0 +1,14 @@
[
{
"code": "reactive_declaration_non_reactive_property",
"message": "Properties of objects and arrays are not reactive unless in runes mode. Changes to this property will not cause the reactive statement to update",
"start": {
"line": 4,
"column": 11
},
"end": {
"line": 4,
"column": 19
}
}
]

@ -0,0 +1,9 @@
<script>
let prop;
$: {
const obj = get_obj();
prop = obj.prop;
}
</script>
<p>{prop}</p>
Loading…
Cancel
Save