From: Evan You Date: Mon, 24 May 2021 23:09:18 +0000 (-0400) Subject: refactor: adjust absent prop casting logic X-Git-Tag: v3.1.0-beta.4~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b76c453507fd2bd5b5569997e469acdbda7206bd;p=thirdparty%2Fvuejs%2Fcore.git refactor: adjust absent prop casting logic --- diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index f94d1522cc..3c9afc7c5c 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -226,7 +226,8 @@ export function updateProps( rawCurrentProps, camelizedKey, value, - instance + instance, + false /* isAbsent */ ) } } else { @@ -271,10 +272,11 @@ export function updateProps( ) { props[key] = resolvePropValue( options, - rawProps || EMPTY_OBJ, + rawCurrentProps, key, undefined, - instance + instance, + true /* isAbsent */ ) } } else { @@ -363,14 +365,17 @@ function setFullProps( } if (needCastKeys) { + const rawCurrentProps = toRaw(props) + const castValues = rawCastValues || EMPTY_OBJ for (let i = 0; i < needCastKeys.length; i++) { const key = needCastKeys[i] props[key] = resolvePropValue( options!, - rawCastValues || EMPTY_OBJ, + rawCurrentProps, key, - rawCastValues && rawCastValues[key], - instance + castValues[key], + instance, + !hasOwn(castValues, key) ) } } @@ -383,7 +388,8 @@ function resolvePropValue( props: Data, key: string, value: unknown, - instance: ComponentInternalInstance + instance: ComponentInternalInstance, + isAbsent: boolean ) { const opt = options[key] if (opt != null) { @@ -412,13 +418,13 @@ function resolvePropValue( } // boolean casting if (opt[BooleanFlags.shouldCast]) { - if ( + if (isAbsent && !hasDefault) { + value = false + } else if ( opt[BooleanFlags.shouldCastTrue] && (value === '' || value === hyphenate(key)) ) { value = true - } else if (!hasOwn(props, key) && !hasDefault) { - value = false } } }