fix(ivy): auto register NgModules with ID (#33663)

PR Close #33663
This commit is contained in:
Andrew Scott 2019-11-07 11:45:01 -08:00 committed by Kara Erickson
parent fcde671ae2
commit a972e4cd4d
2 changed files with 10 additions and 1 deletions

View File

@ -6,7 +6,9 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {Type} from '../interface/type'; import {Type} from '../interface/type';
import {autoRegisterModuleById} from '../render3/definition';
import {NgModuleType} from '../render3/ng_module_ref'; import {NgModuleType} from '../render3/ng_module_ref';
import {stringify} from '../util/stringify'; import {stringify} from '../util/stringify';
@ -68,5 +70,5 @@ export function restoreRegisteredModulesState(moduleMap: ModuleRegistrationMap)
} }
export function getRegisteredNgModuleType(id: string) { export function getRegisteredNgModuleType(id: string) {
return modules.get(id); return modules.get(id) || autoRegisterModuleById[id];
} }

View File

@ -22,6 +22,7 @@ import {TConstants} from './interfaces/node';
// while SelectorFlags is unused here, it's required so that types don't get resolved lazily // while SelectorFlags is unused here, it's required so that types don't get resolved lazily
// see: https://github.com/Microsoft/web-build-tools/issues/1050 // see: https://github.com/Microsoft/web-build-tools/issues/1050
import {CssSelectorList, SelectorFlags} from './interfaces/projection'; import {CssSelectorList, SelectorFlags} from './interfaces/projection';
import {NgModuleType} from './ng_module_ref';
let _renderCompCount = 0; let _renderCompCount = 0;
@ -338,6 +339,8 @@ export function extractPipeDef(type: Type<any>): PipeDef<any> {
return def !; return def !;
} }
export const autoRegisterModuleById: {[id: string]: NgModuleType} = {};
/** /**
* @codeGenApi * @codeGenApi
*/ */
@ -376,6 +379,10 @@ export function ɵɵdefineNgModule<T>(def: {
schemas: def.schemas || null, schemas: def.schemas || null,
id: def.id || null, id: def.id || null,
}; };
if (def.id != null) {
noSideEffects(
() => { autoRegisterModuleById[def.id !] = def.type as unknown as NgModuleType; });
}
return res as never; return res as never;
} }