From 785da0f1bfa163b232009b4c9123b26b545a09dc Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 9 Jun 2021 09:42:23 -0700 Subject: [PATCH] =?UTF-8?q?fix(core):=20ensure=20that=20autoRegisterModule?= =?UTF-8?q?ById=20registration=20in=20=C9=B5=C9=B5defineNgModule=20is=20no?= =?UTF-8?q?t=20DCE-ed=20by=20closure=20(#42529)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the autoRegisterModuleById registration was marked with noSideEffects wrapper to ensure that we don't end up retaining all NgModules. However the return value was not referenced by anything, so closure compiler removed it because it determined that this code has no side effects and is not referenced by anyone. This issue affects apps that use Closure Compiler and also rely on https://angular.io/api/core/getModuleFactory to retrieve factories by ID. This combination is used heavily in google3, especially in Pantheon. Fixes b/188453434 PR Close #42529 --- packages/core/src/render3/definition.ts | 30 ++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/core/src/render3/definition.ts b/packages/core/src/render3/definition.ts index 865b8aa5b3e..626c0dd6bba 100644 --- a/packages/core/src/render3/definition.ts +++ b/packages/core/src/render3/definition.ts @@ -410,22 +410,22 @@ export function ɵɵdefineNgModule(def: { /** Unique ID for the module that is used with `getModuleFactory`. */ id?: string | null; }): unknown { - const res: NgModuleDef = { - type: def.type, - bootstrap: def.bootstrap || EMPTY_ARRAY, - declarations: def.declarations || EMPTY_ARRAY, - imports: def.imports || EMPTY_ARRAY, - exports: def.exports || EMPTY_ARRAY, - transitiveCompileScopes: null, - schemas: def.schemas || null, - id: def.id || null, - }; - if (def.id != null) { - noSideEffects(() => { + return noSideEffects(() => { + const res: NgModuleDef = { + type: def.type, + bootstrap: def.bootstrap || EMPTY_ARRAY, + declarations: def.declarations || EMPTY_ARRAY, + imports: def.imports || EMPTY_ARRAY, + exports: def.exports || EMPTY_ARRAY, + transitiveCompileScopes: null, + schemas: def.schemas || null, + id: def.id || null, + }; + if (def.id != null) { autoRegisterModuleById[def.id!] = def.type as unknown as NgModuleType; - }); - } - return res; + } + return res; + }); } /**