33import Vue from 'vue'
44import { compileToFunctions } from 'vue-template-compiler'
55import { throwError } from './util'
6- import { componentNeedsCompiling } from './validators'
6+ import {
7+ componentNeedsCompiling ,
8+ templateContainsComponent
9+ } from './validators'
710import { compileTemplate } from './compile-template'
8- import { capitalize , camelize , hyphenate } from './util'
911
1012function isVueComponent ( comp ) {
1113 return comp && ( comp . render || comp . template || comp . options )
@@ -40,14 +42,16 @@ function getCoreProperties (component: Component): Object {
4042 functional : component . functional
4143 }
4244}
43- function createStubFromString ( templateString : string , originalComponent : Component ) : Object {
45+ function createStubFromString (
46+ templateString : string ,
47+ originalComponent : Component ,
48+ name : string
49+ ) : Object {
4450 if ( ! compileToFunctions ) {
4551 throwError ( 'vueTemplateCompiler is undefined, you must pass components explicitly if vue-template-compiler is undefined' )
4652 }
4753
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 ) ) {
5155 throwError ( 'options.stub cannot contain a circular reference' )
5256 }
5357
@@ -66,7 +70,10 @@ function createBlankStub (originalComponent: Component) {
6670 }
6771}
6872
69- export function createComponentStubs ( originalComponents : Object = { } , stubs : Object ) : Object {
73+ export function createComponentStubs (
74+ originalComponents : Object = { } ,
75+ stubs : Object
76+ ) : Object {
7077 const components = { }
7178 if ( ! stubs ) {
7279 return components
@@ -103,7 +110,7 @@ export function createComponentStubs (originalComponents: Object = {}, stubs: Ob
103110 // Remove cached constructor
104111 delete originalComponents [ stub ] . _Ctor
105112 if ( typeof stubs [ stub ] === 'string' ) {
106- components [ stub ] = createStubFromString ( stubs [ stub ] , originalComponents [ stub ] )
113+ components [ stub ] = createStubFromString ( stubs [ stub ] , originalComponents [ stub ] , stub )
107114 } else {
108115 components [ stub ] = {
109116 ...stubs [ stub ] ,
0 commit comments