better cyclical dependency detection - fixes #2055

pull/2063/head
Rich Harris 6 years ago
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);
}

@ -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>
`);
}
};

@ -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…
Cancel
Save