feat(props): enable case conversion in all builds, preserve casing for attrs

This commit is contained in:
Evan You 2019-10-24 10:59:57 -04:00
parent e2917fef96
commit 42bf9ca3e5

View File

@ -128,11 +128,13 @@ export function resolveProps(
for (const key in rawProps) { for (const key in rawProps) {
// key, ref are reserved // key, ref are reserved
if (isReservedProp(key)) continue if (isReservedProp(key)) continue
const camelKey = __RUNTIME_COMPILE__ ? camelize(key) : key // prop option names are camelized during normalization, so to support
// any non-declared data are put into a separate `attrs` object // kebab -> camel conversion here we need to camelize the key.
// for spreading const camelKey = camelize(key)
if (hasDeclaredProps && !hasOwn(options, camelKey)) { if (hasDeclaredProps && !hasOwn(options, camelKey)) {
;(attrs || (attrs = {}))[camelKey] = rawProps[key] // Any non-declared props are put into a separate `attrs` object
// for spreading. Make sure to preserve original key casing
;(attrs || (attrs = {}))[key] = rawProps[key]
} else { } else {
setProp(camelKey, rawProps[key]) setProp(camelKey, rawProps[key])
} }
@ -164,9 +166,11 @@ export function resolveProps(
} }
// runtime validation // runtime validation
if (__DEV__ && rawProps) { if (__DEV__ && rawProps) {
let rawValue = rawProps[key] let rawValue
if (__RUNTIME_COMPILE__ && !(key in rawProps)) { if (!(key in rawProps) && hyphenate(key) in rawProps) {
rawValue = rawProps[hyphenate(key)] rawValue = rawProps[hyphenate(key)]
} else {
rawValue = rawProps[key]
} }
validateProp(key, toRaw(rawValue), opt, isAbsent) validateProp(key, toRaw(rawValue), opt, isAbsent)
} }