fix(compiler): emit correct type-check-blocks with TemplateRef's (#20463)

The type-check block generated with `"fullTemplateTypeCheck"` was
invalid if the it contained a template ref as would be generated
using the `else` micro-syntax of `NgIf`.

Fixes: #19485

PR Close #20463
This commit is contained in:
Chuck Jazdzewski
2017-11-15 13:20:51 -08:00
committed by Miško Hevery
parent 3df1542c87
commit 81f1d42328
2 changed files with 35 additions and 1 deletions

View File

@ -206,11 +206,16 @@ export class AotCompiler {
// and they also cause TypeScript to include these files into the program too,
// which will make them part of the analyzedFiles.
const externalReferences: StaticSymbol[] = [
// Add references that are available from all the modules and imports.
...ngModuleMeta.transitiveModule.directives.map(d => d.reference),
...ngModuleMeta.transitiveModule.pipes.map(d => d.reference),
...ngModuleMeta.importedModules.map(m => m.type.reference),
...ngModuleMeta.exportedModules.map(m => m.type.reference),
// Add references that might be inserted by the template compiler.
...this._externalIdentifierReferences([Identifiers.TemplateRef, Identifiers.ElementRef]),
];
const externalReferenceVars = new Map<any, string>();
externalReferences.forEach((ref, typeIndex) => {
if (this._host.isSourceFile(ref.filePath)) {
@ -248,6 +253,17 @@ export class AotCompiler {
}
}
private _externalIdentifierReferences(references: o.ExternalReference[]): StaticSymbol[] {
const result: StaticSymbol[] = [];
for (let reference of references) {
const token = createTokenForExternalReference(this._reflector, reference);
if (token.identifier) {
result.push(token.identifier.reference);
}
}
return result;
}
private _createTypeCheckBlock(
ctx: OutputContext, componentId: string, moduleMeta: CompileNgModuleMetadata,
compMeta: CompileDirectiveMetadata, directives: CompileIdentifierMetadata[],