diff --git a/packages/compiler-cli/src/ngtsc/typecheck/extended/api/BUILD.bazel b/packages/compiler-cli/src/ngtsc/typecheck/extended/api/BUILD.bazel new file mode 100644 index 0000000000..a2174ecf81 --- /dev/null +++ b/packages/compiler-cli/src/ngtsc/typecheck/extended/api/BUILD.bazel @@ -0,0 +1,15 @@ +load("//tools:defaults.bzl", "ts_library") + +ts_library( + name = "api", + srcs = glob( + ["**/*.ts"], + ), + visibility = ["//packages/compiler-cli/src/ngtsc:__subpackages__"], + deps = [ + "//packages/compiler", + "//packages/compiler-cli/src/ngtsc/diagnostics", + "//packages/compiler-cli/src/ngtsc/typecheck/api", + "@npm//typescript", + ], +) diff --git a/packages/compiler-cli/src/ngtsc/typecheck/extended/api/api.ts b/packages/compiler-cli/src/ngtsc/typecheck/extended/api/api.ts new file mode 100644 index 0000000000..43ab0f1fec --- /dev/null +++ b/packages/compiler-cli/src/ngtsc/typecheck/extended/api/api.ts @@ -0,0 +1,47 @@ +/** + * @license + * Copyright Google LLC All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +import {TmplAstNode} from '@angular/compiler'; +import * as ts from 'typescript'; + +import {ErrorCode} from '../../../diagnostics'; +import {TemplateTypeChecker} from '../../api'; + +/** + * A `ts.Diangostic` with a specific error code. + */ +export type TemplateDiagnostic = ts.Diagnostic&{code: T}; + +/** + * A Template Check receives information about the template it's checking and returns + * information about the diagnostics to be generated. + */ +export interface TemplateCheck { + /** Unique template check code, used for configuration and searching the error. */ + code: T; + + /** Runs check and returns information about the diagnostics to be generated. */ + run(ctx: TemplateContext, template: TmplAstNode[]): TemplateDiagnostic[]; +} + +/** + * The TemplateContext provided to a Template Check to get diagnostic information. + */ +export interface TemplateContext { + /** Interface that provides information about template nodes. */ + templateTypeChecker: TemplateTypeChecker; + + /** + * TypeScript interface that provides type information about symbols that appear + * in the template (it is not to query types outside the Angular component). + */ + typeChecker: ts.TypeChecker; + + /** The `@Component()` class from which the template was obtained. */ + component: ts.ClassDeclaration; +}