const classify = (str: string): string =>
str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')
+export function getComponentName(
+ Component: ConcreteComponent
+): string | undefined {
+ return isFunction(Component)
+ ? Component.displayName || Component.name
+ : Component.name
+}
+
/* istanbul ignore next */
export function formatComponentName(
instance: ComponentInternalInstance | null,
Component: ConcreteComponent,
isRoot = false
): string {
- let name = isFunction(Component)
- ? Component.displayName || Component.name
- : Component.name
+ let name = getComponentName(Component)
if (!name && Component.__file) {
const match = Component.__file.match(/([^/\\]+)\.\w+$/)
if (match) {
import {
ConcreteComponent,
getCurrentInstance,
- FunctionalComponent,
SetupContext,
ComponentInternalInstance,
LifecycleHooks,
- currentInstance
+ currentInstance,
+ getComponentName
} from '../component'
import { VNode, cloneVNode, isVNode, VNodeProps } from '../vnode'
import { warn } from '../warning'
function pruneCache(filter?: (name: string) => boolean) {
cache.forEach((vnode, key) => {
- const name = getName(vnode.type as ConcreteComponent)
+ const name = getComponentName(vnode.type as ConcreteComponent)
if (name && (!filter || !filter(name))) {
pruneCacheEntry(key)
}
let vnode = getInnerChild(rawVNode)
const comp = vnode.type as ConcreteComponent
- const name = getName(comp)
+ const name = getComponentName(comp)
const { include, exclude, max } = props
if (
}
}
-function getName(comp: ConcreteComponent): string | void {
- return (comp as FunctionalComponent).displayName || comp.name
-}
-
function matches(pattern: MatchPattern, name: string): boolean {
if (isArray(pattern)) {
return pattern.some((p: string | RegExp) => matches(p, name))
import {
currentInstance,
ConcreteComponent,
- FunctionalComponent,
- ComponentOptions
+ ComponentOptions,
+ getComponentName
} from '../component'
import { Directive } from '../directives'
import { camelize, capitalize, isString } from '@vue/shared'
return Component
}
- const selfName =
- (Component as FunctionalComponent).displayName || Component.name
+ const selfName = getComponentName(Component)
if (
selfName &&
(selfName === name ||