feat(ivy): register NgModules with ids when compiled with AOT (#29980)

This commit adds registration of AOT compiled NgModules that have 'id'
properties set in their metadata. Such modules have a call to
registerNgModuleType() emitted as part of compilation.

The JIT behavior of this code is already in place.

This is required for module loading systems (such as g3) which rely on
getModuleFactory().

PR Close #29980
This commit is contained in:
Alex Rickabaugh
2019-04-18 16:22:53 -07:00
committed by Ben Lesh
parent 4229b41057
commit 0df719a461
5 changed files with 46 additions and 3 deletions

View File

@ -484,6 +484,21 @@ describe('ngtsc behavioral tests', () => {
expect(jsContents).not.toContain('\u0275\u0275setNgModuleScope(TestModule,');
});
it('should emit a \u0275registerNgModuleType call when the module has an id', () => {
env.tsconfig();
env.write('test.ts', `
import {NgModule} from '@angular/core';
@NgModule({id: 'test'})
export class TestModule {}
`);
env.driveMain();
const jsContents = env.getContents('test.js');
expect(jsContents).toContain('i0.\u0275registerNgModuleType("test", TestModule);');
});
it('should filter out directives and pipes from module exports in the injector def', () => {
env.tsconfig();
env.write('test.ts', `