3
3
import Vue from 'vue'
4
4
import { compileToFunctions } from 'vue-template-compiler'
5
5
import { throwError } from './util'
6
- import { componentNeedsCompiling } from './validators'
6
+ import {
7
+ componentNeedsCompiling ,
8
+ templateContainsComponent
9
+ } from './validators'
7
10
import { compileTemplate } from './compile-template'
8
- import { capitalize , camelize , hyphenate } from './util'
9
11
10
12
function isVueComponent ( comp ) {
11
13
return comp && ( comp . render || comp . template || comp . options )
@@ -40,14 +42,16 @@ function getCoreProperties (component: Component): Object {
40
42
functional : component . functional
41
43
}
42
44
}
43
- function createStubFromString ( templateString : string , originalComponent : Component ) : Object {
45
+ function createStubFromString (
46
+ templateString : string ,
47
+ originalComponent : Component ,
48
+ name : string
49
+ ) : Object {
44
50
if ( ! compileToFunctions ) {
45
51
throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' )
46
52
}
47
53
48
- if ( templateString . indexOf ( hyphenate ( originalComponent . name ) ) !== - 1 ||
49
- templateString . indexOf ( capitalize ( originalComponent . name ) ) !== - 1 ||
50
- templateString . indexOf ( camelize ( originalComponent . name ) ) !== - 1 ) {
54
+ if ( templateContainsComponent ( templateString , name ) ) {
51
55
throwError ( 'options.stub cannot contain a circular reference' )
52
56
}
53
57
@@ -66,7 +70,10 @@ function createBlankStub (originalComponent: Component) {
66
70
}
67
71
}
68
72
69
- export function createComponentStubs ( originalComponents : Object = { } , stubs : Object ) : Object {
73
+ export function createComponentStubs (
74
+ originalComponents : Object = { } ,
75
+ stubs : Object
76
+ ) : Object {
70
77
const components = { }
71
78
if ( ! stubs ) {
72
79
return components
@@ -103,7 +110,7 @@ export function createComponentStubs (originalComponents: Object = {}, stubs: Ob
103
110
// Remove cached constructor
104
111
delete originalComponents [ stub ] . _Ctor
105
112
if ( typeof stubs [ stub ] === 'string' ) {
106
- components [ stub ] = createStubFromString ( stubs [ stub ] , originalComponents [ stub ] )
113
+ components [ stub ] = createStubFromString ( stubs [ stub ] , originalComponents [ stub ] , stub )
107
114
} else {
108
115
components [ stub ] = {
109
116
...stubs [ stub ] ,
0 commit comments