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

feat(warnings): Suggest casting boolean keys #6127

Merged
merged 3 commits into from
Jul 19, 2017
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
6 changes: 5 additions & 1 deletion src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ 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'
)
}

/**
Expand Down
9 changes: 9 additions & 0 deletions test/unit/modules/vdom/create-element.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down