diff --git a/packages/core/src/di/interface/defs.ts b/packages/core/src/di/interface/defs.ts index 56865380f3..c532b72f98 100644 --- a/packages/core/src/di/interface/defs.ts +++ b/packages/core/src/di/interface/defs.ts @@ -195,23 +195,15 @@ export function ɵɵdefineInjector(options: {factory: () => any, providers?: any * @param type A type which may have its own (non-inherited) `ɵprov`. */ export function getInjectableDef(type: any): ɵɵInjectableDef|null { - return getOwnDefinition(type, type[NG_PROV_DEF]) || - getOwnDefinition(type, type[NG_INJECTABLE_DEF]); + return getOwnDefinition(type, NG_PROV_DEF) || getOwnDefinition(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`. - * - * 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(type: any, def: ɵɵInjectableDef): ɵɵInjectableDef|null { - return def && def.token === type ? def : null; +function getOwnDefinition(type: any, field: string): ɵɵInjectableDef|null { + return type.hasOwnProperty(field) ? type[field] : null; } /** @@ -223,10 +215,7 @@ function getOwnDefinition(type: any, def: ɵɵInjectableDef): ɵɵInjectab * scenario if we find the `ɵprov` on an ancestor only. */ export function getInheritedInjectableDef(type: any): ɵɵInjectableDef|null { - // See `jit/injectable.ts#compileInjectable` for context on NG_PROV_DEF_FALLBACK. - const def = type && - (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF] || - (type[NG_PROV_DEF_FALLBACK] && type[NG_PROV_DEF_FALLBACK]())); + const def = type && (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF]); if (def) { const typeName = getTypeName(type); @@ -273,14 +262,6 @@ export function getInjectorDef(type: any): ɵɵInjectorDef|null { export const NG_PROV_DEF = getClosureSafeProperty({ɵprov: 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 export const NG_INJECTABLE_DEF = getClosureSafeProperty({ngInjectableDef: getClosureSafeProperty}); export const NG_INJECTOR_DEF = getClosureSafeProperty({ngInjectorDef: getClosureSafeProperty}); diff --git a/packages/core/src/di/jit/injectable.ts b/packages/core/src/di/jit/injectable.ts index 231f2090ec..702560897c 100644 --- a/packages/core/src/di/jit/injectable.ts +++ b/packages/core/src/di/jit/injectable.ts @@ -12,7 +12,7 @@ import {NG_FACTORY_DEF} from '../../render3/fields'; import {getClosureSafeProperty} from '../../util/property'; import {resolveForwardRef} from '../forward_ref'; 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 {angularCoreDiEnv} from './environment'; @@ -40,16 +40,6 @@ export function compileInjectable(type: Type, srcMeta?: Injectable): void { 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 diff --git a/packages/core/test/bundling/forms/bundle.golden_symbols.json b/packages/core/test/bundling/forms/bundle.golden_symbols.json index 2f07151f8a..0bf195a2ab 100644 --- a/packages/core/test/bundling/forms/bundle.golden_symbols.json +++ b/packages/core/test/bundling/forms/bundle.golden_symbols.json @@ -356,9 +356,6 @@ { "name": "NG_PROV_DEF" }, - { - "name": "NG_PROV_DEF_FALLBACK" - }, { "name": "NG_VALIDATORS" }, diff --git a/packages/core/test/bundling/injection/bundle.golden_symbols.json b/packages/core/test/bundling/injection/bundle.golden_symbols.json index 4e26d5b4c9..eee96403a7 100644 --- a/packages/core/test/bundling/injection/bundle.golden_symbols.json +++ b/packages/core/test/bundling/injection/bundle.golden_symbols.json @@ -38,9 +38,6 @@ { "name": "NG_PROV_DEF" }, - { - "name": "NG_PROV_DEF_FALLBACK" - }, { "name": "NOT_YET" }, diff --git a/packages/core/test/bundling/router/bundle.golden_symbols.json b/packages/core/test/bundling/router/bundle.golden_symbols.json index ca5d9b81ae..a05336e440 100644 --- a/packages/core/test/bundling/router/bundle.golden_symbols.json +++ b/packages/core/test/bundling/router/bundle.golden_symbols.json @@ -431,9 +431,6 @@ { "name": "NG_PROV_DEF" }, - { - "name": "NG_PROV_DEF_FALLBACK" - }, { "name": "NONE" },