fix(runtime-core): fix kebab-case prop required warning

fix #3495
ref #3363
This commit is contained in:
Evan You 2021-03-27 11:16:39 -04:00
parent 37c17091fd
commit 2121c32e22
2 changed files with 25 additions and 1 deletions

View File

@ -319,6 +319,25 @@ describe('component props', () => {
expect(`Missing required prop: "num"`).toHaveBeenWarned()
})
// #3495
test('should not warn required props using kebab-case', async () => {
const Comp = {
props: {
fooBar: { type: String, required: true }
},
setup() {
return () => null
}
}
render(
h(Comp, {
'foo-bar': 'hello'
}),
nodeOps.createElement('div')
)
expect(`Missing required prop: "fooBar"`).not.toHaveBeenWarned()
})
test('merging props from mixins and extends', () => {
let setupProps: any
let renderProxy: any

View File

@ -480,7 +480,12 @@ function validateProps(
for (const key in options) {
let opt = options[key]
if (opt == null) continue
validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key))
validateProp(
key,
resolvedValues[key],
opt,
!hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key))
)
}
}