refactor: adjust absent prop casting logic
This commit is contained in:
parent
0255be2f4b
commit
b76c453507
@ -226,7 +226,8 @@ export function updateProps(
|
|||||||
rawCurrentProps,
|
rawCurrentProps,
|
||||||
camelizedKey,
|
camelizedKey,
|
||||||
value,
|
value,
|
||||||
instance
|
instance,
|
||||||
|
false /* isAbsent */
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -271,10 +272,11 @@ export function updateProps(
|
|||||||
) {
|
) {
|
||||||
props[key] = resolvePropValue(
|
props[key] = resolvePropValue(
|
||||||
options,
|
options,
|
||||||
rawProps || EMPTY_OBJ,
|
rawCurrentProps,
|
||||||
key,
|
key,
|
||||||
undefined,
|
undefined,
|
||||||
instance
|
instance,
|
||||||
|
true /* isAbsent */
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -363,14 +365,17 @@ function setFullProps(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needCastKeys) {
|
if (needCastKeys) {
|
||||||
|
const rawCurrentProps = toRaw(props)
|
||||||
|
const castValues = rawCastValues || EMPTY_OBJ
|
||||||
for (let i = 0; i < needCastKeys.length; i++) {
|
for (let i = 0; i < needCastKeys.length; i++) {
|
||||||
const key = needCastKeys[i]
|
const key = needCastKeys[i]
|
||||||
props[key] = resolvePropValue(
|
props[key] = resolvePropValue(
|
||||||
options!,
|
options!,
|
||||||
rawCastValues || EMPTY_OBJ,
|
rawCurrentProps,
|
||||||
key,
|
key,
|
||||||
rawCastValues && rawCastValues[key],
|
castValues[key],
|
||||||
instance
|
instance,
|
||||||
|
!hasOwn(castValues, key)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,7 +388,8 @@ function resolvePropValue(
|
|||||||
props: Data,
|
props: Data,
|
||||||
key: string,
|
key: string,
|
||||||
value: unknown,
|
value: unknown,
|
||||||
instance: ComponentInternalInstance
|
instance: ComponentInternalInstance,
|
||||||
|
isAbsent: boolean
|
||||||
) {
|
) {
|
||||||
const opt = options[key]
|
const opt = options[key]
|
||||||
if (opt != null) {
|
if (opt != null) {
|
||||||
@ -412,13 +418,13 @@ function resolvePropValue(
|
|||||||
}
|
}
|
||||||
// boolean casting
|
// boolean casting
|
||||||
if (opt[BooleanFlags.shouldCast]) {
|
if (opt[BooleanFlags.shouldCast]) {
|
||||||
if (
|
if (isAbsent && !hasDefault) {
|
||||||
|
value = false
|
||||||
|
} else if (
|
||||||
opt[BooleanFlags.shouldCastTrue] &&
|
opt[BooleanFlags.shouldCastTrue] &&
|
||||||
(value === '' || value === hyphenate(key))
|
(value === '' || value === hyphenate(key))
|
||||||
) {
|
) {
|
||||||
value = true
|
value = true
|
||||||
} else if (!hasOwn(props, key) && !hasDefault) {
|
|
||||||
value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user