Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 000c834

Browse files
dgp1130matsko
authored andcommitted
fix(core): remove side effects from ɵɵgetInheritedFactory() (#35769) (#35846)
`ɵɵ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 (cherry picked from commit c195d22) PR Close #35846
1 parent d24ce21 commit 000c834

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

integration/_payload-limits.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"uncompressed": {
6161
"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",
6262
"bundle": "TODO(i): we should define ngDevMode to false in Closure, but --define only works in the global scope.",
63-
"bundle": 175498
63+
"bundle": 170618
6464
}
6565
}
6666
}

packages/core/src/render3/di.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {getInjectorDef} from '../di/interface/defs';
1414
import {InjectFlags} from '../di/interface/injector';
1515
import {Type} from '../interface/type';
1616
import {assertDefined, assertEqual} from '../util/assert';
17+
import {noSideEffects} from '../util/closure';
1718

1819
import {assertDirectiveDef} from './assert';
1920
import {getFactoryDef} from './definition';
@@ -655,15 +656,17 @@ export function ɵɵgetFactoryOf<T>(type: Type<any>): FactoryFn<T>|null {
655656
* @codeGenApi
656657
*/
657658
export function ɵɵgetInheritedFactory<T>(type: Type<any>): (type: Type<T>) => T {
658-
const proto = Object.getPrototypeOf(type.prototype).constructor as Type<any>;
659-
const factory = (proto as any)[NG_FACTORY_DEF] || ɵɵgetFactoryOf<T>(proto);
660-
if (factory !== null) {
661-
return factory;
662-
} else {
663-
// There is no factory defined. Either this was improper usage of inheritance
664-
// (no Angular decorator on the superclass) or there is no constructor at all
665-
// in the inheritance chain. Since the two cases cannot be distinguished, the
666-
// latter has to be assumed.
667-
return (t) => new t();
668-
}
659+
return noSideEffects(() => {
660+
const proto = Object.getPrototypeOf(type.prototype).constructor as Type<any>;
661+
const factory = (proto as any)[NG_FACTORY_DEF] || ɵɵgetFactoryOf<T>(proto);
662+
if (factory !== null) {
663+
return factory;
664+
} else {
665+
// There is no factory defined. Either this was improper usage of inheritance
666+
// (no Angular decorator on the superclass) or there is no constructor at all
667+
// in the inheritance chain. Since the two cases cannot be distinguished, the
668+
// latter has to be assumed.
669+
return (t) => new t();
670+
}
671+
});
669672
}

packages/core/test/bundling/cyclic_import/bundle.golden_symbols.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@
167167
{
168168
"name": "attachPatchData"
169169
},
170+
{
171+
"name": "autoRegisterModuleById"
172+
},
170173
{
171174
"name": "baseResolveDirective"
172175
},

0 commit comments

Comments
 (0)