@@ -16,8 +16,11 @@ const DIRECTIVES = 'directives'
16
16
/**
17
17
* @private
18
18
*/
19
- export function resolveComponent ( name : string ) : ConcreteComponent | string {
20
- return resolveAsset ( COMPONENTS , name ) || name
19
+ export function resolveComponent (
20
+ name : string ,
21
+ maybeSelfReference ?: boolean
22
+ ) : ConcreteComponent | string {
23
+ return resolveAsset ( COMPONENTS , name , true , maybeSelfReference ) || name
21
24
}
22
25
23
26
export const NULL_DYNAMIC_COMPONENT = Symbol ( )
@@ -48,7 +51,8 @@ export function resolveDirective(name: string): Directive | undefined {
48
51
function resolveAsset (
49
52
type : typeof COMPONENTS ,
50
53
name : string ,
51
- warnMissing ?: boolean
54
+ warnMissing ?: boolean ,
55
+ maybeSelfReference ?: boolean
52
56
) : ConcreteComponent | undefined
53
57
// overload 2: directives
54
58
function resolveAsset (
@@ -59,20 +63,15 @@ function resolveAsset(
59
63
function resolveAsset (
60
64
type : typeof COMPONENTS | typeof DIRECTIVES ,
61
65
name : string ,
62
- warnMissing = true
66
+ warnMissing = true ,
67
+ maybeSelfReference = false
63
68
) {
64
69
const instance = currentRenderingInstance || currentInstance
65
70
if ( instance ) {
66
71
const Component = instance . type
67
72
68
- // self name has highest priority
73
+ // explicit self name has highest priority
69
74
if ( type === COMPONENTS ) {
70
- // special self referencing call generated by compiler
71
- // inferred from SFC filename
72
- if ( name === `_self` ) {
73
- return Component
74
- }
75
-
76
75
const selfName = getComponentName ( Component )
77
76
if (
78
77
selfName &&
@@ -90,9 +89,16 @@ function resolveAsset(
90
89
resolve ( instance [ type ] || ( Component as ComponentOptions ) [ type ] , name ) ||
91
90
// global registration
92
91
resolve ( instance . appContext [ type ] , name )
92
+
93
+ if ( ! res && maybeSelfReference ) {
94
+ // fallback to implicit self-reference
95
+ return Component
96
+ }
97
+
93
98
if ( __DEV__ && warnMissing && ! res ) {
94
99
warn ( `Failed to resolve ${ type . slice ( 0 , - 1 ) } : ${ name } ` )
95
100
}
101
+
96
102
return res
97
103
} else if ( __DEV__ ) {
98
104
warn (
0 commit comments