Skip to content

Warn when not passing props in kebab-case #5161

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

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/core/vdom/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,17 @@ function extractProps (data: VNodeData, Ctor: Class<Component>): ?Object {
if (attrs || props || domProps) {
for (const key in propOptions) {
const altKey = hyphenate(key)
const keyInLowerCase = key.toLowerCase()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this inside the NODE_ENV conditional block as well? It's ok to use two nested ifs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, updated!

if (
process.env.NODE_ENV !== 'production' &&
key !== keyInLowerCase &&
attrs && attrs.hasOwnProperty(keyInLowerCase)
) {
warn(
`HTML attributes are case-insensitive. camelCased prop names need ` +
`to use their kebab-case equivalents. ${key} should be ${altKey}.`
)
}
checkProp(res, props, key, altKey, true) ||
checkProp(res, attrs, key, altKey) ||
checkProp(res, domProps, key, altKey)
Expand Down
19 changes: 19 additions & 0 deletions test/unit/features/component/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,25 @@ describe('Component', () => {
expect(vm.$el.outerHTML).toBe('<ul><li>1</li><li>2</li></ul>')
})

it('should warn when not passing props in kebab-case', () => {
new Vue({
data: {
list: [{ a: 1 }, { a: 2 }]
},
template: '<test :somecollection="list"></test>',
components: {
test: {
template: '<ul><li v-for="item in someCollection">{{item.a}}</li></ul>',
props: ['someCollection']
}
}
}).$mount()
expect(
'HTML attributes are case-insensitive. camelCased prop names need ' +
'to use their kebab-case equivalents. someCollection should be some-collection.'
).toHaveBeenWarned()
})

it('not found component should not throw', () => {
expect(function () {
new Vue({
Expand Down