refactor: adjust warning for fn props and component with many props

This commit is contained in:
Evan You 2019-11-23 22:17:46 -05:00
parent 33d79d6451
commit bdafa1dfc4

View File

@ -131,8 +131,12 @@ function formatComponentName(vnode: ComponentVNode, file?: string): string {
function formatProps(props: Data): any[] { function formatProps(props: Data): any[] {
const res: any[] = [] const res: any[] = []
for (const key in props) { const keys = Object.keys(props)
keys.slice(0, 3).forEach(key => {
res.push(...formatProp(key, props[key])) res.push(...formatProp(key, props[key]))
})
if (keys.length > 3) {
res.push(` ...`)
} }
return res return res
} }
@ -143,11 +147,17 @@ function formatProp(key: string, value: unknown, raw?: boolean): any {
if (isString(value)) { if (isString(value)) {
value = JSON.stringify(value) value = JSON.stringify(value)
return raw ? value : [`${key}=${value}`] return raw ? value : [`${key}=${value}`]
} else if (typeof value === 'number' || value == null) { } else if (
typeof value === 'number' ||
typeof value === 'boolean' ||
value == null
) {
return raw ? value : [`${key}=${value}`] return raw ? value : [`${key}=${value}`]
} else if (isRef(value)) { } else if (isRef(value)) {
value = formatProp(key, toRaw(value.value), true) value = formatProp(key, toRaw(value.value), true)
return raw ? value : [`${key}=Ref<`, value, `>`] return raw ? value : [`${key}=Ref<`, value, `>`]
} else if (isFunction(value)) {
return [`${key}=fn${value.name ? `<${value.name}>` : ``}`]
} else { } else {
value = toRaw(value) value = toRaw(value)
return raw ? value : [`${key}=`, value] return raw ? value : [`${key}=`, value]