Skip to content

Commit 10e8628

Browse files
committed
refactor: move formatComponentName to component.ts
1 parent 2f8838d commit 10e8628

File tree

2 files changed

+17
-61
lines changed

2 files changed

+17
-61
lines changed

packages/runtime-vapor/src/component.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ function getAttrsProxy(instance: ComponentInternalInstance): Data {
413413
))
414414
)
415415
}
416-
417416
const classifyRE = /(?:^|[-_])(\w)/g
418417
const classify = (str: string): string =>
419418
str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')
@@ -427,7 +426,6 @@ export function getComponentName(
427426
: Component.name || (includeInferred && Component.__name)
428427
}
429428

430-
/* istanbul ignore next */
431429
export function formatComponentName(
432430
instance: ComponentInternalInstance | null,
433431
Component: Component,
@@ -441,19 +439,22 @@ export function formatComponentName(
441439
}
442440
}
443441

444-
if (!name && instance && instance.parent) {
445-
// try to infer the name based on reverse resolution
446-
const inferFromRegistry = (registry: Record<string, any> | undefined) => {
447-
for (const key in registry) {
448-
if (registry[key] === Component) {
449-
return key
450-
}
451-
}
452-
}
453-
name =
454-
inferFromRegistry(instance.comps) ||
455-
inferFromRegistry(instance.appContext.components)
456-
}
442+
// TODO registry
443+
// if (!name && instance && instance.parent) {
444+
// // try to infer the name based on reverse resolution
445+
// const inferFromRegistry = (registry: Record<string, any> | undefined) => {
446+
// for (const key in registry) {
447+
// if (registry[key] === Component) {
448+
// return key
449+
// }
450+
// }
451+
// }
452+
// name =
453+
// inferFromRegistry(
454+
// instance.components ||
455+
// (instance.parent.type as ComponentOptions).components,
456+
// ) || inferFromRegistry(instance.appContext.components)
457+
// }
457458

458459
return name ? classify(name) : isRoot ? `App` : `Anonymous`
459460
}

packages/runtime-vapor/src/warning.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type Component,
33
type ComponentInternalInstance,
44
currentInstance,
5+
formatComponentName,
56
} from './component'
67
import { isFunction, isString } from '@vue/shared'
78
import { isRef, pauseTracking, resetTracking, toRaw } from '@vue/reactivity'
@@ -155,49 +156,3 @@ function formatProp(key: string, value: unknown, raw?: boolean): any {
155156
return raw ? value : [`${key}=`, value]
156157
}
157158
}
158-
159-
export function getComponentName(
160-
Component: Component,
161-
includeInferred = true,
162-
): string | false | undefined {
163-
return isFunction(Component)
164-
? Component.displayName || Component.name
165-
: Component.name || (includeInferred && Component.__name)
166-
}
167-
168-
export function formatComponentName(
169-
instance: ComponentInternalInstance | null,
170-
Component: Component,
171-
isRoot = false,
172-
): string {
173-
let name = getComponentName(Component)
174-
if (!name && Component.__file) {
175-
const match = Component.__file.match(/([^/\\]+)\.\w+$/)
176-
if (match) {
177-
name = match[1]
178-
}
179-
}
180-
181-
// TODO registry
182-
// if (!name && instance && instance.parent) {
183-
// // try to infer the name based on reverse resolution
184-
// const inferFromRegistry = (registry: Record<string, any> | undefined) => {
185-
// for (const key in registry) {
186-
// if (registry[key] === Component) {
187-
// return key
188-
// }
189-
// }
190-
// }
191-
// name =
192-
// inferFromRegistry(
193-
// instance.components ||
194-
// (instance.parent.type as ComponentOptions).components,
195-
// ) || inferFromRegistry(instance.appContext.components)
196-
// }
197-
198-
return name ? classify(name) : isRoot ? `App` : `Anonymous`
199-
}
200-
201-
const classifyRE = /(?:^|[-_])(\w)/g
202-
const classify = (str: string): string =>
203-
str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')

0 commit comments

Comments
 (0)