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

View File

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