From f64a661fa5a983475177cc8a23426641dec065d0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 7 Feb 2019 11:11:14 -0500 Subject: [PATCH] better cyclical dependency detection - fixes #2055 --- src/compile/Component.ts | 3 ++- .../reactive-values-non-cyclical/_config.js | 17 +++++++++++++++++ .../reactive-values-non-cyclical/main.html | 13 +++++++++++++ .../reactive-declaration-cyclical/errors.json | 7 +++++++ .../reactive-declaration-cyclical/input.html | 7 +++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/reactive-values-non-cyclical/_config.js create mode 100644 test/runtime/samples/reactive-values-non-cyclical/main.html create mode 100644 test/validator/samples/reactive-declaration-cyclical/errors.json create mode 100644 test/validator/samples/reactive-declaration-cyclical/input.html diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 659cf972cc..fa980593a3 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -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); } diff --git a/test/runtime/samples/reactive-values-non-cyclical/_config.js b/test/runtime/samples/reactive-values-non-cyclical/_config.js new file mode 100644 index 0000000000..e134a669ee --- /dev/null +++ b/test/runtime/samples/reactive-values-non-cyclical/_config.js @@ -0,0 +1,17 @@ +export default { + props: { + x: 42 + }, + + html: ` +

42 42

+ `, + + test({ assert, component, target }) { + component.x = 43; + + assert.htmlEqual(target.innerHTML, ` +

43 43

+ `); + } +}; diff --git a/test/runtime/samples/reactive-values-non-cyclical/main.html b/test/runtime/samples/reactive-values-non-cyclical/main.html new file mode 100644 index 0000000000..061a38857a --- /dev/null +++ b/test/runtime/samples/reactive-values-non-cyclical/main.html @@ -0,0 +1,13 @@ + + +

{a} {b}

\ No newline at end of file diff --git a/test/validator/samples/reactive-declaration-cyclical/errors.json b/test/validator/samples/reactive-declaration-cyclical/errors.json new file mode 100644 index 0000000000..1e4169a0ee --- /dev/null +++ b/test/validator/samples/reactive-declaration-cyclical/errors.json @@ -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 +}] \ No newline at end of file diff --git a/test/validator/samples/reactive-declaration-cyclical/input.html b/test/validator/samples/reactive-declaration-cyclical/input.html new file mode 100644 index 0000000000..c8221b9aa8 --- /dev/null +++ b/test/validator/samples/reactive-declaration-cyclical/input.html @@ -0,0 +1,7 @@ + \ No newline at end of file