@@ -151,10 +151,12 @@ export class LocalModuleScopeRegistry implements MetadataRegistry, ComponentScop
151151 registerPipeMetadata ( pipe : PipeMeta ) : void { }
152152
153153 getScopeForComponent ( clazz : ClassDeclaration ) : LocalModuleScope | null {
154- const scope = ! this . declarationToModule . has ( clazz )
155- ? null
156- : this . getScopeOfModule ( this . declarationToModule . get ( clazz ) ! . ngModule ) ;
157- return scope ;
154+ if ( ! this . declarationToModule . has ( clazz ) ) {
155+ return null ;
156+ }
157+
158+ const module = this . declarationToModule . get ( clazz ) ! . ngModule ;
159+ return this . getScopeOfModule ( module ) ;
158160 }
159161
160162 /**
@@ -181,9 +183,12 @@ export class LocalModuleScopeRegistry implements MetadataRegistry, ComponentScop
181183 * defined, or the string `'error'` if the scope contained errors.
182184 */
183185 getScopeOfModule ( clazz : ClassDeclaration ) : LocalModuleScope | null {
184- return this . moduleToRef . has ( clazz )
185- ? this . getScopeOfModuleReference ( this . moduleToRef . get ( clazz ) ! )
186- : null ;
186+ if ( ! this . moduleToRef . has ( clazz ) ) {
187+ return null ;
188+ }
189+
190+ const scope = this . getScopeOfModuleReference ( this . moduleToRef . get ( clazz ) ! ) ;
191+ return scope === 'cycle' ? null : scope ;
187192 }
188193
189194 /**
@@ -249,13 +254,17 @@ export class LocalModuleScopeRegistry implements MetadataRegistry, ComponentScop
249254 /**
250255 * Implementation of `getScopeOfModule` which accepts a reference to a class.
251256 */
252- private getScopeOfModuleReference ( ref : Reference < ClassDeclaration > ) : LocalModuleScope | null {
257+ private getScopeOfModuleReference (
258+ ref : Reference < ClassDeclaration > ,
259+ ) : LocalModuleScope | null | 'cycle' {
253260 if ( this . cache . has ( ref . node ) ) {
254261 const cachedValue = this . cache . get ( ref . node ) ;
255262
256- if ( cachedValue ! == IN_PROGRESS_RESOLUTION ) {
257- return cachedValue as LocalModuleScope | null ;
263+ if ( cachedValue = == IN_PROGRESS_RESOLUTION ) {
264+ return 'cycle' ;
258265 }
266+
267+ return cachedValue as LocalModuleScope | null ;
259268 }
260269
261270 this . cache . set ( ref . node , IN_PROGRESS_RESOLUTION ) ;
@@ -593,7 +602,8 @@ export class LocalModuleScopeRegistry implements MetadataRegistry, ComponentScop
593602 }
594603 return this . dependencyScopeReader . resolve ( ref ) ;
595604 } else {
596- if ( this . cache . get ( ref . node ) === IN_PROGRESS_RESOLUTION ) {
605+ const scope = this . getScopeOfModuleReference ( ref ) ;
606+ if ( scope === 'cycle' ) {
597607 diagnostics . push (
598608 makeDiagnostic (
599609 type === 'import'
@@ -603,11 +613,10 @@ export class LocalModuleScopeRegistry implements MetadataRegistry, ComponentScop
603613 `NgModule "${ type } " field contains a cycle` ,
604614 ) ,
605615 ) ;
606- return 'cycle' ;
607616 }
608617
609618 // The NgModule is declared locally in the current program. Resolve it from the registry.
610- return this . getScopeOfModuleReference ( ref ) ;
619+ return scope ;
611620 }
612621 }
613622
0 commit comments