feat(ivy): support pipe compilation from local metadata (#24703)

This updates the r3_pipe_compiler to not depend on global analysis,
and to produce ngPipeDef instructions in the same way that the other
compilers do. It's a precursor to JIT and AOT implementations of
@Pipe compilation.

PR Close #24703
This commit is contained in:
Alex Rickabaugh
2018-06-26 10:43:06 -07:00
committed by Miško Hevery
parent ffbacdf4ac
commit dbdcfed2bd
11 changed files with 78 additions and 43 deletions

View File

@ -16,7 +16,7 @@ import {Type} from '../type';
import {resolveRendererType2} from '../view/util';
import {diPublic} from './di';
import {ComponentDefFeature, ComponentDefInternal, ComponentQuery, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDef, PipeType, PipeTypesOrFactory} from './interfaces/definition';
import {ComponentDefFeature, ComponentDefInternal, ComponentQuery, ComponentTemplate, ComponentType, DirectiveDefFeature, DirectiveDefInternal, DirectiveDefListOrFactory, DirectiveType, DirectiveTypesOrFactory, PipeDefInternal, PipeType, PipeTypesOrFactory} from './interfaces/definition';
import {CssSelectorList, SelectorFlags} from './interfaces/projection';
@ -255,7 +255,7 @@ export function extractDirectiveDef(type: DirectiveType<any>& ComponentType<any>
return def;
}
export function extractPipeDef(type: PipeType<any>): PipeDef<any> {
export function extractPipeDef(type: PipeType<any>): PipeDefInternal<any> {
const def = type.ngPipeDef;
if (ngDevMode && !def) {
throw new Error(`'${type.name}' is not a 'PipeType'.`);
@ -483,7 +483,7 @@ export function definePipe<T>(pipeDef: {
/** Whether the pipe is pure. */
pure?: boolean
}): never {
return (<PipeDef<T>>{
return (<PipeDefInternal<T>>{
name: pipeDef.name,
factory: pipeDef.factory,
pure: pipeDef.pure !== false,

View File

@ -226,13 +226,13 @@ export interface ComponentDef<T, Selector extends string> extends DirectiveDef<T
*
* See: {@link definePipe}
*/
export interface PipeDef<T> {
export interface PipeDef<T, S extends string> {
/**
* Pipe name.
*
* Used to resolve pipe in templates.
*/
name: string;
name: S;
/**
* Factory function used to create a new pipe instance.
@ -251,6 +251,8 @@ export interface PipeDef<T> {
onDestroy: (() => void)|null;
}
export type PipeDefInternal<T> = PipeDef<T, string>;
export type DirectiveDefFeature = <T>(directiveDef: DirectiveDef<T, string>) => void;
export type ComponentDefFeature = <T>(componentDef: ComponentDef<T, string>) => void;
@ -276,12 +278,13 @@ export type DirectiveTypeList =
*/
export type PipeDefListOrFactory = (() => PipeDefList) | PipeDefList;
export type PipeDefList = PipeDef<any>[];
export type PipeDefList = PipeDefInternal<any>[];
export type PipeTypesOrFactory = (() => DirectiveTypeList) | DirectiveTypeList;
export type PipeTypeList =
(PipeDef<any>| Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
(PipeDefInternal<any>|
Type<any>/* Type as workaround for: Microsoft/TypeScript/issues/4881 */)[];
// Note: This hack is necessary so we don't erroneously get a circular dependency

View File

@ -10,7 +10,7 @@ import {Injector} from '../../di/injector';
import {Sanitizer} from '../../sanitization/security';
import {LContainer} from './container';
import {ComponentQuery, ComponentTemplate, DirectiveDefInternal, DirectiveDefList, PipeDef, PipeDefList} from './definition';
import {ComponentQuery, ComponentTemplate, DirectiveDefInternal, DirectiveDefList, PipeDefInternal, PipeDefList} from './definition';
import {LContainerNode, LElementNode, LViewNode, TNode} from './node';
import {LQueries} from './query';
import {Renderer3} from './renderer';
@ -456,7 +456,7 @@ export type HookData = (number | (() => void))[];
* as its pipe instance in the data array. Any nodes that do not have static
* data store a null value in tData to avoid a sparse array.
*/
export type TData = (TNode | PipeDef<any>| null)[];
export type TData = (TNode | PipeDefInternal<any>| null)[];
/** Type for TView.currentMatches */
export type CurrentMatchesList = [DirectiveDefInternal<any>, (string | number | null)];

View File

@ -9,7 +9,7 @@
import {PipeTransform} from '../change_detection/pipe_transform';
import {getTView, load, store} from './instructions';
import {PipeDef, PipeDefList} from './interfaces/definition';
import {PipeDefInternal, PipeDefList} from './interfaces/definition';
import {HEADER_OFFSET} from './interfaces/view';
import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunctionV} from './pure_function';
@ -22,7 +22,7 @@ import {pureFunction1, pureFunction2, pureFunction3, pureFunction4, pureFunction
*/
export function pipe(index: number, pipeName: string): any {
const tView = getTView();
let pipeDef: PipeDef<any>;
let pipeDef: PipeDefInternal<any>;
const adjustedIndex = index + HEADER_OFFSET;
if (tView.firstTemplatePass) {
@ -33,7 +33,7 @@ export function pipe(index: number, pipeName: string): any {
])).push(adjustedIndex, pipeDef.onDestroy);
}
} else {
pipeDef = tView.data[adjustedIndex] as PipeDef<any>;
pipeDef = tView.data[adjustedIndex] as PipeDefInternal<any>;
}
const pipeInstance = pipeDef.factory();
@ -49,7 +49,7 @@ export function pipe(index: number, pipeName: string): any {
* @param registry Full list of available pipes
* @returns Matching PipeDef
*/
function getPipeDef(name: string, registry: PipeDefList | null): PipeDef<any> {
function getPipeDef(name: string, registry: PipeDefList | null): PipeDefInternal<any> {
if (registry) {
for (let i = 0; i < registry.length; i++) {
const pipeDef = registry[i];
@ -151,5 +151,5 @@ export function pipeBindV(index: number, slotOffset: number, values: any[]): any
}
function isPure(index: number): boolean {
return (<PipeDef<any>>getTView().data[index + HEADER_OFFSET]).pure;
return (<PipeDefInternal<any>>getTView().data[index + HEADER_OFFSET]).pure;
}