refactor(compiler-cli): introduce extended package to typecheck with it's API (#42984)

This commit introduces //packages/compiler-cli/src/ngtsc/typecheck/extended
as a container for a new phase of diagnostics generation. The API provides an
interface for new template checks to implement and generate template diagnostics.

Refs #42966

PR Close #42984
This commit is contained in:
Daniel Trevino 2021-07-23 17:14:49 +00:00 committed by Andrew Kushnir
parent e3415e597e
commit 3a092d6cea
2 changed files with 62 additions and 0 deletions

View File

@ -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",
],
)

View File

@ -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<T extends ErrorCode> = 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<T extends ErrorCode> {
/** 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<T>[];
}
/**
* 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;
}