feat(ivy): turn on template type-checking via fullTemplateTypeCheck (#26203)
This commit enables generation and checking of a type checking ts.Program whenever the fullTemplateTypeCheck flag is enabled in tsconfig.json. It puts together all the pieces built previously and causes diagnostics to be emitted whenever type errors are discovered in a template. Todos: * map errors back to template HTML * expand set of type errors covered in generated type-check blocks PR Close #26203
This commit is contained in:

committed by
Jason Aden

parent
36d6e6076e
commit
19c4e705ff
@ -19,6 +19,7 @@ import {FactoryGenerator, FactoryInfo, GeneratedFactoryHostWrapper, generatedFac
|
||||
import {TypeScriptReflectionHost} from './metadata';
|
||||
import {FileResourceLoader, HostResourceLoader} from './resource_loader';
|
||||
import {IvyCompilation, ivyTransformFactory} from './transform';
|
||||
import {TypeCheckContext, TypeCheckProgramHost} from './typecheck';
|
||||
|
||||
export class NgtscProgram implements api.Program {
|
||||
private tsProgram: ts.Program;
|
||||
@ -103,7 +104,13 @@ export class NgtscProgram implements api.Program {
|
||||
fileName?: string|undefined, cancellationToken?: ts.CancellationToken|
|
||||
undefined): ReadonlyArray<ts.Diagnostic|api.Diagnostic> {
|
||||
const compilation = this.ensureAnalyzed();
|
||||
return compilation.diagnostics;
|
||||
const diagnostics = [...compilation.diagnostics];
|
||||
if (!!this.options.fullTemplateTypeCheck) {
|
||||
const ctx = new TypeCheckContext();
|
||||
compilation.typeCheck(ctx);
|
||||
diagnostics.push(...this.compileTypeCheckProgram(ctx));
|
||||
}
|
||||
return diagnostics;
|
||||
}
|
||||
|
||||
async loadNgStructureAsync(): Promise<void> {
|
||||
@ -183,6 +190,17 @@ export class NgtscProgram implements api.Program {
|
||||
return emitResult;
|
||||
}
|
||||
|
||||
private compileTypeCheckProgram(ctx: TypeCheckContext): ReadonlyArray<ts.Diagnostic> {
|
||||
const host = new TypeCheckProgramHost(this.tsProgram, this.host, ctx);
|
||||
const auxProgram = ts.createProgram({
|
||||
host,
|
||||
rootNames: this.tsProgram.getRootFileNames(),
|
||||
oldProgram: this.tsProgram,
|
||||
options: this.options,
|
||||
});
|
||||
return auxProgram.getSemanticDiagnostics();
|
||||
}
|
||||
|
||||
private makeCompilation(): IvyCompilation {
|
||||
const checker = this.tsProgram.getTypeChecker();
|
||||
const scopeRegistry = new SelectorScopeRegistry(checker, this.reflector);
|
||||
|
Reference in New Issue
Block a user