refactor(ivy): move directive, component and pipe factories to ngFactoryFn (#31953)

Reworks the compiler to output the factories for directives, components and pipes under a new static field called `ngFactoryFn`, instead of the usual `factory` property in their respective defs. This should eventually allow us to inject any kind of decorated class (e.g. a pipe).

**Note:** these changes are the first part of the refactor and they don't include injectables. I decided to leave injectables for a follow-up PR, because there's some more cases we need to handle when it comes to their factories. Furthermore, directives, components and pipes make up most of the compiler output tests that need to be refactored and it'll make follow-up PRs easier to review if the tests are cleaned up now.

This is part of the larger refactor for FW-1468.

PR Close #31953
This commit is contained in:
Kristiyan Kostadinov
2019-08-12 09:26:20 +03:00
committed by atscott
parent 14feb56139
commit c885178d5f
71 changed files with 894 additions and 675 deletions

View File

@ -76,7 +76,10 @@ export interface ComponentType<T> extends Type<T> { ngComponentDef: never; }
* A subclass of `Type` which has a static `ngDirectiveDef`:`DirectiveDef` field making it
* consumable for rendering.
*/
export interface DirectiveType<T> extends Type<T> { ngDirectiveDef: never; }
export interface DirectiveType<T> extends Type<T> {
ngDirectiveDef: never;
ngFactoryDef: () => T;
}
export const enum DirectiveDefFlags {ContentQuery = 0b10}
@ -175,9 +178,10 @@ export interface DirectiveDef<T> extends ɵɵBaseDef<T> {
readonly exportAs: string[]|null;
/**
* Factory function used to create a new directive instance.
* Factory function used to create a new directive instance. Will be null initially.
* Populated when the factory is first requested by directive instantiation logic.
*/
factory: FactoryFn<T>;
factory: FactoryFn<T>|null;
/* The following are lifecycle hooks for this component */
onChanges: (() => void)|null;
@ -207,6 +211,11 @@ export type ɵɵComponentDefWithMeta<
T, Selector extends String, ExportAs extends string[], InputMap extends{[key: string]: string},
OutputMap extends{[key: string]: string}, QueryFields extends string[]> = ComponentDef<T>;
/**
* @codeGenApi
*/
export type ɵɵFactoryDef<T> = () => T;
/**
* Runtime link information for Components.
*
@ -329,6 +338,9 @@ export interface ComponentDef<T> extends DirectiveDef<T> {
* See: {@link definePipe}
*/
export interface PipeDef<T> {
/** Token representing the pipe. */
type: Type<T>;
/**
* Pipe name.
*
@ -337,9 +349,10 @@ export interface PipeDef<T> {
readonly name: string;
/**
* Factory function used to create a new pipe instance.
* Factory function used to create a new pipe instance. Will be null initially.
* Populated when the factory is first requested by pipe instantiation logic.
*/
factory: FactoryFn<T>;
factory: FactoryFn<T>|null;
/**
* Whether or not the pipe is pure.