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

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