( type: Type<any> | AbstractType<any>, )
| 916 | * @codeGenApi |
| 917 | */ |
| 918 | export function ɵɵgetInheritedFactory<T>( |
| 919 | type: Type<any> | AbstractType<any>, |
| 920 | ): (type: Type<T>) => T { |
| 921 | return noSideEffects(() => { |
| 922 | const ownConstructor = type.prototype.constructor; |
| 923 | const ownFactory = ownConstructor[NG_FACTORY_DEF] || getFactoryOf(ownConstructor); |
| 924 | const objectPrototype = Object.prototype; |
| 925 | let parent = Object.getPrototypeOf(type.prototype).constructor; |
| 926 | |
| 927 | // Go up the prototype until we hit `Object`. |
| 928 | while (parent && parent !== objectPrototype) { |
| 929 | const factory = parent[NG_FACTORY_DEF] || getFactoryOf(parent); |
| 930 | |
| 931 | // If we hit something that has a factory and the factory isn't the same as the type, |
| 932 | // we've found the inherited factory. Note the check that the factory isn't the type's |
| 933 | // own factory is redundant in most cases, but if the user has custom decorators on the |
| 934 | // class, this lookup will start one level down in the prototype chain, causing us to |
| 935 | // find the own factory first and potentially triggering an infinite loop downstream. |
| 936 | if (factory && factory !== ownFactory) { |
| 937 | return factory; |
| 938 | } |
| 939 | |
| 940 | parent = Object.getPrototypeOf(parent); |
| 941 | } |
| 942 | |
| 943 | // There is no factory defined. Either this was improper usage of inheritance |
| 944 | // (no Angular decorator on the superclass) or there is no constructor at all |
| 945 | // in the inheritance chain. Since the two cases cannot be distinguished, the |
| 946 | // latter has to be assumed. |
| 947 | return (t: Type<T>) => new t(); |
| 948 | }); |
| 949 | } |
| 950 | |
| 951 | function getFactoryOf<T>(type: Type<any>): ((type?: Type<T>) => T | null) | null { |
| 952 | if (isForwardRef(type)) { |
no test coverage detected
searching dependent graphs…