refactor(core): rename ngInjectorDef to ɵinj (#33151)
Injector 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 ngInjectorDef to inj. 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. PR Close #33151
This commit is contained in:

committed by
Matias Niemelä

parent
3e14c2d02c
commit
cda9248b33
@ -104,7 +104,7 @@ export interface InjectorType<T> extends Type<T> {
|
||||
/**
|
||||
* Opaque type whose structure is highly version dependent. Do not rely on any properties.
|
||||
*/
|
||||
ngInjectorDef: never;
|
||||
ɵinj: never;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,7 +159,7 @@ export const defineInjectable = ɵɵdefineInjectable;
|
||||
/**
|
||||
* Construct an `InjectorDef` which configures an injector.
|
||||
*
|
||||
* This should be assigned to a static `ngInjectorDef` field on a type, which will then be an
|
||||
* This should be assigned to a static injector def (`ɵinj`) field on a type, which will then be an
|
||||
* `InjectorType`.
|
||||
*
|
||||
* Options:
|
||||
@ -223,13 +223,13 @@ export function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDef<T>|nu
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the `ngInjectorDef` type in a way which is immune to accidentally reading inherited value.
|
||||
* Read the injector def type in a way which is immune to accidentally reading inherited value.
|
||||
*
|
||||
* @param type type which may have `ngInjectorDef`
|
||||
* @param type type which may have an injector def (`ɵinj`)
|
||||
*/
|
||||
export function getInjectorDef<T>(type: any): ɵɵInjectorDef<T>|null {
|
||||
return type && type.hasOwnProperty(NG_INJECTOR_DEF) ? (type as any)[NG_INJECTOR_DEF] : null;
|
||||
return type && type.hasOwnProperty(NG_INJ_DEF) ? (type as any)[NG_INJ_DEF] : null;
|
||||
}
|
||||
|
||||
export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty});
|
||||
export const NG_INJECTOR_DEF = getClosureSafeProperty({ngInjectorDef: getClosureSafeProperty});
|
||||
export const NG_INJ_DEF = getClosureSafeProperty({ɵinj: getClosureSafeProperty});
|
||||
|
@ -251,11 +251,11 @@ export class R3Injector {
|
||||
defOrWrappedDef = resolveForwardRef(defOrWrappedDef);
|
||||
if (!defOrWrappedDef) return false;
|
||||
|
||||
// Either the defOrWrappedDef is an InjectorType (with ngInjectorDef) or an
|
||||
// Either the defOrWrappedDef is an InjectorType (with injector def) or an
|
||||
// InjectorDefTypeWithProviders (aka ModuleWithProviders). Detecting either is a megamorphic
|
||||
// read, so care is taken to only do the read once.
|
||||
|
||||
// First attempt to read the ngInjectorDef.
|
||||
// First attempt to read the injector def (`ɵinj`).
|
||||
let def = getInjectorDef(defOrWrappedDef);
|
||||
|
||||
// If that's not present, then attempt to read ngModule from the InjectorDefTypeWithProviders.
|
||||
@ -416,7 +416,8 @@ function injectableDefOrInjectorDefFactory(token: Type<any>| InjectionToken<any>
|
||||
return factory;
|
||||
}
|
||||
|
||||
// If the token is an NgModule, it's also injectable but the factory is on its ngInjectorDef.
|
||||
// If the token is an NgModule, it's also injectable but the factory is on its injector def
|
||||
// (`ɵinj`)
|
||||
const injectorDef = getInjectorDef(token);
|
||||
if (injectorDef !== null) {
|
||||
return injectorDef.factory;
|
||||
|
Reference in New Issue
Block a user