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
This commit is contained in:
JoostK 2022-04-30 12:40:10 +02:00 committed by Dylan Hunn
parent 38f2906422
commit 9cfea3d522

View file

@ -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(