Skip to content

Commit

Permalink
fix(core): Make set/delete warning condition for undefined, null and
Browse files Browse the repository at this point in the history
primitive values more precise.  Corrects vuejs#7452
  • Loading branch information
pkaminski committed Mar 13, 2018
1 parent 731b498 commit 876d7f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/core/observer/index.js
Expand Up @@ -10,6 +10,8 @@ import {
hasProto,
isObject,
isPlainObject,
isPrimitive,
isUndef,
isValidArrayIndex,
isServerRendering
} from '../util/index'
Expand Down Expand Up @@ -195,10 +197,9 @@ export function defineReactive (
*/
export function set (target: Array<any> | Object, key: any, val: any): any {
if (process.env.NODE_ENV !== 'production' &&
!Array.isArray(target) &&
!isObject(target)
(isUndef(target) || isPrimitive(target))
) {
warn(`Cannot set reactive property on non-object/array value: ${target}`)
warn(`Cannot set reactive property on undefined, null, or primitive value: ${(target: any)}`)
}
if (Array.isArray(target) && isValidArrayIndex(key)) {
target.length = Math.max(target.length, key)
Expand Down Expand Up @@ -231,10 +232,9 @@ export function set (target: Array<any> | Object, key: any, val: any): any {
*/
export function del (target: Array<any> | Object, key: any) {
if (process.env.NODE_ENV !== 'production' &&
!Array.isArray(target) &&
!isObject(target)
(isUndef(target) || isPrimitive(target))
) {
warn(`Cannot delete reactive property on non-object/array value: ${target}`)
warn(`Cannot delete reactive property on undefined, null, or primitive value: ${(target: any)}`)
}
if (Array.isArray(target) && isValidArrayIndex(key)) {
target.splice(key, 1)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/modules/observer/observer.spec.js
Expand Up @@ -360,12 +360,12 @@ describe('Observer', () => {
try {
setProp(null, 'foo', 1)
} catch (e) {}
expect(`Cannot set reactive property on non-object/array value`).toHaveBeenWarned()
expect(`Cannot set reactive property on undefined, null, or primitive value`).toHaveBeenWarned()

try {
delProp(null, 'foo')
} catch (e) {}
expect(`Cannot delete reactive property on non-object/array value`).toHaveBeenWarned()
expect(`Cannot delete reactive property on undefined, null, or primitive value`).toHaveBeenWarned()
})

it('should lazy invoke existing getters', () => {
Expand Down

0 comments on commit 876d7f9

Please sign in to comment.