fix(ivy): ensure pipe declarations are populated lazily when a forward ref is detected (#26765)

PR Close #26765
This commit is contained in:
Matias Niemelä
2018-10-25 11:13:14 -07:00
parent 2fd4c372d5
commit 8171a2ab94
5 changed files with 97 additions and 19 deletions

View File

@ -159,11 +159,11 @@ export interface R3ComponentMetadata extends R3DirectiveMetadata {
directives: Map<string, o.Expression>;
/**
* Whether to wrap the 'directives' array, if one is generated, in a closure.
* Whether to wrap the 'directives' and/or `pipes` array, if one is generated, in a closure.
*
* This is done when the directives contain forward references.
* This is done when the directives or pipes contain forward references.
*/
wrapDirectivesInClosure: boolean;
wrapDirectivesAndPipesInClosure: boolean;
/**
* A collection of styling data that will be applied and scoped to the component.

View File

@ -239,7 +239,7 @@ export function compileComponentFromMetadata(
// e.g. `directives: [MyDirective]`
if (directivesUsed.size) {
let directivesExpr: o.Expression = o.literalArr(Array.from(directivesUsed));
if (meta.wrapDirectivesInClosure) {
if (meta.wrapDirectivesAndPipesInClosure) {
directivesExpr = o.fn([], [new o.ReturnStatement(directivesExpr)]);
}
definitionMap.set('directives', directivesExpr);
@ -247,7 +247,11 @@ export function compileComponentFromMetadata(
// e.g. `pipes: [MyPipe]`
if (pipesUsed.size) {
definitionMap.set('pipes', o.literalArr(Array.from(pipesUsed)));
let pipesExpr: o.Expression = o.literalArr(Array.from(pipesUsed));
if (meta.wrapDirectivesAndPipesInClosure) {
pipesExpr = o.fn([], [new o.ReturnStatement(pipesExpr)]);
}
definitionMap.set('pipes', pipesExpr);
}
// e.g. `styles: [str1, str2]`
@ -331,7 +335,7 @@ export function compileComponentFromRender2(
directives: typeMapToExpressionMap(directiveTypeBySel, outputCtx),
pipes: typeMapToExpressionMap(pipeTypeByName, outputCtx),
viewQueries: queriesFromGlobalMetadata(component.viewQueries, outputCtx),
wrapDirectivesInClosure: false,
wrapDirectivesAndPipesInClosure: false,
styles: (summary.template && summary.template.styles) || EMPTY_ARRAY,
encapsulation:
(summary.template && summary.template.encapsulation) || core.ViewEncapsulation.Emulated,