( instance: ComponentInternalInstance | null, Component: ConcreteComponent, isRoot = false, )
| 1224 | } |
| 1225 | |
| 1226 | export function formatComponentName( |
| 1227 | instance: ComponentInternalInstance | null, |
| 1228 | Component: ConcreteComponent, |
| 1229 | isRoot = false, |
| 1230 | ): string { |
| 1231 | let name = getComponentName(Component) |
| 1232 | if (!name && Component.__file) { |
| 1233 | const match = Component.__file.match(/([^/\\]+)\.\w+$/) |
| 1234 | if (match) { |
| 1235 | name = match[1] |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | if (!name && instance) { |
| 1240 | // try to infer the name based on reverse resolution |
| 1241 | const inferFromRegistry = ( |
| 1242 | registry: Record<string, any> | undefined | null, |
| 1243 | ) => { |
| 1244 | for (const key in registry) { |
| 1245 | if (registry[key] === Component) { |
| 1246 | return key |
| 1247 | } |
| 1248 | } |
| 1249 | } |
| 1250 | name = |
| 1251 | inferFromRegistry(instance.components) || |
| 1252 | (instance.parent && |
| 1253 | inferFromRegistry( |
| 1254 | (instance.parent.type as ComponentOptions).components, |
| 1255 | )) || |
| 1256 | inferFromRegistry(instance.appContext.components) |
| 1257 | } |
| 1258 | |
| 1259 | return name ? classify(name) : isRoot ? `App` : `Anonymous` |
| 1260 | } |
| 1261 | |
| 1262 | export function isClassComponent(value: unknown): value is ClassComponent { |
| 1263 | return isFunction(value) && '__vccOpts' in value |
no test coverage detected