Skip to content

Commit

Permalink
fix(core): ensure that autoRegisterModuleById registration in ɵɵdefin…
Browse files Browse the repository at this point in the history
…eNgModule is not DCE-ed by closure (#42529)

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
  • Loading branch information
IgorMinar authored and alxhub committed Jun 9, 2021
1 parent e36c5b4 commit 3961b3c
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions packages/core/src/render3/definition.ts
Expand Up @@ -410,22 +410,22 @@ export function ɵɵdefineNgModule<T>(def: {
/** Unique ID for the module that is used with `getModuleFactory`. */
id?: string | null;
}): unknown {
const res: NgModuleDef<T> = {
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<T> = {
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;
});
}

/**
Expand Down

0 comments on commit 3961b3c

Please sign in to comment.