Factory defs are not considered public API, so the property
that contains them should be prefixed with Angular's marker
for "private" ('ɵ') to discourage apps from relying on def
APIs directly.
This commit adds the prefix and shortens the name from
ngFactoryDef to fac. This is because property names
cannot be minified by Uglify without turning on property
mangling (which most apps have turned off) and are thus
size-sensitive.
Note that the other "defs" (ngPipeDef, etc) will be
prefixed and shortened in follow-up PRs, in an attempt to
limit how large and conflict-y this change is.
PR Close #33116
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
/**
|
|
* @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
|
|
*/
|
|
|
|
import {R3PipeMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
|
|
import {reflectDependencies} from '../../di/jit/util';
|
|
import {Type} from '../../interface/type';
|
|
import {Pipe} from '../../metadata/directives';
|
|
import {NG_FACTORY_DEF, NG_PIPE_DEF} from '../fields';
|
|
|
|
import {angularCoreEnv} from './environment';
|
|
|
|
export function compilePipe(type: Type<any>, meta: Pipe): void {
|
|
let ngPipeDef: any = null;
|
|
let ngFactoryDef: any = null;
|
|
|
|
Object.defineProperty(type, NG_FACTORY_DEF, {
|
|
get: () => {
|
|
if (ngFactoryDef === null) {
|
|
const metadata = getPipeMetadata(type, meta);
|
|
ngFactoryDef = getCompilerFacade().compileFactory(
|
|
angularCoreEnv, `ng:///${metadata.name}/ɵfac.js`,
|
|
{...metadata, injectFn: 'directiveInject', isPipe: true});
|
|
}
|
|
return ngFactoryDef;
|
|
},
|
|
// Make the property configurable in dev mode to allow overriding in tests
|
|
configurable: !!ngDevMode,
|
|
});
|
|
|
|
Object.defineProperty(type, NG_PIPE_DEF, {
|
|
get: () => {
|
|
if (ngPipeDef === null) {
|
|
const metadata = getPipeMetadata(type, meta);
|
|
ngPipeDef = getCompilerFacade().compilePipe(
|
|
angularCoreEnv, `ng:///${metadata.name}/ngPipeDef.js`, metadata);
|
|
}
|
|
return ngPipeDef;
|
|
},
|
|
// Make the property configurable in dev mode to allow overriding in tests
|
|
configurable: !!ngDevMode,
|
|
});
|
|
}
|
|
|
|
function getPipeMetadata(type: Type<any>, meta: Pipe): R3PipeMetadataFacade {
|
|
return {
|
|
type: type,
|
|
typeArgumentCount: 0,
|
|
name: type.name,
|
|
deps: reflectDependencies(type),
|
|
pipeName: meta.name,
|
|
pure: meta.pure !== undefined ? meta.pure : true
|
|
};
|
|
}
|