|
|
@@ -16,8 +16,11 @@ const DIRECTIVES = 'directives'
|
|
|
/**
|
|
|
* @private
|
|
|
*/
|
|
|
-export function resolveComponent(name: string): ConcreteComponent | string {
|
|
|
- return resolveAsset(COMPONENTS, name) || name
|
|
|
+export function resolveComponent(
|
|
|
+ name: string,
|
|
|
+ maybeSelfReference?: boolean
|
|
|
+): ConcreteComponent | string {
|
|
|
+ return resolveAsset(COMPONENTS, name, true, maybeSelfReference) || name
|
|
|
}
|
|
|
|
|
|
export const NULL_DYNAMIC_COMPONENT = Symbol()
|
|
|
@@ -48,7 +51,8 @@ export function resolveDirective(name: string): Directive | undefined {
|
|
|
function resolveAsset(
|
|
|
type: typeof COMPONENTS,
|
|
|
name: string,
|
|
|
- warnMissing?: boolean
|
|
|
+ warnMissing?: boolean,
|
|
|
+ maybeSelfReference?: boolean
|
|
|
): ConcreteComponent | undefined
|
|
|
// overload 2: directives
|
|
|
function resolveAsset(
|
|
|
@@ -59,20 +63,15 @@ function resolveAsset(
|
|
|
function resolveAsset(
|
|
|
type: typeof COMPONENTS | typeof DIRECTIVES,
|
|
|
name: string,
|
|
|
- warnMissing = true
|
|
|
+ warnMissing = true,
|
|
|
+ maybeSelfReference = false
|
|
|
) {
|
|
|
const instance = currentRenderingInstance || currentInstance
|
|
|
if (instance) {
|
|
|
const Component = instance.type
|
|
|
|
|
|
- // self name has highest priority
|
|
|
+ // explicit self name has highest priority
|
|
|
if (type === COMPONENTS) {
|
|
|
- // special self referencing call generated by compiler
|
|
|
- // inferred from SFC filename
|
|
|
- if (name === `_self`) {
|
|
|
- return Component
|
|
|
- }
|
|
|
-
|
|
|
const selfName = getComponentName(Component)
|
|
|
if (
|
|
|
selfName &&
|
|
|
@@ -90,9 +89,16 @@ function resolveAsset(
|
|
|
resolve(instance[type] || (Component as ComponentOptions)[type], name) ||
|
|
|
// global registration
|
|
|
resolve(instance.appContext[type], name)
|
|
|
+
|
|
|
+ if (!res && maybeSelfReference) {
|
|
|
+ // fallback to implicit self-reference
|
|
|
+ return Component
|
|
|
+ }
|
|
|
+
|
|
|
if (__DEV__ && warnMissing && !res) {
|
|
|
warn(`Failed to resolve ${type.slice(0, -1)}: ${name}`)
|
|
|
}
|
|
|
+
|
|
|
return res
|
|
|
} else if (__DEV__) {
|
|
|
warn(
|