wip: style/class normalization

This commit is contained in:
Evan You
2019-06-01 17:43:41 +08:00
parent 05556eacb2
commit d6d4ba8679
3 changed files with 68 additions and 20 deletions

View File

@@ -36,12 +36,10 @@ type RequiredKeys<T> = {
type OptionalKeys<T> = Exclude<keyof T, RequiredKeys<T>>
type InferPropType<T> = T extends null
? any
: // null & true would fail to infer
T extends { type: null | true }
? any
: // somehow `ObjectContructor` when inferred from { (): T } becomes `any`
T extends ObjectConstructor | { type: ObjectConstructor }
? any // null & true would fail to infer
: T extends { type: null | true }
? any // somehow `ObjectContructor` when inferred from { (): T } becomes `any`
: T extends ObjectConstructor | { type: ObjectConstructor }
? { [key: string]: any }
: T extends Prop<infer V> ? V : T
@@ -64,8 +62,6 @@ type NormalizedProp =
type NormalizedPropsOptions = Record<string, NormalizedProp>
const isReservedKey = (key: string): boolean => key[0] === '_' || key[0] === '$'
// resolve raw VNode data.
// - filter out reserved keys (key, ref, slots)
// - extract class and style into $attrs (to be merged onto child
@@ -182,7 +178,7 @@ function normalizePropsOptions(
warn(`props must be strings when using array syntax.`, raw[i])
}
const normalizedKey = camelize(raw[i])
if (!isReservedKey(normalizedKey)) {
if (normalizedKey[0] !== '$') {
normalized[normalizedKey] = EMPTY_OBJ
} else if (__DEV__) {
warn(`Invalid prop name: "${normalizedKey}" is a reserved property.`)
@@ -194,7 +190,7 @@ function normalizePropsOptions(
}
for (const key in raw) {
const normalizedKey = camelize(key)
if (!isReservedKey(normalizedKey)) {
if (normalizedKey[0] !== '$') {
const opt = raw[key]
const prop: NormalizedProp = (normalized[normalizedKey] =
isArray(opt) || isFunction(opt) ? { type: opt } : opt)