Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Make set/delete warning condition for undefined, null and primitive values more precise. Corrects #7452 #7818

Merged
merged 1 commit into from Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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