fix(ivy): correct timing of NgModuleFactory registration (#30706)

Commit 0df719a46 introduced registration of NgModules with ids when compiled
with AOT, and f74373f2d corrected the timing to avoid issues with tree
shaking. Neither of these approaches were correct.

This commit fixes the timing to match View Engine and avoid tree shaking
issues, as well as fixes a bug with the registration of imported module ids.

A new Ivy-only test is added which verifies that modules get registered
correctly under real-world conditions.

PR Close #30706
This commit is contained in:
Alex Rickabaugh
2019-05-28 15:20:53 -07:00
committed by Matias Niemelä
parent 7a0f8ac36c
commit b4644d7bb0
3 changed files with 70 additions and 12 deletions

View File

@ -37,10 +37,21 @@ function assertSameOrNotExisting(id: string, type: Type<any>| null, incoming: Ty
}
}
export function registerNgModuleType(id: string, ngModuleType: NgModuleType) {
const existing = modules.get(id) as NgModuleType | null;
assertSameOrNotExisting(id, existing, ngModuleType);
modules.set(id, ngModuleType);
export function registerNgModuleType(ngModuleType: NgModuleType) {
if (ngModuleType.ngModuleDef.id !== null) {
const id = ngModuleType.ngModuleDef.id;
const existing = modules.get(id) as NgModuleType | null;
assertSameOrNotExisting(id, existing, ngModuleType);
modules.set(id, ngModuleType);
}
let imports = ngModuleType.ngModuleDef.imports;
if (imports instanceof Function) {
imports = imports();
}
if (imports) {
imports.forEach((i: NgModuleType<any>) => registerNgModuleType(i));
}
}
export function clearModulesForTest(): void {