fix(ivy): componentFactories not populated in ModuleWithComponentFactories (#28112)
Fixes the `ModuleWithComponentFactories.componentFactories` not being populated when calling `compileModuleAndAllComponentsSync` in Ivy. These changes resolve FW-929. PR Close #28112
This commit is contained in:
parent
da1d19b40f
commit
bac71ef419
|
@ -12,6 +12,8 @@ import {StaticProvider} from '../di/interface/provider';
|
||||||
import {MissingTranslationStrategy} from '../i18n/tokens';
|
import {MissingTranslationStrategy} from '../i18n/tokens';
|
||||||
import {Type} from '../interface/type';
|
import {Type} from '../interface/type';
|
||||||
import {ViewEncapsulation} from '../metadata';
|
import {ViewEncapsulation} from '../metadata';
|
||||||
|
import {ComponentFactory as ComponentFactoryR3} from '../render3/component_ref';
|
||||||
|
import {getComponentDef, getNgModuleDef} from '../render3/definition';
|
||||||
import {NgModuleFactory as NgModuleFactoryR3} from '../render3/ng_module_ref';
|
import {NgModuleFactory as NgModuleFactoryR3} from '../render3/ng_module_ref';
|
||||||
|
|
||||||
import {ComponentFactory} from './component_factory';
|
import {ComponentFactory} from './component_factory';
|
||||||
|
@ -56,7 +58,14 @@ const Compiler_compileModuleAndAllComponentsSync__PRE_R3__: <T>(moduleType: Type
|
||||||
export const Compiler_compileModuleAndAllComponentsSync__POST_R3__: <T>(moduleType: Type<T>) =>
|
export const Compiler_compileModuleAndAllComponentsSync__POST_R3__: <T>(moduleType: Type<T>) =>
|
||||||
ModuleWithComponentFactories<T> = function<T>(moduleType: Type<T>):
|
ModuleWithComponentFactories<T> = function<T>(moduleType: Type<T>):
|
||||||
ModuleWithComponentFactories<T> {
|
ModuleWithComponentFactories<T> {
|
||||||
return new ModuleWithComponentFactories(Compiler_compileModuleSync__POST_R3__(moduleType), []);
|
const ngModuleFactory = Compiler_compileModuleSync__POST_R3__(moduleType);
|
||||||
|
const moduleDef = getNgModuleDef(moduleType) !;
|
||||||
|
const componentFactories = moduleDef.declarations.reduce((factories, declaration) => {
|
||||||
|
const componentDef = getComponentDef(declaration);
|
||||||
|
componentDef && factories.push(new ComponentFactoryR3(componentDef));
|
||||||
|
return factories;
|
||||||
|
}, [] as ComponentFactory<any>[]);
|
||||||
|
return new ModuleWithComponentFactories(ngModuleFactory, componentFactories);
|
||||||
};
|
};
|
||||||
const Compiler_compileModuleAndAllComponentsSync =
|
const Compiler_compileModuleAndAllComponentsSync =
|
||||||
Compiler_compileModuleAndAllComponentsSync__PRE_R3__;
|
Compiler_compileModuleAndAllComponentsSync__PRE_R3__;
|
||||||
|
|
|
@ -1097,8 +1097,7 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
.toHaveText('dynamic greet');
|
.toHaveText('dynamic greet');
|
||||||
}));
|
}));
|
||||||
|
|
||||||
fixmeIvy('FW-929: ModuleWithComponentFactories.componentFactories is never filled in')
|
it('should create a component that has been freshly compiled', () => {
|
||||||
.it('should create a component that has been freshly compiled', () => {
|
|
||||||
@Component({template: ''})
|
@Component({template: ''})
|
||||||
class RootComp {
|
class RootComp {
|
||||||
constructor(public vc: ViewContainerRef) {}
|
constructor(public vc: ViewContainerRef) {}
|
||||||
|
@ -1123,8 +1122,8 @@ function declareTests(config?: {useJit: boolean}) {
|
||||||
class MyModule {
|
class MyModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
const compFixture = TestBed.configureTestingModule({imports: [RootModule]})
|
const compFixture =
|
||||||
.createComponent(RootComp);
|
TestBed.configureTestingModule({imports: [RootModule]}).createComponent(RootComp);
|
||||||
const compiler = <Compiler>TestBed.get(Compiler);
|
const compiler = <Compiler>TestBed.get(Compiler);
|
||||||
const myCompFactory =
|
const myCompFactory =
|
||||||
<ComponentFactory<MyComp>>compiler.compileModuleAndAllComponentsSync(MyModule)
|
<ComponentFactory<MyComp>>compiler.compileModuleAndAllComponentsSync(MyModule)
|
||||||
|
|
|
@ -700,6 +700,17 @@ export class TestBedRender3 implements Injector, TestBed {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
_getComponentFactories(moduleType: NgModuleType): ComponentFactory<any>[] {
|
||||||
|
return moduleType.ngModuleDef.declarations.reduce((factories, declaration) => {
|
||||||
|
const componentDef = (declaration as any).ngComponentDef;
|
||||||
|
componentDef && factories.push(new ComponentFactory(componentDef, this._moduleRef));
|
||||||
|
return factories;
|
||||||
|
}, [] as ComponentFactory<any>[]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the module scoping queue should be flushed, and flush it if needed.
|
* Check whether the module scoping queue should be flushed, and flush it if needed.
|
||||||
*
|
*
|
||||||
|
@ -757,7 +768,9 @@ class R3TestCompiler implements Compiler {
|
||||||
}
|
}
|
||||||
|
|
||||||
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
|
compileModuleAndAllComponentsSync<T>(moduleType: Type<T>): ModuleWithComponentFactories<T> {
|
||||||
return new ModuleWithComponentFactories(this.compileModuleSync(moduleType), []);
|
const ngModuleFactory = this.compileModuleSync(moduleType);
|
||||||
|
const componentFactories = this.testBed._getComponentFactories(moduleType as NgModuleType<T>);
|
||||||
|
return new ModuleWithComponentFactories(ngModuleFactory, componentFactories);
|
||||||
}
|
}
|
||||||
|
|
||||||
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
|
compileModuleAndAllComponentsAsync<T>(moduleType: Type<T>):
|
||||||
|
|
Loading…
Reference in New Issue