diff --git a/goldens/public-api/compiler-cli/compiler_options.md b/goldens/public-api/compiler-cli/compiler_options.md index 106c43325ab..2125d3d7e9a 100644 --- a/goldens/public-api/compiler-cli/compiler_options.md +++ b/goldens/public-api/compiler-cli/compiler_options.md @@ -10,6 +10,22 @@ export interface BazelAndG3Options { generateDeepReexports?: boolean; } +// @public +export enum DiagnosticCategoryLabel { + Error = "error", + Suppress = "suppress", + Warning = "warning" +} + +// @public +export interface DiagnosticOptions { + extendedDiagnostics?: { + checks?: { + [Name in ExtendedTemplateDiagnosticName]?: DiagnosticCategoryLabel; + }; + }; +} + // @public export interface I18nOptions { enableI18nLegacyMessageIdFormat?: boolean; diff --git a/packages/compiler-cli/src/ngtsc/core/BUILD.bazel b/packages/compiler-cli/src/ngtsc/core/BUILD.bazel index 7f00fa4479a..0dc379f3a5d 100644 --- a/packages/compiler-cli/src/ngtsc/core/BUILD.bazel +++ b/packages/compiler-cli/src/ngtsc/core/BUILD.bazel @@ -47,6 +47,7 @@ ts_library( name = "api", srcs = glob(["api/**/*.ts"]), deps = [ + "//packages/compiler-cli/src/ngtsc/diagnostics", "//packages/compiler-cli/src/ngtsc/file_system", "//packages/compiler-cli/src/ngtsc/shims:api", "@npm//typescript", diff --git a/packages/compiler-cli/src/ngtsc/core/api/src/options.ts b/packages/compiler-cli/src/ngtsc/core/api/src/options.ts index 39f4d141ce2..923b0972272 100644 --- a/packages/compiler-cli/src/ngtsc/core/api/src/options.ts +++ b/packages/compiler-cli/src/ngtsc/core/api/src/options.ts @@ -8,7 +8,7 @@ import ts from 'typescript'; -import {BazelAndG3Options, I18nOptions, LegacyNgcOptions, MiscOptions, NgcCompatibilityOptions, StrictTemplateOptions, TargetOptions} from './public_options'; +import {BazelAndG3Options, DiagnosticOptions, I18nOptions, LegacyNgcOptions, MiscOptions, NgcCompatibilityOptions, StrictTemplateOptions, TargetOptions} from './public_options'; /** @@ -53,6 +53,12 @@ export interface InternalOptions { * Also includes a few miscellaneous options. */ export interface NgCompilerOptions extends ts.CompilerOptions, LegacyNgcOptions, BazelAndG3Options, - NgcCompatibilityOptions, StrictTemplateOptions, - TestOnlyOptions, I18nOptions, TargetOptions, - InternalOptions, MiscOptions {} + DiagnosticOptions, NgcCompatibilityOptions, + StrictTemplateOptions, TestOnlyOptions, I18nOptions, + TargetOptions, InternalOptions, MiscOptions { + // Replace the index signature type from `ts.CompilerOptions` as it is more strict than it needs + // to be and would conflict with some types from the other interfaces. This is ok because Angular + // compiler options are actually separate from TS compiler options in the `tsconfig.json` and we + // have full control over the structure of Angular's compiler options. + [prop: string]: any; +} diff --git a/packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts b/packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts index 91da97d649a..765718eae74 100644 --- a/packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts +++ b/packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts @@ -6,6 +6,8 @@ * found in the LICENSE file at https://angular.io/license */ +import {ExtendedTemplateDiagnosticName} from '../../../../ngtsc/diagnostics'; + /** * Options supported by the legacy View Engine compiler, which are still consumed by the Angular Ivy * compiler for backwards compatibility. @@ -258,6 +260,40 @@ export interface StrictTemplateOptions { strictLiteralTypes?: boolean; } +/** + * A label referring to a `ts.DiagnosticCategory` or `'suppress'`, meaning the associated diagnostic + * should not be displayed at all. + * + * @publicApi + */ +export enum DiagnosticCategoryLabel { + /** Treat the diagnostic as a warning, don't fail the compilation. */ + Warning = 'warning', + + /** Treat the diagnostic as a hard error, fail the compilation. */ + Error = 'error', + + /** Ignore the diagnostic altogether. */ + Suppress = 'suppress', +} + +/** + * Options which control how diagnostics are emitted from the compiler. + * + * @publicApi + */ +export interface DiagnosticOptions { + /** Options which control how diagnostics are emitted from the compiler. */ + extendedDiagnostics?: { + /** + * A map of each extended template diagnostic's name to its category. This can be expanded in + * the future with more information for each check or for additional diagnostics not part of the + * extended template diagnostics system. + */ + checks?: {[Name in ExtendedTemplateDiagnosticName]?: DiagnosticCategoryLabel}; + }; +} + /** * Options which control behavior useful for "monorepo" build cases using Bazel (such as the * internal Google monorepo, g3).