MCPcopy
hub / github.com/vuejs/core / formatComponentName

Function formatComponentName

packages/runtime-core/src/component.ts:1226–1260  ·  view source on GitHub ↗
(
  instance: ComponentInternalInstance | null,
  Component: ConcreteComponent,
  isRoot = false,
)

Source from the content-addressed store, hash-verified

1224}
1225
1226export 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
1262export function isClassComponent(value: unknown): value is ClassComponent {
1263 return isFunction(value) && '__vccOpts' in value

Callers 7

emitFunction · 0.90
warnFunction · 0.90
formatTraceEntryFunction · 0.90
endMeasureFunction · 0.90
warnDeprecationFunction · 0.90
component.spec.tsFile · 0.90
setupStatefulComponentFunction · 0.85

Calls 3

getComponentNameFunction · 0.85
inferFromRegistryFunction · 0.85
classifyFunction · 0.85

Tested by

no test coverage detected