wip: fix props/attrs bugs

This commit is contained in:
Evan You 2024-12-06 22:07:21 +08:00
parent 238d1817cc
commit 685f7820a1
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
1 changed files with 8 additions and 7 deletions

View File

@ -39,16 +39,16 @@ export function getPropsProxyHandlers(
} }
const propsOptions = normalizePropsOptions(comp)[0] const propsOptions = normalizePropsOptions(comp)[0]
const emitsOptions = normalizeEmitsOptions(comp) const emitsOptions = normalizeEmitsOptions(comp)
const isProp = propsOptions ? (key: string) => hasOwn(propsOptions, key) : NO const isProp = propsOptions
? (key: string) => hasOwn(propsOptions, camelize(key))
: NO
const isAttr = propsOptions const isAttr = propsOptions
? (key: string) => ? (key: string) =>
key !== '$' && !isProp(key) && !isEmitListener(emitsOptions, key) key !== '$' && !isProp(key) && !isEmitListener(emitsOptions, key)
: YES : YES
const getProp = (instance: VaporComponentInstance, key: string) => { const getProp = (instance: VaporComponentInstance, key: string) => {
if (key === '$' || !isProp(key)) { if (!isProp(key)) return
return
}
const rawProps = instance.rawProps const rawProps = instance.rawProps
const dynamicSources = rawProps.$ const dynamicSources = rawProps.$
if (dynamicSources) { if (dynamicSources) {
@ -88,6 +88,7 @@ export function getPropsProxyHandlers(
undefined, undefined,
instance, instance,
resolveDefault, resolveDefault,
true,
) )
} }
@ -128,7 +129,7 @@ export function getPropsProxyHandlers(
} }
} }
if (hasOwn(target, key)) { if (hasOwn(target, key)) {
return target[key] return target[key]()
} }
} }
@ -220,9 +221,9 @@ export function hasFallthroughAttrs(
return true return true
} else { } else {
// check if rawProps contains any keys not declared // check if rawProps contains any keys not declared
const propsOptions = normalizePropsOptions(comp)[0] const propsOptions = normalizePropsOptions(comp)[0]!
for (const key in rawProps) { for (const key in rawProps) {
if (!hasOwn(propsOptions!, key)) { if (!hasOwn(propsOptions, camelize(key))) {
return true return true
} }
} }