Skip to content

Commit 78b55c4

Browse files
authored
fix: exclude local declarations from non-reactive property warnings (#12909)
* fix: exclude local declarations from non-reactive property warnings * copypasta fail
1 parent 0da4116 commit 78b55c4

File tree

8 files changed

+45
-1
lines changed

8 files changed

+45
-1
lines changed

.changeset/perfect-pugs-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: exclude local declarations from non-reactive property warnings

packages/svelte/src/compiler/phases/2-analyze/visitors/MemberExpression.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export function MemberExpression(node, context) {
3939
binding.declaration_kind === 'import' ||
4040
(binding.initial &&
4141
binding.initial.type !== 'ArrayExpression' &&
42-
binding.initial.type !== 'ObjectExpression')
42+
binding.initial.type !== 'ObjectExpression' &&
43+
binding.scope.function_depth <= 1)
4344
) {
4445
if (parent.type !== 'MemberExpression' && parent.type !== 'CallExpression') {
4546
w.reactive_declaration_non_reactive_property(node);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { test } from '../../test';
2+
3+
export default test({});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import { obj } from './data.js';
3+
4+
$: prop = obj.prop;
5+
obj.foo = 'a different prop';
6+
</script>
7+
8+
<p>{prop}</p>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "reactive_declaration_non_reactive_property",
4+
"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",
5+
"start": {
6+
"line": 4,
7+
"column": 11
8+
},
9+
"end": {
10+
"line": 4,
11+
"column": 19
12+
}
13+
}
14+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { test } from '../../test';
2+
3+
export default test({});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<script>
2+
let prop;
3+
$: {
4+
const obj = get_obj();
5+
prop = obj.prop;
6+
}
7+
</script>
8+
9+
<p>{prop}</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)