refactor(compiler-cli): make file/shim split 1:n instead of 1:1 (#38105)

Previously in the template type-checking engine, it was assumed that every
input file would have an associated type-checking shim. The type check block
code for all components in the input file would be generated into this shim.

This is fine for whole-program type checking operations, but to support the
language service's requirements for low latency, it would be ideal to be
able to check a single component in isolation, especially if the component
is declared along with many others in a single file.

This commit removes the assumption that the file/shim mapping is 1:1, and
introduces the concept of component-to-shim mapping. Any
`TypeCheckingProgramStrategy` must provide such a mapping.

To achieve this:

 * type checking record information is now split into file-level data as
   well as per-shim data.
 * components are now assigned a stable `TemplateId` which is unique to the
   file in which they're declared.

PR Close #38105
This commit is contained in:
Alex Rickabaugh
2020-06-22 12:32:24 -07:00
committed by Misko Hevery
parent 9c8bc4a239
commit 736f6337b2
8 changed files with 200 additions and 89 deletions

View File

@ -12,21 +12,21 @@ import {AbsoluteFsPath} from '../file_system';
/**
* Interface of the incremental build engine.
*
* `W` is a generic type representing a unit of work. This is generic to avoid a cyclic dependency
* between the incremental engine API definition and its consumer(s).
* `T` is a generic type representing template type-checking data for a particular file, which is
* generic for the same reason.
* `AnalysisT` is a generic type representing a unit of work. This is generic to avoid a cyclic
* dependency between the incremental engine API definition and its consumer(s).
* `FileTypeCheckDataT` is a generic type representing template type-checking data for a particular
* input file, which is generic for the same reason.
*/
export interface IncrementalBuild<W, T> {
export interface IncrementalBuild<AnalysisT, FileTypeCheckDataT> {
/**
* Retrieve the prior analysis work, if any, done for the given source file.
*/
priorWorkFor(sf: ts.SourceFile): W[]|null;
priorWorkFor(sf: ts.SourceFile): AnalysisT[]|null;
/**
* Retrieve the prior type-checking work, if any, that's been done for the given source file.
*/
priorTypeCheckingResultsFor(sf: ts.SourceFile): T|null;
priorTypeCheckingResultsFor(fileSf: ts.SourceFile): FileTypeCheckDataT|null;
}
/**