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:
Alex Rickabaugh
2018-09-21 14:03:55 -07:00
committed by Jason Aden
parent 36d6e6076e
commit 19c4e705ff
8 changed files with 111 additions and 26 deletions

View File

@ -15,6 +15,7 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/host",
"//packages/compiler-cli/src/ngtsc/metadata",
"//packages/compiler-cli/src/ngtsc/translator",
"//packages/compiler-cli/src/ngtsc/typecheck",
"//packages/compiler-cli/src/ngtsc/util",
],
)

View File

@ -10,6 +10,7 @@ import {ConstantPool, Expression, Statement, Type} from '@angular/compiler';
import * as ts from 'typescript';
import {Decorator} from '../../host';
import {TypeCheckContext} from '../../typecheck';
/**
@ -43,6 +44,8 @@ export interface DecoratorHandler<A, M> {
*/
analyze(node: ts.Declaration, metadata: M): AnalysisOutput<A>;
typeCheck?(ctx: TypeCheckContext, node: ts.Declaration, metadata: A): void;
/**
* Generate a description of the field which should be added to the class, including any
* initialization code to be generated.
@ -60,6 +63,7 @@ export interface AnalysisOutput<A> {
analysis?: A;
diagnostics?: ts.Diagnostic[];
factorySymbolName?: string;
typeCheck?: boolean;
}
/**

View File

@ -12,10 +12,12 @@ import * as ts from 'typescript';
import {FatalDiagnosticError} from '../../diagnostics';
import {Decorator, ReflectionHost} from '../../host';
import {reflectNameOfDeclaration} from '../../metadata/src/reflector';
import {TypeCheckContext} from '../../typecheck';
import {AnalysisOutput, CompileResult, DecoratorHandler} from './api';
import {DtsFileTransformer} from './declaration';
/**
* Record of an adapter which decided to emit a static field, and the analysis it performed to
* prepare for that operation.
@ -38,6 +40,7 @@ export class IvyCompilation {
* information recorded about them for later compilation.
*/
private analysis = new Map<ts.Declaration, EmitFieldOperation<any, any>>();
private typeCheckMap = new Map<ts.Declaration, DecoratorHandler<any, any>>();
/**
* Tracks factory information which needs to be generated.
@ -107,6 +110,9 @@ export class IvyCompilation {
analysis: analysis.analysis,
metadata: metadata,
});
if (!!analysis.typeCheck) {
this.typeCheckMap.set(node, adapter);
}
}
if (analysis.diagnostics !== undefined) {
@ -156,6 +162,14 @@ export class IvyCompilation {
}
}
typeCheck(context: TypeCheckContext): void {
this.typeCheckMap.forEach((handler, node) => {
if (handler.typeCheck !== undefined) {
handler.typeCheck(context, node, this.analysis.get(node) !.analysis);
}
});
}
/**
* Perform a compilation operation on the given class declaration and return instructions to an
* AST transformer if any are available.