refactor(compiler-cli): add allDiagnosticFactories (#44391)

Refs #42966.

This is a static array of all the 1P extended template diagnostic factories built into the Angular compiler directly. It provides an encapsulated list of all diagnostics rather than requiring users to manually list each one individually.

PR Close #44391
This commit is contained in:
Doug Parker
2021-11-29 17:11:41 -08:00
committed by Andrew Scott
parent a3082fbba7
commit f8e7f60edf
4 changed files with 16 additions and 7 deletions
@@ -37,8 +37,6 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/typecheck/diagnostics",
"//packages/compiler-cli/src/ngtsc/typecheck/extended",
"//packages/compiler-cli/src/ngtsc/typecheck/extended/api",
"//packages/compiler-cli/src/ngtsc/typecheck/extended/checks/invalid_banana_in_box",
"//packages/compiler-cli/src/ngtsc/typecheck/extended/checks/nullish_coalescing_not_nullable",
"//packages/compiler-cli/src/ngtsc/util",
"//packages/compiler-cli/src/ngtsc/xi18n",
"@npm//typescript",
@@ -28,10 +28,8 @@ import {generatedFactoryTransform} from '../../shims';
import {aliasTransformFactory, CompilationMode, declarationTransformFactory, DecoratorHandler, DtsTransformRegistry, ivyTransformFactory, TraitCompiler} from '../../transform';
import {TemplateTypeCheckerImpl} from '../../typecheck';
import {OptimizeFor, TemplateTypeChecker, TypeCheckingConfig} from '../../typecheck/api';
import {ExtendedTemplateCheckerImpl} from '../../typecheck/extended';
import {ALL_DIAGNOSTIC_FACTORIES, ExtendedTemplateCheckerImpl} from '../../typecheck/extended';
import {ExtendedTemplateChecker} from '../../typecheck/extended/api';
import {factory as invalidBananaInBoxFactory} from '../../typecheck/extended/checks/invalid_banana_in_box';
import {factory as NullishCoalescingNotNullableFactory} from '../../typecheck/extended/checks/nullish_coalescing_not_nullable';
import {getSourceFileOrNull, isDtsPath, toUnredirectedSourceFile} from '../../util/src/typescript';
import {Xi18nContext} from '../../xi18n';
import {NgCompilerAdapter, NgCompilerOptions} from '../api';
@@ -1067,9 +1065,8 @@ export class NgCompiler {
reflector, this.adapter, this.incrementalCompilation, scopeRegistry, typeCheckScopeRegistry,
this.delegatingPerfRecorder);
const diagnosticFactories = [invalidBananaInBoxFactory, NullishCoalescingNotNullableFactory];
const extendedTemplateChecker = new ExtendedTemplateCheckerImpl(
templateTypeChecker, checker, diagnosticFactories, this.options);
templateTypeChecker, checker, ALL_DIAGNOSTIC_FACTORIES, this.options);
return {
isCore,
@@ -11,6 +11,8 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/diagnostics",
"//packages/compiler-cli/src/ngtsc/typecheck/api",
"//packages/compiler-cli/src/ngtsc/typecheck/extended/api",
"//packages/compiler-cli/src/ngtsc/typecheck/extended/checks/invalid_banana_in_box",
"//packages/compiler-cli/src/ngtsc/typecheck/extended/checks/nullish_coalescing_not_nullable",
"@npm//typescript",
],
)
@@ -6,4 +6,16 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ErrorCode, ExtendedTemplateDiagnosticName} from '../../diagnostics';
import {TemplateCheckFactory} from './api';
import {factory as invalidBananaInBoxFactory} from './checks/invalid_banana_in_box';
import {factory as nullishCoalescingNotNullableFactory} from './checks/nullish_coalescing_not_nullable';
export {ExtendedTemplateCheckerImpl} from './src/extended_template_checker';
export const ALL_DIAGNOSTIC_FACTORIES:
readonly TemplateCheckFactory<ErrorCode, ExtendedTemplateDiagnosticName>[] = [
invalidBananaInBoxFactory,
nullishCoalescingNotNullableFactory,
];