fix(runtime-core): fix component name inference in warnings

Should not pollute component definition name property
fix #1418
This commit is contained in:
Evan You
2020-06-26 09:28:15 -04:00
parent 1c4e1b6792
commit e765d81404
4 changed files with 24 additions and 20 deletions

View File

@@ -682,6 +682,7 @@ const classify = (str: string): string =>
str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')
export function formatComponentName(
instance: ComponentInternalInstance | null,
Component: Component,
isRoot = false
): string {
@@ -694,5 +695,17 @@ export function formatComponentName(
name = match[1]
}
}
if (!name && instance && instance.parent) {
// try to infer the name based on local resolution
const registry = instance.parent.components
for (const key in registry) {
if (registry[key] === Component) {
name = key
break
}
}
}
return name ? classify(name) : isRoot ? `App` : `Anonymous`
}