fix(core): remove side effects from `ɵɵgetInheritedFactory()` (#35769)

`ɵɵgetInheritedFactory()` is called from generated code for a component which extends another class. This function is detected by Closure to have a side effect and is not able to tree shake the component as a result. Marking it with `noSideEffects()` tells Closure it can remove this function under the relevant tree shaking conditions.

PR Close #35769
This commit is contained in:
Doug Parker 2020-02-21 16:20:16 -08:00 committed by atscott
parent 9cf85d2177
commit c195d22f68
3 changed files with 18 additions and 12 deletions

View File

@ -60,7 +60,7 @@
"uncompressed": {
"bundle": "TODO(i): temporarily increase the payload size limit from 105779 - this is due to a closure issue related to ESM reexports that still needs to be investigated",
"bundle": "TODO(i): we should define ngDevMode to false in Closure, but --define only works in the global scope.",
"bundle": 175498
"bundle": 170618
}
}
}

View File

@ -14,6 +14,7 @@ import {getInjectorDef} from '../di/interface/defs';
import {InjectFlags} from '../di/interface/injector';
import {Type} from '../interface/type';
import {assertDefined, assertEqual} from '../util/assert';
import {noSideEffects} from '../util/closure';
import {assertDirectiveDef} from './assert';
import {getFactoryDef} from './definition';
@ -655,15 +656,17 @@ export function ɵɵgetFactoryOf<T>(type: Type<any>): FactoryFn<T>|null {
* @codeGenApi
*/
export function ɵɵgetInheritedFactory<T>(type: Type<any>): (type: Type<T>) => T {
const proto = Object.getPrototypeOf(type.prototype).constructor as Type<any>;
const factory = (proto as any)[NG_FACTORY_DEF] || ɵɵgetFactoryOf<T>(proto);
if (factory !== null) {
return factory;
} else {
// There is no factory defined. Either this was improper usage of inheritance
// (no Angular decorator on the superclass) or there is no constructor at all
// in the inheritance chain. Since the two cases cannot be distinguished, the
// latter has to be assumed.
return (t) => new t();
}
return noSideEffects(() => {
const proto = Object.getPrototypeOf(type.prototype).constructor as Type<any>;
const factory = (proto as any)[NG_FACTORY_DEF] || ɵɵgetFactoryOf<T>(proto);
if (factory !== null) {
return factory;
} else {
// There is no factory defined. Either this was improper usage of inheritance
// (no Angular decorator on the superclass) or there is no constructor at all
// in the inheritance chain. Since the two cases cannot be distinguished, the
// latter has to be assumed.
return (t) => new t();
}
});
}

View File

@ -167,6 +167,9 @@
{
"name": "attachPatchData"
},
{
"name": "autoRegisterModuleById"
},
{
"name": "baseResolveDirective"
},