0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-29 08:32:05 +01:00

Merge pull request #2063 from sveltejs/gh-2055

better cyclical dependency detection
This commit is contained in:
Rich Harris 2019-02-07 11:21:45 -05:00 committed by GitHub
commit 3dab978bc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 1 deletions

View File

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

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

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

View File

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

View File

@ -0,0 +1,7 @@
<script>
let a = 1;
let b = 2;
$: a = b + 1;
$: b = a + 1;
</script>