forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler-cli): introduce the TemplateTypeChecker abstraction (…
…angular#38105) This commit significantly refactors the 'typecheck' package to introduce a new abstraction, the `TemplateTypeChecker`. To achieve this: * a 'typecheck:api' package is introduced, containing common interfaces that consumers of the template type-checking infrastructure can depend on without incurring a dependency on the template type-checking machinery as a whole. * interfaces for `TemplateTypeChecker` and `TypeCheckContext` are introduced which contain the abstract operations supported by the implementation classes `TemplateTypeCheckerImpl` and `TypeCheckContextImpl` respectively. * the `TemplateTypeChecker` interface supports diagnostics on a whole program basis to start with, but the implementation is purposefully designed to support incremental diagnostics at a per-file or per-component level. * `TemplateTypeChecker` supports direct access to the type check block of a component. * the testing utility is refactored to be a lot more useful, and new tests are added for the new abstraction. PR Close angular#38105
- Loading branch information
Showing
43 changed files
with
694 additions
and
313 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load("//tools:defaults.bzl", "ts_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ts_library( | ||
name = "api", | ||
srcs = glob(["**/*.ts"]), | ||
module_name = "@angular/compiler-cli/src/ngtsc/typecheck/api", | ||
deps = [ | ||
"//packages:types", | ||
"//packages/compiler", | ||
"//packages/compiler-cli/src/ngtsc/file_system", | ||
"//packages/compiler-cli/src/ngtsc/imports", | ||
"//packages/compiler-cli/src/ngtsc/metadata", | ||
"//packages/compiler-cli/src/ngtsc/reflection", | ||
"@npm//typescript", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* @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'; | ||
|
||
/** | ||
* Interface to the Angular Template Type Checker to extract diagnostics and intelligence from the | ||
* compiler's understanding of component templates. | ||
* | ||
* This interface is analogous to TypeScript's own `ts.TypeChecker` API. | ||
* | ||
* In general, this interface supports two kinds of operations: | ||
* - updating Type Check Blocks (TCB)s that capture the template in the form of TypeScript code | ||
* - querying information about available TCBs, including diagnostics | ||
* | ||
* Once a TCB is available, information about it can be queried. If no TCB is available to answer a | ||
* query, depending on the method either `null` will be returned or an error will be thrown. | ||
*/ | ||
export interface TemplateTypeChecker { | ||
/** | ||
* Get all `ts.Diagnostic`s currently available for the given `ts.SourceFile`. | ||
* | ||
* This method will fail (throw) if there are components within the `ts.SourceFile` that do not | ||
* have TCBs available. | ||
*/ | ||
getDiagnosticsForFile(sf: ts.SourceFile): ts.Diagnostic[]; | ||
|
||
/** | ||
* Retrieve the top-level node representing the TCB for the given component. | ||
* | ||
* This can return `null` if there is no TCB available for the component. | ||
* | ||
* This method always runs in `OptimizeFor.SingleFile` mode. | ||
*/ | ||
getTypeCheckBlock(component: ts.ClassDeclaration): ts.Node|null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* @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 {ParseSourceFile, R3TargetBinder, SchemaMetadata, TmplAstNode} from '@angular/compiler'; | ||
import * as ts from 'typescript'; | ||
|
||
import {Reference} from '../../imports'; | ||
import {ClassDeclaration} from '../../reflection'; | ||
|
||
import {TemplateSourceMapping, TypeCheckableDirectiveMeta} from './api'; | ||
|
||
/** | ||
* A currently pending type checking operation, into which templates for type-checking can be | ||
* registered. | ||
*/ | ||
export interface TypeCheckContext { | ||
/** | ||
* Register a template to potentially be type-checked. | ||
* | ||
* Templates registered via `addTemplate` are available for checking, but might be skipped if | ||
* checking of that component is not required. This can happen for a few reasons, including if | ||
* the component was previously checked and the prior results are still valid. | ||
* | ||
* @param ref a `Reference` to the component class which yielded this template. | ||
* @param binder an `R3TargetBinder` which encapsulates the scope of this template, including all | ||
* available directives. | ||
* @param template the original template AST of this component. | ||
* @param pipes a `Map` of pipes available within the scope of this template. | ||
* @param schemas any schemas which apply to this template. | ||
* @param sourceMapping a `TemplateSourceMapping` instance which describes the origin of the | ||
* template text described by the AST. | ||
* @param file the `ParseSourceFile` associated with the template. | ||
*/ | ||
addTemplate( | ||
ref: Reference<ClassDeclaration<ts.ClassDeclaration>>, | ||
binder: R3TargetBinder<TypeCheckableDirectiveMeta>, template: TmplAstNode[], | ||
pipes: Map<string, Reference<ClassDeclaration<ts.ClassDeclaration>>>, | ||
schemas: SchemaMetadata[], sourceMapping: TemplateSourceMapping, file: ParseSourceFile): void; | ||
} | ||
|
||
/** | ||
* Interface to trigger generation of type-checking code for a program given a new | ||
* `TypeCheckContext`. | ||
*/ | ||
export interface ProgramTypeCheckAdapter { | ||
typeCheck(sf: ts.SourceFile, ctx: TypeCheckContext): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* @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 | ||
*/ | ||
|
||
export * from './api'; | ||
export * from './checker'; | ||
export * from './context'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.