8000 fix(compiler-cli): avoid fatal diagnostics for invalid module schemas… · angular/angular@9ec9c7e · GitHub
[go: up one dir, main page]

Skip to content

Commit 9ec9c7e

Browse files
clydinalxhub
authored andcommitted
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
1 parent 6e2fa1d commit 9ec9c7e

File tree

1 file changed

+20
-4
lines changed
  • packages/compiler-cli/src/ngtsc/annotations/ng_module/src

1 file changed

+20
-4
lines changed

packages/compiler-cli/src/ngtsc/annotations/ng_module/src/handler.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,26 @@ export class NgModuleDecoratorHandler
466466
}
467467
}
468468

469-
const schemas =
470-
this.compilationMode !== CompilationMode.LOCAL && ngModule.has('schemas')
471-
? extractSchemas(ngModule.get('schemas')!, this.evaluator, 'NgModule')
472-
: [];
469+
let schemas: SchemaMetadata[] | undefined;
470+
try {
471+
schemas =
472+
this.compilationMode !== CompilationMode.LOCAL && ngModule.has('schemas')
473+
? extractSchemas(ngModule.get('schemas')!, this.evaluator, 'NgModule')
474+
: [];
475+
} catch (e) {
476+
if (e instanceof FatalDiagnosticError) {
477+
diagnostics.push(e.toDiagnostic());
478+
479+
// Use an empty schema array if schema extract fails.
480+
// A build will still fail in this case. However, for the language service,
481+
// this allows the module to exist in the compiler registry and prevents
482+
// cascading diagnostics within an IDE due to "missing" components. The
483+
// originating schema related errors will still be reported in the IDE.
484+
schemas = [];
485+
} else {
486+
throw e;
487+
}
488+
}
473489

474490
let id: Expression | null = null;
475491
if (ngModule.has('id')) {

0 commit comments

Comments
 (0)
0