From 0f7f8d9c556ea3b906daf9d1c8e70ab6fed8269c Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sun, 16 Jul 2017 18:33:16 +0200 Subject: [PATCH 1/3] feat(warnings): Suggest casting boolean keys Closes #6126 --- src/shared/util.js | 2 +- test/unit/modules/vdom/create-element.spec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/shared/util.js b/src/shared/util.js index 4ad915a3462..47d6e66f54e 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -22,7 +22,7 @@ export function isFalse (v: any): boolean %checks { * Check if value is primitive */ export function isPrimitive (value: any): boolean %checks { - return typeof value === 'string' || typeof value === 'number' + return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' } /** diff --git a/test/unit/modules/vdom/create-element.spec.js b/test/unit/modules/vdom/create-element.spec.js index 82d6f6bdcb4..e2e8ce27a6d 100644 --- a/test/unit/modules/vdom/create-element.spec.js +++ b/test/unit/modules/vdom/create-element.spec.js @@ -162,6 +162,15 @@ describe('create-element', () => { expect('Avoid using non-primitive value as key').toHaveBeenWarned() }) + it('doesn\'t warn boolean key', () => { + new Vue({ + render (h) { + return h('div', { key: true }) + } + }).$mount() + expect('Avoid using non-primitive value as key').not.toHaveBeenWarned() + }) + it('nested child elements should be updated correctly', done => { const vm = new Vue({ data: { n: 1 }, From 4e2fb9395d8e62f4e6e70d4975f0a25f952e2b0d Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 19 Jul 2017 08:18:31 -0400 Subject: [PATCH 2/3] Update util.js --- src/shared/util.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/shared/util.js b/src/shared/util.js index 47d6e66f54e..8c6d588692e 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -22,7 +22,8 @@ export function isFalse (v: any): boolean %checks { * Check if value is primitive */ export function isPrimitive (value: any): boolean %checks { - return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' + const type = typeof value + return type === 'string' || type === 'number' || type === 'boolean' } /** From f6dea2be645f1317cbcedc235fd5ebc3d70bb8ac Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 19 Jul 2017 08:21:28 -0400 Subject: [PATCH 3/3] Update util.js --- src/shared/util.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/shared/util.js b/src/shared/util.js index 8c6d588692e..c890d2eddc7 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -22,8 +22,11 @@ export function isFalse (v: any): boolean %checks { * Check if value is primitive */ export function isPrimitive (value: any): boolean %checks { - const type = typeof value - return type === 'string' || type === 'number' || type === 'boolean' + return ( + typeof value === 'string' || + typeof value === 'number' || + typeof value === 'boolean' + ) } /**