@@ -32,7 +32,6 @@ export class Injector {
3232 wrapper as any ,
3333 module ,
3434 null ,
35- null ,
3635 instances => {
3736 collection . set ( metatype . name , {
3837 instance : new metatype ( ...instances ) ,
@@ -77,10 +76,9 @@ export class Injector {
7776 public async loadInstanceOfComponent (
7877 wrapper : InstanceWrapper < Injectable > ,
7978 module : Module ,
80- context : Module [ ] = [ ] ,
8179 ) {
8280 const components = module . components ;
83- await this . loadInstance < Injectable > ( wrapper , components , module , context ) ;
81+ await this . loadInstance < Injectable > ( wrapper , components , module ) ;
8482 }
8583
8684 public applyDoneSubject < T > ( wrapper : InstanceWrapper < T > ) : ( ) => void {
@@ -96,7 +94,6 @@ export class Injector {
9694 wrapper : InstanceWrapper < T > ,
9795 collection ,
9896 module : Module ,
99- context : Module [ ] = [ ] ,
10097 ) {
10198 if ( wrapper . isPending ) {
10299 return await wrapper . done$ ;
@@ -113,7 +110,6 @@ export class Injector {
113110 wrapper ,
114111 module ,
115112 inject ,
116- context ,
117113 async instances => {
118114 if ( isNil ( inject ) ) {
119115 currentMetatype . instance = Object . assign (
@@ -136,7 +132,6 @@ export class Injector {
136132 wrapper : InstanceWrapper < T > ,
137133 module : Module ,
138134 inject : any [ ] ,
139- context : Module [ ] ,
140135 callback : ( args ) => void ,
141136 ) {
142137 let isResolved = true ;
@@ -151,7 +146,6 @@ export class Injector {
151146 param ,
152147 { index, length : args . length } ,
153148 module ,
154- context ,
155149 ) ;
156150 if ( ! paramWrapper . isResolved && ! paramWrapper . forwardRef ) {
157151 isResolved = false ;
@@ -179,7 +173,6 @@ export class Injector {
179173 param : Type < any > | string | symbol | any ,
180174 { index, length } : { index : number ; length : number } ,
181175 module : Module ,
182- context : Module [ ] ,
183176 ) {
184177 if ( isUndefined ( param ) ) {
185178 throw new UndefinedDependencyException ( wrapper . name , index , length ) ;
@@ -190,7 +183,6 @@ export class Injector {
190183 isFunction ( token ) ? ( token as Type < any > ) . name : token ,
191184 { index, length } ,
192185 wrapper ,
193- context ,
194186 ) ;
195187 }
196188
@@ -210,15 +202,13 @@ export class Injector {
210202 name : any ,
211203 { index, length } : { index : number ; length : number } ,
212204 wrapper : InstanceWrapper < T > ,
213- context : Module [ ] ,
214205 ) {
215206 const components = module . components ;
216- const instanceWrapper = await this . scanForComponent (
207+ const instanceWrapper = await this . lookupComponent (
217208 components ,
218209 module ,
219210 { name, index, length } ,
220211 wrapper ,
221- context ,
222212 ) ;
223213 if ( ! instanceWrapper . isResolved && ! instanceWrapper . forwardRef ) {
224214 await this . loadInstanceOfComponent ( instanceWrapper , module ) ;
@@ -229,110 +219,50 @@ export class Injector {
229219 return instanceWrapper ;
230220 }
231221
232- public async scanForComponent (
222+ public async lookupComponent (
233223 components : Map < string , any > ,
234224 module : Module ,
235225 { name, index, length } : { name : any ; index : number ; length : number } ,
236226 { metatype } ,
237- context : Module [ ] = [ ] ,
238227 ) {
239- const component = await this . scanForComponentInScopes (
240- context ,
241- { name, index, length } ,
242- metatype ,
243- ) ;
244- if ( component ) {
245- return component ;
246- }
247228 const scanInExports = ( ) =>
248- this . scanForComponentInExports (
229+ this . lookupComponentInExports (
249230 components ,
250231 { name, index, length } ,
251232 module ,
252233 metatype ,
253- context ,
254234 ) ;
255235 return components . has ( name ) ? components . get ( name ) : await scanInExports ( ) ;
256236 }
257237
258- public async scanForComponentInExports (
238+ public async lookupComponentInExports (
259239 components : Map < string , any > ,
260240 { name, index, length } : { name : any ; index : number ; length : number } ,
261241 module : Module ,
262242 metatype ,
263- context : Module [ ] = [ ] ,
264243 ) {
265- const instanceWrapper = await this . scanForComponentInRelatedModules (
244+ const instanceWrapper = await this . lookupComponentInRelatedModules (
266245 module ,
267246 name ,
268- context ,
269247 ) ;
270248 if ( isNil ( instanceWrapper ) ) {
271249 throw new UnknownDependenciesException ( metatype . name , index , length ) ;
272250 }
273251 return instanceWrapper ;
274252 }
275253
276- public async scanForComponentInScopes (
277- context : Module [ ] ,
278- { name, index, length } : { name : any ; index : number ; length : number } ,
279- metatype ,
280- ) {
281- context = context || [ ] ;
282- for ( const ctx of context ) {
283- const component = await this . scanForComponentInScope (
284- ctx ,
285- { name, index, length } ,
286- metatype ,
287- ) ;
288- if ( component ) return component ;
289- }
290- return null ;
291- }
292-
293- public async scanForComponentInScope (
294- context : Module ,
295- { name, index, length } : { name : any ; index : number ; length : number } ,
296- metatype ,
297- ) {
298- try {
299- const component = await this . scanForComponent (
300- context . components ,
301- context ,
302- { name, index, length } ,
303- { metatype } ,
304- null ,
305- ) ;
306- if ( ! component . isResolved && ! component . forwardRef ) {
307- await this . loadInstanceOfComponent ( component , context ) ;
308- }
309- return component ;
310- } catch ( e ) {
311- if ( e instanceof RuntimeException ) {
312- return null ;
313- }
314- throw e ;
315- }
316- }
317-
318- public async scanForComponentInRelatedModules (
319- module : Module ,
320- name : any ,
321- context : Module [ ] ,
322- ) {
254+ public async lookupComponentInRelatedModules ( module : Module , name : any ) {
323255 let component = null ;
324256 const relatedModules = module . relatedModules || [ ] ;
325257
326258 for ( const relatedModule of this . flatMap ( [ ...relatedModules . values ( ) ] ) ) {
327259 const { components, exports } = relatedModule ;
328- const isInScope = context === null ;
329- if ( ( ! exports . has ( name ) && ! isInScope ) || ! components . has ( name ) ) {
260+ if ( ! exports . has ( name ) || ! components . has ( name ) ) {
330261 continue ;
331262 }
332263 component = components . get ( name ) ;
333264 if ( ! component . isResolved && ! component . forwardRef ) {
334- const ctx = isInScope ? [ module ] : [ ] . concat ( context , module ) ;
335- await this . loadInstanceOfComponent ( component , relatedModule , ctx ) ;
265+ await this . loadInstanceOfComponent ( component , relatedModule ) ;
336266 break ;
337267 }
338268 }
@@ -348,19 +278,20 @@ export class Injector {
348278 }
349279
350280 public flatMap ( modules : Module [ ] ) : Module [ ] {
351- return modules . concat . apply (
352- modules ,
353- modules . map ( ( module : Module ) => {
354- const { relatedModules, exports } = module ;
355- return this . flatMap (
356- [ ...relatedModules . values ( ) ]
357- . filter ( related => ! ! related )
358- . filter ( related => {
359- const { metatype } = related ;
360- return exports . has ( metatype . name ) ;
361- } ) ,
362- ) ;
363- } ) ,
364- ) ;
281+ if ( ! modules ) {
282+ return [ ] ;
283+ }
284+ const flatten = ( module : Module ) => {
285+ const { relatedModules, exports } = module ;
286+ return this . flatMap (
287+ [ ...relatedModules . values ( ) ]
288+ . filter ( related => ! ! related )
289+ . filter ( related => {
290+ const { metatype } = related ;
291+ return exports . has ( metatype . name ) ;
292+ } ) ,
293+ ) ;
294+ } ;
295+ return modules . concat . apply ( modules , modules . map ( flatten ) ) ;
365296 }
366297}
0 commit comments