mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
fix(compiler-cli): avoid fatal diagnostics for invalid module schemas (#61220)
In the event of an invalid `schemas` field for an Angular module, an empty schema array will now be used instead of a fatal error occurring. A build will still fail in this case with the error reported as a diagnostic. However, for the language service, this allows the module to exist in the compiler registry and prevents cascading diagnostics within an IDE due to "missing" modules/components. The originating schema related errors will still be reported in the IDE. PR Close #61220
This commit is contained in:
parent
ba38e1c301
commit
f03ff5acf9
1 changed files with 20 additions and 4 deletions
|
|
@ -466,10 +466,26 @@ export class NgModuleDecoratorHandler
|
|||
}
|
||||
}
|
||||
|
||||
const schemas =
|
||||
this.compilationMode !== CompilationMode.LOCAL && ngModule.has('schemas')
|
||||
? extractSchemas(ngModule.get('schemas')!, this.evaluator, 'NgModule')
|
||||
: [];
|
||||
let schemas: SchemaMetadata[] | undefined;
|
||||
try {
|
||||
schemas =
|
||||
this.compilationMode !== CompilationMode.LOCAL && ngModule.has('schemas')
|
||||
? extractSchemas(ngModule.get('schemas')!, this.evaluator, 'NgModule')
|
||||
: [];
|
||||
} catch (e) {
|
||||
if (e instanceof FatalDiagnosticError) {
|
||||
diagnostics.push(e.toDiagnostic());
|
||||
|
||||
// Use an empty schema array if schema extract fails.
|
||||
// A build will still fail in this case. However, for the language service,
|
||||
// this allows the module to exist in the compiler registry and prevents
|
||||
// cascading diagnostics within an IDE due to "missing" components. The
|
||||
// originating schema related errors will still be reported in the IDE.
|
||||
schemas = [];
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
let id: Expression | null = null;
|
||||
if (ngModule.has('id')) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue