From f8e7f60edfedf8a8fd5860d962b89fde1156986a Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Mon, 29 Nov 2021 17:11:41 -0800 Subject: [PATCH] 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 --- packages/compiler-cli/src/ngtsc/core/BUILD.bazel | 2 -- packages/compiler-cli/src/ngtsc/core/src/compiler.ts | 7 ++----- .../src/ngtsc/typecheck/extended/BUILD.bazel | 2 ++ .../src/ngtsc/typecheck/extended/index.ts | 12 ++++++++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/core/BUILD.bazel b/packages/compiler-cli/src/ngtsc/core/BUILD.bazel index 0f348a408b2..7f00fa4479a 100644 --- a/packages/compiler-cli/src/ngtsc/core/BUILD.bazel +++ b/packages/compiler-cli/src/ngtsc/core/BUILD.bazel @@ -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", diff --git a/packages/compiler-cli/src/ngtsc/core/src/compiler.ts b/packages/compiler-cli/src/ngtsc/core/src/compiler.ts index 1c893b282df..9ffb0e98434 100644 --- a/packages/compiler-cli/src/ngtsc/core/src/compiler.ts +++ b/packages/compiler-cli/src/ngtsc/core/src/compiler.ts @@ -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, diff --git a/packages/compiler-cli/src/ngtsc/typecheck/extended/BUILD.bazel b/packages/compiler-cli/src/ngtsc/typecheck/extended/BUILD.bazel index e84bab1fe0f..00218c0b36c 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/extended/BUILD.bazel +++ b/packages/compiler-cli/src/ngtsc/typecheck/extended/BUILD.bazel @@ -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", ], ) diff --git a/packages/compiler-cli/src/ngtsc/typecheck/extended/index.ts b/packages/compiler-cli/src/ngtsc/typecheck/extended/index.ts index c668f20a5e1..0717e4634d6 100644 --- a/packages/compiler-cli/src/ngtsc/typecheck/extended/index.ts +++ b/packages/compiler-cli/src/ngtsc/typecheck/extended/index.ts @@ -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[] = [ + invalidBananaInBoxFactory, + nullishCoalescingNotNullableFactory, + ];