@@ -14,19 +14,19 @@ import {
1414} from './validators'
1515import { compileTemplate } from './compile-template'
1616
17- function isVueComponent ( comp ) {
17+ function isVueComponent ( comp ) : boolean {
1818 return comp && ( comp . render || comp . template || comp . options )
1919}
2020
21- function isValidStub ( stub : any ) {
21+ function isValidStub ( stub : any ) : boolean {
2222 return (
2323 ( ! ! stub && typeof stub === 'string' ) ||
2424 stub === true ||
2525 isVueComponent ( stub )
2626 )
2727}
2828
29- function resolveComponent ( obj , component ) {
29+ function resolveComponent ( obj : Object , component : string ) : Object {
3030 return obj [ component ] ||
3131 obj [ hyphenate ( component ) ] ||
3232 obj [ camelize ( component ) ] ||
@@ -35,7 +35,7 @@ function resolveComponent (obj, component) {
3535 { }
3636}
3737
38- function isRequiredComponent ( name ) {
38+ function isRequiredComponent ( name ) : boolean {
3939 return (
4040 name === 'KeepAlive' || name === 'Transition' || name === 'TransitionGroup'
4141 )
@@ -59,11 +59,12 @@ function getCoreProperties (componentOptions: Component): Object {
5959 functional : componentOptions . functional
6060 }
6161}
62+
6263function createStubFromString (
6364 templateString : string ,
6465 originalComponent : Component ,
6566 name : string
66- ) : Object {
67+ ) : Component {
6768 if ( ! compileToFunctions ) {
6869 throwError (
6970 `vueTemplateCompiler is undefined, you must pass ` +
@@ -86,7 +87,10 @@ function createStubFromString (
8687 }
8788}
8889
89- function createBlankStub ( originalComponent : Component , name : string ) {
90+ function createBlankStub (
91+ originalComponent : Component ,
92+ name : string
93+ ) : Component {
9094 const componentOptions = typeof originalComponent === 'function'
9195 ? originalComponent . extendOptions
9296 : originalComponent
@@ -110,8 +114,8 @@ function createBlankStub (originalComponent: Component, name: string) {
110114
111115export function createComponentStubs (
112116 originalComponents : Object = { } ,
113- stubs : Object
114- ) : Object {
117+ stubs : Stubs
118+ ) : Components {
115119 const components = { }
116120 if ( ! stubs ) {
117121 return components
@@ -130,55 +134,61 @@ export function createComponentStubs (
130134 components [ stub ] = createBlankStub ( component , stub )
131135 } )
132136 } else {
133- Object . keys ( stubs ) . forEach ( stub => {
134- if ( stubs [ stub ] === false ) {
137+ const stubsObject = ( stubs : { [ name : string ] : Component | string | true } )
138+ Object . keys ( stubsObject ) . forEach ( stubName => {
139+ const stub = stubsObject [ stubName ]
140+ if ( stub === false ) {
135141 return
136142 }
137- if ( ! isValidStub ( stubs [ stub ] ) ) {
143+
144+ if ( ! isValidStub ( stub ) ) {
138145 throwError (
139146 `options.stub values must be passed a string or ` + `component`
140147 )
141148 }
142- if ( stubs [ stub ] === true ) {
143- const component = resolveComponent ( originalComponents , stub )
144- components [ stub ] = createBlankStub ( component , stub )
149+
150+ if ( stub === true ) {
151+ const component = resolveComponent ( originalComponents , stubName )
152+ components [ stubName ] = createBlankStub ( component , stubName )
145153 return
146154 }
147155
148- if ( componentNeedsCompiling ( stubs [ stub ] ) ) {
149- compileTemplate ( stubs [ stub ] )
156+ if ( typeof stub !== 'string' && componentNeedsCompiling ( stub ) ) {
157+ compileTemplate ( stub )
150158 }
151159
152- if ( originalComponents [ stub ] ) {
160+ if ( originalComponents [ stubName ] ) {
153161 // Remove cached constructor
154- delete originalComponents [ stub ] . _Ctor
155- if ( typeof stubs [ stub ] === 'string' ) {
156- components [ stub ] = createStubFromString (
157- stubs [ stub ] ,
158- originalComponents [ stub ] ,
159- stub
162+ delete originalComponents [ stubName ] . _Ctor
163+ if ( typeof stub === 'string' ) {
164+ components [ stubName ] = createStubFromString (
165+ stub ,
166+ originalComponents [ stubName ] ,
167+ stubName
160168 )
161169 } else {
162- components [ stub ] = {
163- ...stubs [ stub ] ,
164- name : originalComponents [ stub ] . name
170+ const stubObject = ( stub : Object )
171+ components [ stubName ] = {
172+ ...stubObject ,
173+ name : originalComponents [ stubName ] . name
165174 }
166175 }
167176 } else {
168- if ( typeof stubs [ stub ] === 'string' ) {
177+ if ( typeof stub === 'string' ) {
169178 if ( ! compileToFunctions ) {
170179 throwError (
171180 `vueTemplateCompiler is undefined, you must pass ` +
172181 `precompiled components if vue-template-compiler is ` +
173182 `undefined`
174183 )
175184 }
176- components [ stub ] = {
177- ...compileToFunctions ( stubs [ stub ] )
185+ components [ stubName ] = {
186+ ...compileToFunctions ( stub )
178187 }
179188 } else {
180- components [ stub ] = {
181- ...stubs [ stub ]
189+ const stubObject = ( stub : Object )
190+ components [ stubName ] = {
191+ ...stubObject
182192 }
183193 }
184194 }
@@ -187,7 +197,10 @@ export function createComponentStubs (
187197 return components
188198}
189199
190- function stubComponents ( components : Object , stubbedComponents : Object ) {
200+ function stubComponents (
201+ components : Components ,
202+ stubbedComponents : Components
203+ ) : void {
191204 Object . keys ( components ) . forEach ( component => {
192205 const cmp = components [ component ]
193206 const componentOptions = typeof cmp === 'function'
@@ -202,7 +215,7 @@ function stubComponents (components: Object, stubbedComponents: Object) {
202215 } )
203216}
204217
205- export function createComponentStubsForAll ( component : Component ) : Object {
218+ export function createComponentStubsForAll ( component : Component ) : Components {
206219 const stubbedComponents = { }
207220
208221 if ( component . components ) {
@@ -228,7 +241,9 @@ export function createComponentStubsForAll (component: Component): Object {
228241 return stubbedComponents
229242}
230243
231- export function createComponentStubsForGlobals ( instance : Component ) : Object {
244+ export function createComponentStubsForGlobals (
245+ instance : Component
246+ ) : Components {
232247 const components = { }
233248 Object . keys ( instance . options . components ) . forEach ( c => {
234249 if ( isRequiredComponent ( c ) ) {
0 commit comments