From 9cfea3d522c0e4a34bb3a5d0fa9d04f64de39b49 Mon Sep 17 00:00:00 2001 From: JoostK Date: Sat, 30 Apr 2022 12:40:10 +0200 Subject: [PATCH] fix(compiler-cli): report invalid imports in standalone components during resolve phase (#45827) The analysis phase of the compiler should operate on individual classes, independently of the analysis of other classes. The validation that `Component.imports` only contains standalone entities or NgModules however did happen during the analysis phase, introducing a dependency on other classes and causing inconsistencies due to ordering and/or asynchronous timing differences. This commit fixes the issue by moving the validation to the resolve phase, which occurs after all classes have been analyzed. Fixes #45819 PR Close #45827 --- .../ngtsc/annotations/component/src/handler.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts b/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts index 17ca0077251..21d2ae247bf 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/component/src/handler.ts @@ -276,16 +276,6 @@ export class ComponentDecoratorHandler implements } diagnostics.push(...importDiagnostics); } - - const validationDiagnostics = - validateStandaloneImports(resolvedImports, rawImports, this.metaReader, this.scopeReader); - if (validationDiagnostics.length > 0) { - isPoisoned = true; - if (diagnostics === undefined) { - diagnostics = []; - } - diagnostics.push(...validationDiagnostics); - } } let schemas: SchemaMetadata[]|null = null; @@ -801,6 +791,12 @@ export class ComponentDecoratorHandler implements } } + if (analysis.resolvedImports !== null && analysis.rawImports !== null) { + const standaloneDiagnostics = validateStandaloneImports( + analysis.resolvedImports, analysis.rawImports, this.metaReader, this.scopeReader); + diagnostics.push(...standaloneDiagnostics); + } + if (analysis.providersRequiringFactory !== null && analysis.meta.providers instanceof WrappedNodeExpr) { const providerDiagnostics = getProviderDiagnostics(