@@ -21,7 +21,6 @@ import {
2121 DEFAULT_ERROR_CODE ,
2222 Diagnostic ,
2323 EmitFlags ,
24- LazyRoute ,
2524 Program ,
2625 SOURCE ,
2726 UNKNOWN_ERROR_CODE ,
@@ -422,25 +421,33 @@ export class AngularCompilerPlugin {
422421 }
423422
424423 private _listLazyRoutesFromProgram ( ) : LazyRouteMap {
425- let lazyRoutes : LazyRoute [ ] ;
424+ let entryRoute : string | undefined ;
425+ let ngProgram : Program ;
426+
426427 if ( this . _JitMode ) {
427428 if ( ! this . entryModule ) {
428429 return { } ;
429430 }
430431
431- const ngProgram = createProgram ( {
432+ time ( 'AngularCompilerPlugin._listLazyRoutesFromProgram.createProgram' ) ;
433+ ngProgram = createProgram ( {
432434 rootNames : this . _rootNames ,
433435 options : { ...this . _compilerOptions , genDir : '' , collectAllErrors : true } ,
434436 host : this . _compilerHost ,
435437 } ) ;
438+ timeEnd ( 'AngularCompilerPlugin._listLazyRoutesFromProgram.createProgram' ) ;
436439
437- lazyRoutes = ngProgram . listLazyRoutes (
438- this . entryModule . path + '#' + this . entryModule . className ,
439- ) ;
440+ entryRoute = this . entryModule . path + '#' + this . entryModule . className ;
440441 } else {
441- lazyRoutes = ( this . _program as Program ) . listLazyRoutes ( ) ;
442+ ngProgram = this . _program as Program ;
442443 }
443444
445+ time ( 'AngularCompilerPlugin._listLazyRoutesFromProgram.listLazyRoutes' ) ;
446+ // entryRoute will only be defined in JIT.
447+ // In AOT all routes within the program are returned.
448+ const lazyRoutes = ngProgram . listLazyRoutes ( entryRoute ) ;
449+ timeEnd ( 'AngularCompilerPlugin._listLazyRoutesFromProgram.listLazyRoutes' ) ;
450+
444451 return lazyRoutes . reduce (
445452 ( acc , curr ) => {
446453 const ref = curr . route ;
0 commit comments