| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  | import {WrappedValue} from '../change_detection/change_detection_util'; | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  | import {PipeTransform} from '../change_detection/pipe_transform'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  | import {getFactoryDef} from './definition'; | 
					
						
							| 
									
										
										
										
											2019-08-12 08:11:32 +03:00
										 |  |  | import {store} from './instructions/all'; | 
					
						
							| 
									
										
										
										
											2018-09-21 12:12:06 -07:00
										 |  |  | import {PipeDef, PipeDefList} from './interfaces/definition'; | 
					
						
							| 
									
										
										
										
											2019-01-10 16:10:11 +01:00
										 |  |  | import {BINDING_INDEX, HEADER_OFFSET, TVIEW} from './interfaces/view'; | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  | import {ɵɵpureFunction1, ɵɵpureFunction2, ɵɵpureFunction3, ɵɵpureFunction4, ɵɵpureFunctionV} from './pure_function'; | 
					
						
							| 
									
										
										
										
											2019-01-10 16:10:11 +01:00
										 |  |  | import {getLView} from './state'; | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  | import {NO_CHANGE} from './tokens'; | 
					
						
							| 
									
										
										
										
											2019-08-12 08:11:32 +03:00
										 |  |  | import {load} from './util/view_utils'; | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Create a pipe. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param index Pipe index where the pipe will be stored. | 
					
						
							| 
									
										
										
										
											2018-03-30 16:07:37 -07:00
										 |  |  |  * @param pipeName The name of the pipe | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |  * @returns T the instance of the pipe. | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-10 13:45:26 -07:00
										 |  |  |  * @codeGenApi | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  | export function ɵɵpipe(index: number, pipeName: string): any { | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |   const tView = getLView()[TVIEW]; | 
					
						
							| 
									
										
										
										
											2018-09-21 12:12:06 -07:00
										 |  |  |   let pipeDef: PipeDef<any>; | 
					
						
							| 
									
										
										
										
											2018-06-07 22:42:32 -07:00
										 |  |  |   const adjustedIndex = index + HEADER_OFFSET; | 
					
						
							| 
									
										
										
										
											2018-03-27 15:53:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |   if (tView.firstTemplatePass) { | 
					
						
							| 
									
										
										
										
											2018-03-27 15:53:48 -07:00
										 |  |  |     pipeDef = getPipeDef(pipeName, tView.pipeRegistry); | 
					
						
							| 
									
										
										
										
											2018-06-07 22:42:32 -07:00
										 |  |  |     tView.data[adjustedIndex] = pipeDef; | 
					
						
							| 
									
										
										
										
											2018-03-21 15:10:34 -07:00
										 |  |  |     if (pipeDef.onDestroy) { | 
					
						
							| 
									
										
										
										
											2019-01-07 10:38:55 +01:00
										 |  |  |       (tView.destroyHooks || (tView.destroyHooks = [])).push(adjustedIndex, pipeDef.onDestroy); | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-03-27 15:53:48 -07:00
										 |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2018-09-21 12:12:06 -07:00
										 |  |  |     pipeDef = tView.data[adjustedIndex] as PipeDef<any>; | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-03-27 15:53:48 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 09:26:20 +03:00
										 |  |  |   const pipeFactory = pipeDef.factory || (pipeDef.factory = getFactoryDef(pipeDef.type, true)); | 
					
						
							|  |  |  |   const pipeInstance = pipeFactory(); | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  |   store(index, pipeInstance); | 
					
						
							|  |  |  |   return pipeInstance; | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-27 15:53:48 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Searches the pipe registry for a pipe with the given name. If one is found, | 
					
						
							|  |  |  |  * returns the pipe. Otherwise, an error is thrown because the pipe cannot be resolved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param name Name of pipe to resolve | 
					
						
							|  |  |  |  * @param registry Full list of available pipes | 
					
						
							| 
									
										
										
										
											2018-04-13 23:02:29 -07:00
										 |  |  |  * @returns Matching PipeDef | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @publicApi | 
					
						
							| 
									
										
										
										
											2018-03-27 15:53:48 -07:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-09-21 12:12:06 -07:00
										 |  |  | function getPipeDef(name: string, registry: PipeDefList | null): PipeDef<any> { | 
					
						
							| 
									
										
										
										
											2018-03-27 15:53:48 -07:00
										 |  |  |   if (registry) { | 
					
						
							| 
									
										
										
										
											2019-01-03 15:55:01 +01:00
										 |  |  |     for (let i = registry.length - 1; i >= 0; i--) { | 
					
						
							| 
									
										
										
										
											2018-03-27 15:53:48 -07:00
										 |  |  |       const pipeDef = registry[i]; | 
					
						
							|  |  |  |       if (name === pipeDef.name) { | 
					
						
							|  |  |  |         return pipeDef; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-12-11 10:43:02 -08:00
										 |  |  |   throw new Error(`The pipe '${name}' could not be found!`); | 
					
						
							| 
									
										
										
										
											2018-03-27 15:53:48 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-05 13:28:38 -08:00
										 |  |  |  * Invokes a pipe with 1 arguments. | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This instruction acts as a guard to {@link PipeTransform#transform} invoking | 
					
						
							|  |  |  |  * the pipe only when an input to the pipe changes. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param index Pipe index where the pipe was stored on creation. | 
					
						
							| 
									
										
										
										
											2018-08-21 18:52:26 -07:00
										 |  |  |  * @param slotOffset the offset in the reserved slot space | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * @param v1 1st argument to {@link PipeTransform#transform}. | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-10 13:45:26 -07:00
										 |  |  |  * @codeGenApi | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  | export function ɵɵpipeBind1(index: number, slotOffset: number, v1: any): any { | 
					
						
							| 
									
										
										
										
											2019-08-12 08:11:32 +03:00
										 |  |  |   const pipeInstance = load<PipeTransform>(getLView(), index); | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |   return unwrapValue( | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       isPure(index) ? ɵɵpureFunction1(slotOffset, pipeInstance.transform, v1, pipeInstance) : | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |                       pipeInstance.transform(v1)); | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-05 13:28:38 -08:00
										 |  |  |  * Invokes a pipe with 2 arguments. | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This instruction acts as a guard to {@link PipeTransform#transform} invoking | 
					
						
							|  |  |  |  * the pipe only when an input to the pipe changes. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param index Pipe index where the pipe was stored on creation. | 
					
						
							| 
									
										
										
										
											2018-08-21 18:52:26 -07:00
										 |  |  |  * @param slotOffset the offset in the reserved slot space | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * @param v1 1st argument to {@link PipeTransform#transform}. | 
					
						
							|  |  |  |  * @param v2 2nd argument to {@link PipeTransform#transform}. | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-10 13:45:26 -07:00
										 |  |  |  * @codeGenApi | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  | export function ɵɵpipeBind2(index: number, slotOffset: number, v1: any, v2: any): any { | 
					
						
							| 
									
										
										
										
											2019-08-12 08:11:32 +03:00
										 |  |  |   const pipeInstance = load<PipeTransform>(getLView(), index); | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |   return unwrapValue( | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       isPure(index) ? ɵɵpureFunction2(slotOffset, pipeInstance.transform, v1, v2, pipeInstance) : | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |                       pipeInstance.transform(v1, v2)); | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-05 13:28:38 -08:00
										 |  |  |  * Invokes a pipe with 3 arguments. | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This instruction acts as a guard to {@link PipeTransform#transform} invoking | 
					
						
							|  |  |  |  * the pipe only when an input to the pipe changes. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param index Pipe index where the pipe was stored on creation. | 
					
						
							| 
									
										
										
										
											2018-08-21 18:52:26 -07:00
										 |  |  |  * @param slotOffset the offset in the reserved slot space | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * @param v1 1st argument to {@link PipeTransform#transform}. | 
					
						
							|  |  |  |  * @param v2 2nd argument to {@link PipeTransform#transform}. | 
					
						
							|  |  |  |  * @param v3 4rd argument to {@link PipeTransform#transform}. | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-10 13:45:26 -07:00
										 |  |  |  * @codeGenApi | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  | export function ɵɵpipeBind3(index: number, slotOffset: number, v1: any, v2: any, v3: any): any { | 
					
						
							| 
									
										
										
										
											2019-08-12 08:11:32 +03:00
										 |  |  |   const pipeInstance = load<PipeTransform>(getLView(), index); | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |   return unwrapValue( | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       isPure(index) ? | 
					
						
							|  |  |  |           ɵɵpureFunction3(slotOffset, pipeInstance.transform, v1, v2, v3, pipeInstance) : | 
					
						
							|  |  |  |           pipeInstance.transform(v1, v2, v3)); | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-05 13:28:38 -08:00
										 |  |  |  * Invokes a pipe with 4 arguments. | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This instruction acts as a guard to {@link PipeTransform#transform} invoking | 
					
						
							|  |  |  |  * the pipe only when an input to the pipe changes. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param index Pipe index where the pipe was stored on creation. | 
					
						
							| 
									
										
										
										
											2018-08-21 18:52:26 -07:00
										 |  |  |  * @param slotOffset the offset in the reserved slot space | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * @param v1 1st argument to {@link PipeTransform#transform}. | 
					
						
							|  |  |  |  * @param v2 2nd argument to {@link PipeTransform#transform}. | 
					
						
							|  |  |  |  * @param v3 3rd argument to {@link PipeTransform#transform}. | 
					
						
							|  |  |  |  * @param v4 4th argument to {@link PipeTransform#transform}. | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-10 13:45:26 -07:00
										 |  |  |  * @codeGenApi | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  | export function ɵɵpipeBind4( | 
					
						
							| 
									
										
										
										
											2018-05-21 15:59:25 -07:00
										 |  |  |     index: number, slotOffset: number, v1: any, v2: any, v3: any, v4: any): any { | 
					
						
							| 
									
										
										
										
											2019-08-12 08:11:32 +03:00
										 |  |  |   const pipeInstance = load<PipeTransform>(getLView(), index); | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |   return unwrapValue( | 
					
						
							|  |  |  |       isPure(index) ? | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |           ɵɵpureFunction4(slotOffset, pipeInstance.transform, v1, v2, v3, v4, pipeInstance) : | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |           pipeInstance.transform(v1, v2, v3, v4)); | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2018-02-05 13:28:38 -08:00
										 |  |  |  * Invokes a pipe with variable number of arguments. | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This instruction acts as a guard to {@link PipeTransform#transform} invoking | 
					
						
							|  |  |  |  * the pipe only when an input to the pipe changes. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param index Pipe index where the pipe was stored on creation. | 
					
						
							| 
									
										
										
										
											2018-08-21 18:52:26 -07:00
										 |  |  |  * @param slotOffset the offset in the reserved slot space | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  * @param values Array of arguments to pass to {@link PipeTransform#transform} method. | 
					
						
							| 
									
										
										
										
											2019-04-04 11:41:52 -07:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-04-10 13:45:26 -07:00
										 |  |  |  * @codeGenApi | 
					
						
							| 
									
										
										
										
											2018-01-27 13:07:03 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-06-14 09:27:41 +02:00
										 |  |  | export function ɵɵpipeBindV(index: number, slotOffset: number, values: [any, ...any[]]): any { | 
					
						
							| 
									
										
										
										
											2019-08-12 08:11:32 +03:00
										 |  |  |   const pipeInstance = load<PipeTransform>(getLView(), index); | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |   return unwrapValue( | 
					
						
							| 
									
										
										
										
											2019-05-17 18:49:21 -07:00
										 |  |  |       isPure(index) ? ɵɵpureFunctionV(slotOffset, pipeInstance.transform, values, pipeInstance) : | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |                       pipeInstance.transform.apply(pipeInstance, values)); | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function isPure(index: number): boolean { | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |   return (<PipeDef<any>>getLView()[TVIEW].data[index + HEADER_OFFSET]).pure; | 
					
						
							| 
									
										
										
										
											2018-02-16 16:23:27 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Unwrap the output of a pipe transformation. | 
					
						
							|  |  |  |  * In order to trick change detection into considering that the new value is always different from | 
					
						
							|  |  |  |  * the old one, the old value is overwritten by NO_CHANGE. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @param newValue the pipe transformation output. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | function unwrapValue(newValue: any): any { | 
					
						
							|  |  |  |   if (WrappedValue.isWrapped(newValue)) { | 
					
						
							|  |  |  |     newValue = WrappedValue.unwrap(newValue); | 
					
						
							| 
									
										
										
										
											2019-01-10 16:10:11 +01:00
										 |  |  |     const lView = getLView(); | 
					
						
							|  |  |  |     // The NO_CHANGE value needs to be written at the index where the impacted binding value is
 | 
					
						
							|  |  |  |     // stored
 | 
					
						
							|  |  |  |     const bindingToInvalidateIdx = lView[BINDING_INDEX]; | 
					
						
							|  |  |  |     lView[bindingToInvalidateIdx] = NO_CHANGE; | 
					
						
							| 
									
										
										
										
											2018-12-03 11:40:07 +01:00
										 |  |  |   } | 
					
						
							|  |  |  |   return newValue; | 
					
						
							|  |  |  | } |