refactor(core): remove NG_PROV_DEF_FALLBACK needed for IE10 only (#39090)
This commit removes a workaround previously used for IE 9 and 10 to identify whether InjectableDef was defined on a given class instance. Since support for IE 9 and 10 is removed, this fallback is no longer needed. PR Close #39090
This commit is contained in:
parent
61e6ca9b1f
commit
db37c17e02
|
@ -195,23 +195,15 @@ export function ɵɵdefineInjector(options: {factory: () => any, providers?: any
|
||||||
* @param type A type which may have its own (non-inherited) `ɵprov`.
|
* @param type A type which may have its own (non-inherited) `ɵprov`.
|
||||||
*/
|
*/
|
||||||
export function getInjectableDef<T>(type: any): ɵɵInjectableDef<T>|null {
|
export function getInjectableDef<T>(type: any): ɵɵInjectableDef<T>|null {
|
||||||
return getOwnDefinition(type, type[NG_PROV_DEF]) ||
|
return getOwnDefinition(type, NG_PROV_DEF) || getOwnDefinition(type, NG_INJECTABLE_DEF);
|
||||||
getOwnDefinition(type, type[NG_INJECTABLE_DEF]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return `def` only if it is defined directly on `type` and is not inherited from a base
|
* Return definition only if it is defined directly on `type` and is not inherited from a base
|
||||||
* class of `type`.
|
* class of `type`.
|
||||||
*
|
|
||||||
* The function `Object.hasOwnProperty` is not sufficient to distinguish this case because in older
|
|
||||||
* browsers (e.g. IE10) static property inheritance is implemented by copying the properties.
|
|
||||||
*
|
|
||||||
* Instead, the definition's `token` is compared to the `type`, and if they don't match then the
|
|
||||||
* property was not defined directly on the type itself, and was likely inherited. The definition
|
|
||||||
* is only returned if the `type` matches the `def.token`.
|
|
||||||
*/
|
*/
|
||||||
function getOwnDefinition<T>(type: any, def: ɵɵInjectableDef<T>): ɵɵInjectableDef<T>|null {
|
function getOwnDefinition<T>(type: any, field: string): ɵɵInjectableDef<T>|null {
|
||||||
return def && def.token === type ? def : null;
|
return type.hasOwnProperty(field) ? type[field] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,10 +215,7 @@ function getOwnDefinition<T>(type: any, def: ɵɵInjectableDef<T>): ɵɵInjectab
|
||||||
* scenario if we find the `ɵprov` on an ancestor only.
|
* scenario if we find the `ɵprov` on an ancestor only.
|
||||||
*/
|
*/
|
||||||
export function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDef<T>|null {
|
export function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDef<T>|null {
|
||||||
// See `jit/injectable.ts#compileInjectable` for context on NG_PROV_DEF_FALLBACK.
|
const def = type && (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF]);
|
||||||
const def = type &&
|
|
||||||
(type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF] ||
|
|
||||||
(type[NG_PROV_DEF_FALLBACK] && type[NG_PROV_DEF_FALLBACK]()));
|
|
||||||
|
|
||||||
if (def) {
|
if (def) {
|
||||||
const typeName = getTypeName(type);
|
const typeName = getTypeName(type);
|
||||||
|
@ -273,14 +262,6 @@ export function getInjectorDef<T>(type: any): ɵɵInjectorDef<T>|null {
|
||||||
export const NG_PROV_DEF = getClosureSafeProperty({ɵprov: getClosureSafeProperty});
|
export const NG_PROV_DEF = getClosureSafeProperty({ɵprov: getClosureSafeProperty});
|
||||||
export const NG_INJ_DEF = getClosureSafeProperty({ɵinj: getClosureSafeProperty});
|
export const NG_INJ_DEF = getClosureSafeProperty({ɵinj: getClosureSafeProperty});
|
||||||
|
|
||||||
// On IE10 properties defined via `defineProperty` won't be inherited by child classes,
|
|
||||||
// which will break inheriting the injectable definition from a grandparent through an
|
|
||||||
// undecorated parent class. We work around it by defining a fallback method which will be
|
|
||||||
// used to retrieve the definition. This should only be a problem in JIT mode, because in
|
|
||||||
// AOT TypeScript seems to have a workaround for static properties. When inheriting from an
|
|
||||||
// undecorated parent is no longer supported in v10, this can safely be removed.
|
|
||||||
export const NG_PROV_DEF_FALLBACK = getClosureSafeProperty({ɵprovFallback: getClosureSafeProperty});
|
|
||||||
|
|
||||||
// We need to keep these around so we can read off old defs if new defs are unavailable
|
// We need to keep these around so we can read off old defs if new defs are unavailable
|
||||||
export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty});
|
export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty});
|
||||||
export const NG_INJECTOR_DEF = getClosureSafeProperty({ngInjectorDef: getClosureSafeProperty});
|
export const NG_INJECTOR_DEF = getClosureSafeProperty({ngInjectorDef: getClosureSafeProperty});
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {NG_FACTORY_DEF} from '../../render3/fields';
|
||||||
import {getClosureSafeProperty} from '../../util/property';
|
import {getClosureSafeProperty} from '../../util/property';
|
||||||
import {resolveForwardRef} from '../forward_ref';
|
import {resolveForwardRef} from '../forward_ref';
|
||||||
import {Injectable} from '../injectable';
|
import {Injectable} from '../injectable';
|
||||||
import {NG_PROV_DEF, NG_PROV_DEF_FALLBACK} from '../interface/defs';
|
import {NG_PROV_DEF} from '../interface/defs';
|
||||||
import {ClassSansProvider, ExistingSansProvider, FactorySansProvider, ValueProvider, ValueSansProvider} from '../interface/provider';
|
import {ClassSansProvider, ExistingSansProvider, FactorySansProvider, ValueProvider, ValueSansProvider} from '../interface/provider';
|
||||||
|
|
||||||
import {angularCoreDiEnv} from './environment';
|
import {angularCoreDiEnv} from './environment';
|
||||||
|
@ -40,16 +40,6 @@ export function compileInjectable(type: Type<any>, srcMeta?: Injectable): void {
|
||||||
return ngInjectableDef;
|
return ngInjectableDef;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// On IE10 properties defined via `defineProperty` won't be inherited by child classes,
|
|
||||||
// which will break inheriting the injectable definition from a grandparent through an
|
|
||||||
// undecorated parent class. We work around it by defining a method which should be used
|
|
||||||
// as a fallback. This should only be a problem in JIT mode, because in AOT TypeScript
|
|
||||||
// seems to have a workaround for static properties. When inheriting from an undecorated
|
|
||||||
// parent is no longer supported (v11 or later), this can safely be removed.
|
|
||||||
if (!type.hasOwnProperty(NG_PROV_DEF_FALLBACK)) {
|
|
||||||
(type as any)[NG_PROV_DEF_FALLBACK] = () => (type as any)[NG_PROV_DEF];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if NG_FACTORY_DEF is already defined on this class then don't overwrite it
|
// if NG_FACTORY_DEF is already defined on this class then don't overwrite it
|
||||||
|
|
|
@ -356,9 +356,6 @@
|
||||||
{
|
{
|
||||||
"name": "NG_PROV_DEF"
|
"name": "NG_PROV_DEF"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "NG_PROV_DEF_FALLBACK"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "NG_VALIDATORS"
|
"name": "NG_VALIDATORS"
|
||||||
},
|
},
|
||||||
|
|
|
@ -38,9 +38,6 @@
|
||||||
{
|
{
|
||||||
"name": "NG_PROV_DEF"
|
"name": "NG_PROV_DEF"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "NG_PROV_DEF_FALLBACK"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "NOT_YET"
|
"name": "NOT_YET"
|
||||||
},
|
},
|
||||||
|
|
|
@ -431,9 +431,6 @@
|
||||||
{
|
{
|
||||||
"name": "NG_PROV_DEF"
|
"name": "NG_PROV_DEF"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "NG_PROV_DEF_FALLBACK"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "NONE"
|
"name": "NONE"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue