mirror of
https://github.com/sveltejs/svelte.git
synced 2024-11-29 08:32:05 +01:00
better cyclical dependency detection - fixes #2055
This commit is contained in:
parent
be3808dd08
commit
f64a661fa5
@ -1002,7 +1002,8 @@ export default class Component {
|
||||
const object = getObject(node);
|
||||
const { name } = object;
|
||||
|
||||
if (name[0] === '$' || component.var_lookup.has(name)) {
|
||||
const owner = scope.findOwner(name);
|
||||
if ((!owner || owner === component.instance_scope) && (name[0] === '$' || component.var_lookup.has(name))) {
|
||||
dependencies.add(name);
|
||||
}
|
||||
|
||||
|
17
test/runtime/samples/reactive-values-non-cyclical/_config.js
Normal file
17
test/runtime/samples/reactive-values-non-cyclical/_config.js
Normal file
@ -0,0 +1,17 @@
|
||||
export default {
|
||||
props: {
|
||||
x: 42
|
||||
},
|
||||
|
||||
html: `
|
||||
<p>42 42</p>
|
||||
`,
|
||||
|
||||
test({ assert, component, target }) {
|
||||
component.x = 43;
|
||||
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<p>43 43</p>
|
||||
`);
|
||||
}
|
||||
};
|
13
test/runtime/samples/reactive-values-non-cyclical/main.html
Normal file
13
test/runtime/samples/reactive-values-non-cyclical/main.html
Normal file
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
export let x;
|
||||
|
||||
let a;
|
||||
let b;
|
||||
|
||||
$: a = b;
|
||||
$: b = (function(a) {
|
||||
return a;
|
||||
}(x));
|
||||
</script>
|
||||
|
||||
<p>{a} {b}</p>
|
@ -0,0 +1,7 @@
|
||||
[{
|
||||
"message": "Cyclical dependency detected",
|
||||
"code": "cyclical-reactive-declaration",
|
||||
"start": { "line": 5, "column": 1, "character": 35 },
|
||||
"end": { "line": 5, "column": 14, "character": 48 },
|
||||
"pos": 35
|
||||
}]
|
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
let a = 1;
|
||||
let b = 2;
|
||||
|
||||
$: a = b + 1;
|
||||
$: b = a + 1;
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user