refactor(core): rename ngFactoryDef to ɵfac (#33116)
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
This commit is contained in:

committed by
Miško Hevery

parent
c3aaa5211e
commit
0de2a5e408
@ -48,8 +48,8 @@ export function compileInjectable(type: Type<any>, srcMeta?: Injectable): void {
|
||||
get: () => {
|
||||
if (ngFactoryDef === null) {
|
||||
const metadata = getInjectableMetadata(type, srcMeta);
|
||||
ngFactoryDef = getCompilerFacade().compileFactory(
|
||||
angularCoreDiEnv, `ng:///${type.name}/ngFactoryDef.js`, {
|
||||
ngFactoryDef =
|
||||
getCompilerFacade().compileFactory(angularCoreDiEnv, `ng:///${type.name}/ɵfac.js`, {
|
||||
name: metadata.name,
|
||||
type: metadata.type,
|
||||
typeArgumentCount: metadata.typeArgumentCount,
|
||||
|
@ -760,7 +760,7 @@ export function getFactoryDef<T>(type: any): FactoryFn<T>|null;
|
||||
export function getFactoryDef<T>(type: any, throwNotFound?: boolean): FactoryFn<T>|null {
|
||||
const hasFactoryDef = type.hasOwnProperty(NG_FACTORY_DEF);
|
||||
if (!hasFactoryDef && throwNotFound === true && ngDevMode) {
|
||||
throw new Error(`Type ${stringify(type)} does not have 'ngFactoryDef' property.`);
|
||||
throw new Error(`Type ${stringify(type)} does not have 'ɵfac' property.`);
|
||||
}
|
||||
return hasFactoryDef ? type[NG_FACTORY_DEF] : null;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ export const NG_PIPE_DEF = getClosureSafeProperty({ngPipeDef: getClosureSafeProp
|
||||
export const NG_MODULE_DEF = getClosureSafeProperty({ngModuleDef: getClosureSafeProperty});
|
||||
export const NG_LOCALE_ID_DEF = getClosureSafeProperty({ngLocaleIdDef: getClosureSafeProperty});
|
||||
export const NG_BASE_DEF = getClosureSafeProperty({ngBaseDef: getClosureSafeProperty});
|
||||
export const NG_FACTORY_DEF = getClosureSafeProperty({ngFactoryDef: getClosureSafeProperty});
|
||||
export const NG_FACTORY_DEF = getClosureSafeProperty({ɵfac: getClosureSafeProperty});
|
||||
|
||||
/**
|
||||
* If a directive is diPublic, bloomAdd sets a property on the type with this constant as
|
||||
|
@ -80,7 +80,7 @@ export interface ComponentType<T> extends Type<T> { ɵcmp: never; }
|
||||
*/
|
||||
export interface DirectiveType<T> extends Type<T> {
|
||||
ɵdir: never;
|
||||
ngFactoryDef: () => T;
|
||||
ɵfac: () => T;
|
||||
}
|
||||
|
||||
export enum DirectiveDefFlags {
|
||||
|
@ -166,7 +166,7 @@ function addDirectiveFactoryDef(type: Type<any>, metadata: Directive | Component
|
||||
if (ngFactoryDef === null) {
|
||||
const meta = getDirectiveMetadata(type, metadata);
|
||||
ngFactoryDef = getCompilerFacade().compileFactory(
|
||||
angularCoreEnv, `ng:///${type.name}/ngFactoryDef.js`,
|
||||
angularCoreEnv, `ng:///${type.name}/ɵfac.js`,
|
||||
{...meta.metadata, injectFn: 'directiveInject', isPipe: false});
|
||||
}
|
||||
return ngFactoryDef;
|
||||
|
@ -23,7 +23,7 @@ export function compilePipe(type: Type<any>, meta: Pipe): void {
|
||||
if (ngFactoryDef === null) {
|
||||
const metadata = getPipeMetadata(type, meta);
|
||||
ngFactoryDef = getCompilerFacade().compileFactory(
|
||||
angularCoreEnv, `ng:///${metadata.name}/ngFactoryDef.js`,
|
||||
angularCoreEnv, `ng:///${metadata.name}/ɵfac.js`,
|
||||
{...metadata, injectFn: 'directiveInject', isPipe: true});
|
||||
}
|
||||
return ngFactoryDef;
|
||||
|
Reference in New Issue
Block a user