Merge pull request #2063 from sveltejs/gh-2055

better cyclical dependency detection
pull/2066/head
Rich Harris 6 years ago committed by GitHub
commit 3dab978bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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