From b8e0cccea881583dfe282a5b765ae987ab50f35b Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sat, 19 Jan 2019 10:16:59 -0500 Subject: [PATCH] prevent writing to reactive values - fixes #1920 --- src/compile/Component.ts | 5 ----- .../expected.js | 4 ++-- .../reactive-values-readonly/_config.js | 21 +++++++++++++++++++ .../reactive-values-readonly/main.html | 8 +++++++ 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 test/runtime/samples/reactive-values-readonly/_config.js create mode 100644 test/runtime/samples/reactive-values-readonly/main.html diff --git a/src/compile/Component.ts b/src/compile/Component.ts index b07af70a64..a916078898 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -881,15 +881,10 @@ export default class Component { scope = map.get(node); } - if (parent && parent.type === 'AssignmentExpression' && node === parent.left) { - return this.skip(); - } - if (node.type === 'AssignmentExpression') { assignees.add(getObject(node.left).name); } else if (node.type === 'UpdateExpression') { assignees.add(getObject(node.argument).name); - this.skip(); } else if (isReference(node, parent)) { const object = getObject(node); const { name } = object; diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index 3b4c623407..4f64e95350 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -56,8 +56,8 @@ function instance($$self, $$props, $$invalidate) { if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo); }; - $$self.$$.update = ($$dirty = { foo: 1 }) => { - if ($$dirty.foo) { + $$self.$$.update = ($$dirty = { bar: 1, foo: 1 }) => { + if ($$dirty.bar || $$dirty.foo) { bar = foo * 2; $$invalidate('bar', bar); } }; diff --git a/test/runtime/samples/reactive-values-readonly/_config.js b/test/runtime/samples/reactive-values-readonly/_config.js new file mode 100644 index 0000000000..bf5c9dbb67 --- /dev/null +++ b/test/runtime/samples/reactive-values-readonly/_config.js @@ -0,0 +1,21 @@ +export default { + html: ` +

doubled: 2

+ `, + + test({ assert, component, target }) { + component.a = 2; + + assert.equal(component.doubled, 4); + assert.htmlEqual(target.innerHTML, ` +

doubled: 4

+ `); + + component.doubled = 6; + + assert.equal(component.doubled, 4); + assert.htmlEqual(target.innerHTML, ` +

doubled: 4

+ `); + } +}; diff --git a/test/runtime/samples/reactive-values-readonly/main.html b/test/runtime/samples/reactive-values-readonly/main.html new file mode 100644 index 0000000000..bb49c3ad94 --- /dev/null +++ b/test/runtime/samples/reactive-values-readonly/main.html @@ -0,0 +1,8 @@ + + +

doubled: {doubled}

\ No newline at end of file