fix(ivy): align NgModule registration timing with ViewEngine (#30244)

Currently in Ivy `NgModule` registration happens when the class is declared, however this is inconsistent with ViewEngine and requires extra generated code. These changes remove the generated code for `registerModuleFactory`, pass the id through to the `ngModuleDef` and do the module registration inside `NgModuleFactory.create`.

This PR resolves FW-1285.

PR Close #30244
This commit is contained in:
Kristiyan Kostadinov
2019-05-07 22:57:55 -04:00
committed by Alex Rickabaugh
parent 2f35dbfd3b
commit f74373f2dd
18 changed files with 115 additions and 73 deletions

View File

@ -17,7 +17,7 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
import {modifiedInIvy, obsoleteInIvy, onlyInIvy} from '@angular/private/testing';
import {InternalNgModuleRef, NgModuleFactory} from '../../src/linker/ng_module_factory';
import {clearModulesForTest} from '../../src/linker/ng_module_factory_loader';
import {clearModulesForTest} from '../../src/linker/ng_module_factory_registration';
import {stringify} from '../../src/util/stringify';
class Engine {}
@ -327,6 +327,18 @@ function declareTests(config?: {useJit: boolean}) {
createModule(SomeOtherModule);
}).toThrowError(/Duplicate module registered/);
});
it('should not throw immediately if two modules have the same id', () => {
expect(() => {
@NgModule({id: 'some-module'})
class ModuleA {
}
@NgModule({id: 'some-module'})
class ModuleB {
}
}).not.toThrow();
});
});
describe('entryComponents', () => {