2018-06-26 10:44:05 -07:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 12:08:49 -07:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2018-06-26 10:44:05 -07:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2021-06-28 23:07:41 +02:00
|
|
|
import {getCompilerFacade, JitCompilerUsage, R3PipeMetadataFacade} from '../../compiler/compiler_facade';
|
2019-01-11 16:07:01 -08:00
|
|
|
import {reflectDependencies} from '../../di/jit/util';
|
2019-01-09 13:49:16 -08:00
|
|
|
import {Type} from '../../interface/type';
|
2018-06-26 10:44:05 -07:00
|
|
|
import {Pipe} from '../../metadata/directives';
|
2019-08-12 09:26:20 +03:00
|
|
|
import {NG_FACTORY_DEF, NG_PIPE_DEF} from '../fields';
|
2018-06-26 10:44:05 -07:00
|
|
|
|
|
|
|
import {angularCoreEnv} from './environment';
|
|
|
|
|
|
|
|
export function compilePipe(type: Type<any>, meta: Pipe): void {
|
2018-08-06 14:09:38 -07:00
|
|
|
let ngPipeDef: any = null;
|
2019-08-12 09:26:20 +03:00
|
|
|
let ngFactoryDef: any = null;
|
|
|
|
|
|
|
|
Object.defineProperty(type, NG_FACTORY_DEF, {
|
|
|
|
get: () => {
|
|
|
|
if (ngFactoryDef === null) {
|
|
|
|
const metadata = getPipeMetadata(type, meta);
|
2021-06-28 23:07:41 +02:00
|
|
|
const compiler = getCompilerFacade(
|
|
|
|
{usage: JitCompilerUsage.Decorator, kind: 'pipe', type: metadata.type});
|
2021-03-23 15:14:53 +00:00
|
|
|
ngFactoryDef = compiler.compileFactory(angularCoreEnv, `ng:///${metadata.name}/ɵfac.js`, {
|
|
|
|
name: metadata.name,
|
|
|
|
type: metadata.type,
|
|
|
|
typeArgumentCount: 0,
|
|
|
|
deps: reflectDependencies(type),
|
2021-03-25 21:25:03 +00:00
|
|
|
target: compiler.FactoryTarget.Pipe
|
2021-03-23 15:14:53 +00:00
|
|
|
});
|
2019-08-12 09:26:20 +03:00
|
|
|
}
|
|
|
|
return ngFactoryDef;
|
|
|
|
},
|
|
|
|
// Make the property configurable in dev mode to allow overriding in tests
|
|
|
|
configurable: !!ngDevMode,
|
|
|
|
});
|
|
|
|
|
2018-06-26 10:44:05 -07:00
|
|
|
Object.defineProperty(type, NG_PIPE_DEF, {
|
|
|
|
get: () => {
|
2018-08-06 14:09:38 -07:00
|
|
|
if (ngPipeDef === null) {
|
2019-08-12 09:26:20 +03:00
|
|
|
const metadata = getPipeMetadata(type, meta);
|
2021-06-28 23:07:41 +02:00
|
|
|
const compiler = getCompilerFacade(
|
|
|
|
{usage: JitCompilerUsage.Decorator, kind: 'pipe', type: metadata.type});
|
|
|
|
ngPipeDef =
|
|
|
|
compiler.compilePipe(angularCoreEnv, `ng:///${metadata.name}/ɵpipe.js`, metadata);
|
2018-06-26 10:44:05 -07:00
|
|
|
}
|
2018-08-06 14:09:38 -07:00
|
|
|
return ngPipeDef;
|
|
|
|
},
|
|
|
|
// Make the property configurable in dev mode to allow overriding in tests
|
|
|
|
configurable: !!ngDevMode,
|
2018-06-26 10:44:05 -07:00
|
|
|
});
|
|
|
|
}
|
2019-08-12 09:26:20 +03:00
|
|
|
|
2019-09-01 12:26:04 +02:00
|
|
|
function getPipeMetadata(type: Type<any>, meta: Pipe): R3PipeMetadataFacade {
|
2019-08-12 09:26:20 +03:00
|
|
|
return {
|
|
|
|
type: type,
|
|
|
|
name: type.name,
|
|
|
|
pipeName: meta.name,
|
|
|
|
pure: meta.pure !== undefined ? meta.pure : true
|
|
|
|
};
|
|
|
|
}
|