fix(ivy): correct timing of NgModuleFactory registration (#30706)
Commit0df719a46
introduced registration of NgModules with ids when compiled with AOT, andf74373f2d
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:

committed by
Matias Niemelä

parent
7a0f8ac36c
commit
b4644d7bb0
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, ChangeDetectorRef, Compiler, Component, ComponentFactoryResolver, Directive, HostBinding, Inject, Injectable, InjectionToken, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, Provider, Self, Type, forwardRef, getModuleFactory, ɵivyEnabled as ivyEnabled} from '@angular/core';
|
||||
import {ANALYZE_FOR_ENTRY_COMPONENTS, CUSTOM_ELEMENTS_SCHEMA, ChangeDetectorRef, Compiler, Component, ComponentFactoryResolver, Directive, HostBinding, Inject, Injectable, InjectionToken, Injector, Input, NgModule, NgModuleRef, Optional, Pipe, Provider, Self, Type, forwardRef, getModuleFactory, ɵivyEnabled as ivyEnabled, ɵɵdefineNgModule as defineNgModule} from '@angular/core';
|
||||
import {Console} from '@angular/core/src/console';
|
||||
import {ɵɵInjectableDef, ɵɵdefineInjectable} from '@angular/core/src/di/interface/defs';
|
||||
import {getNgModuleDef} from '@angular/core/src/render3/definition';
|
||||
@ -339,6 +339,28 @@ function declareTests(config?: {useJit: boolean}) {
|
||||
}
|
||||
}).not.toThrow();
|
||||
});
|
||||
|
||||
onlyInIvy('VE does not allow use of NgModuleFactory without importing the .ngfactory')
|
||||
.it('should register a module even if not importing the .ngfactory file or calling create()',
|
||||
() => {
|
||||
class ChildModule {
|
||||
static ngModuleDef = defineNgModule({
|
||||
type: ChildModule,
|
||||
id: 'child',
|
||||
});
|
||||
}
|
||||
|
||||
class Module {
|
||||
static ngModuleDef = defineNgModule({
|
||||
type: Module,
|
||||
id: 'test',
|
||||
imports: [ChildModule],
|
||||
});
|
||||
}
|
||||
|
||||
createModuleFactory(ChildModule);
|
||||
expect(getModuleFactory('child')).toBeAnInstanceOf(NgModuleFactory);
|
||||
});
|
||||
});
|
||||
|
||||
describe('entryComponents', () => {
|
||||
|
Reference in New Issue
Block a user