From ca63c11281c7169ffb17bbd93f24c03823623397 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 9 Dec 2017 22:04:53 -0500 Subject: [PATCH] emit dev mode error for bad arguments to set - fixes #990 --- src/shared/index.js | 10 +++++----- .../samples/dev-warning-bad-set-argument/_config.js | 7 +++++++ .../samples/dev-warning-bad-set-argument/main.html | 11 +++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 test/runtime/samples/dev-warning-bad-set-argument/_config.js create mode 100644 test/runtime/samples/dev-warning-bad-set-argument/main.html diff --git a/src/shared/index.js b/src/shared/index.js index b63a4ab001e3..79b6f2cba9d2 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -165,15 +165,15 @@ export function _set(newState) { } } -export function _setDev(newState) { +export function setDev(newState) { if (typeof newState !== 'object') { throw new Error( - this._debugName + ' .set was called without an object of data key-values to update.' + this._debugName + '.set was called without an object of data key-values to update.' ); } this._checkReadOnly(newState); - _set.call(this, newState); + set.call(this, newState); } export function callAll(fns) { @@ -220,10 +220,10 @@ export var protoDev = { fire: fire, observe: observeDev, on: onDev, - set: set, + set: setDev, teardown: destroyDev, _recompute: noop, - _set: _setDev, + _set: _set, _mount: _mount, _unmount: _unmount }; diff --git a/test/runtime/samples/dev-warning-bad-set-argument/_config.js b/test/runtime/samples/dev-warning-bad-set-argument/_config.js new file mode 100644 index 000000000000..f44e5c95fd22 --- /dev/null +++ b/test/runtime/samples/dev-warning-bad-set-argument/_config.js @@ -0,0 +1,7 @@ +export default { + dev: true, + + error(assert, error) { + assert.equal(error.message, `.set was called without an object of data key-values to update.`); + } +}; diff --git a/test/runtime/samples/dev-warning-bad-set-argument/main.html b/test/runtime/samples/dev-warning-bad-set-argument/main.html new file mode 100644 index 000000000000..cbaf739b10c8 --- /dev/null +++ b/test/runtime/samples/dev-warning-bad-set-argument/main.html @@ -0,0 +1,11 @@ + \ No newline at end of file