fix(ivy): emit generic type arguments in Pipe metadata (#29403)

Previously, only directives and services with generic type parameters
would emit `any` as generic type when emitting Ivy metadata into .d.ts
files. Pipes can also have generic type parameters but did not emit
`any` for all type parameters, resulting in the omission of those
parameters which causes compilation errors.

This commit adds support for pipes with generic type arguments and emits
`any` as generic type in the Ivy metadata.

Fixes #29400

PR Close #29403
This commit is contained in:
JoostK
2019-03-19 21:22:03 +01:00
committed by Matias Niemelä
parent 17b3f11e07
commit 9eb8274991
7 changed files with 55 additions and 11 deletions

View File

@ -77,6 +77,7 @@ export interface R3DependencyMetadataFacade {
export interface R3PipeMetadataFacade {
name: string;
type: any;
typeArgumentCount: number;
pipeName: string;
deps: R3DependencyMetadataFacade[]|null;
pure: boolean;

View File

@ -38,6 +38,7 @@ export class CompilerFacadeImpl implements CompilerFacade {
const res = compilePipeFromMetadata({
name: facade.name,
type: new WrappedNodeExpr(facade.type),
typeArgumentCount: facade.typeArgumentCount,
deps: convertR3DependencyMetadataArray(facade.deps),
pipeName: facade.pipeName,
pure: facade.pure,

View File

@ -14,19 +14,38 @@ import {OutputContext, error} from '../util';
import {R3DependencyMetadata, compileFactoryFunction, dependenciesFromGlobalMetadata} from './r3_factory';
import {Identifiers as R3} from './r3_identifiers';
import {typeWithParameters} from './util';
export interface R3PipeMetadata {
/**
* Name of the pipe type.
*/
name: string;
type: o.Expression;
pipeName: string;
deps: R3DependencyMetadata[]|null;
pure: boolean;
}
export interface R3PipeDef {
expression: o.Expression;
type: o.Type;
statements: o.Statement[];
/**
* An expression representing a reference to the pipe itself.
*/
type: o.Expression;
/**
* Number of generic type parameters of the type itself.
*/
typeArgumentCount: number;
/**
* Name of the pipe.
*/
pipeName: string;
/**
* Dependencies of the pipe's constructor.
*/
deps: R3DependencyMetadata[]|null;
/**
* Whether the pipe is marked as pure.
*/
pure: boolean;
}
export function compilePipeFromMetadata(metadata: R3PipeMetadata) {
@ -51,7 +70,7 @@ export function compilePipeFromMetadata(metadata: R3PipeMetadata) {
const expression = o.importExpr(R3.definePipe).callFn([o.literalMap(definitionMapValues)]);
const type = new o.ExpressionType(o.importExpr(R3.PipeDefWithMeta, [
new o.ExpressionType(metadata.type),
typeWithParameters(metadata.type, metadata.typeArgumentCount),
new o.ExpressionType(new o.LiteralExpr(metadata.pipeName)),
]));
return {expression, type, statements: templateFactory.statements};
@ -73,6 +92,7 @@ export function compilePipeFromRender2(
name,
pipeName: pipe.name,
type: outputCtx.importExpr(pipe.type.reference),
typeArgumentCount: 0,
deps: dependenciesFromGlobalMetadata(pipe.type, outputCtx, reflector),
pure: pipe.pure,
};