feat(core): allow to add precompiled tokens via a provider
Introduces the new `ANALYZE_FOR_PRECOMPILE` token. This token can be used to create a virtual provider that will populate the `precompile` fields of components and app modules based on its `useValue`. All components that are referenced in the `useValue` value (either directly or in a nested array or map) will be added to the `precompile` property. closes #9874 related to #9726
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
*/
|
||||
import './init';
|
||||
import {NestedModule, NestedService, ParentComp, SomeComp, SomeModule, SomeService} from '../src/module_fixtures';
|
||||
import {SomeModuleNgFactory, SomeModuleUsingParentCompNgFactory} from '../src/module_fixtures.ngfactory';
|
||||
import {SomeModuleNgFactory, SomeModuleUsingParentCompNgFactory, SomeModuleWithAnalyzePrecompileProviderNgFactory} from '../src/module_fixtures.ngfactory';
|
||||
import {createComponent, createModule} from './util';
|
||||
|
||||
describe('AppModule', () => {
|
||||
@ -26,6 +26,15 @@ describe('AppModule', () => {
|
||||
expect(compRef.instance instanceof SomeComp).toBe(true);
|
||||
});
|
||||
|
||||
it('should support precompile via the ANALYZE_FOR_PRECOMPILE provider and function providers in components',
|
||||
() => {
|
||||
const moduleRef = createModule(SomeModuleWithAnalyzePrecompileProviderNgFactory);
|
||||
const cf = moduleRef.componentFactoryResolver.resolveComponentFactory(SomeComp);
|
||||
expect(cf.componentType).toBe(SomeComp);
|
||||
// check that the function call that created the provider for ANALYZE_FOR_PRECOMPILE worked.
|
||||
expect(moduleRef.instance.providedValue).toEqual([{a: 'b', component: SomeComp}]);
|
||||
});
|
||||
|
||||
it('should support module directives and pipes', () => {
|
||||
var compFixture = createComponent(SomeComp, SomeModuleNgFactory);
|
||||
var debugElement = compFixture.debugElement;
|
||||
|
Reference in New Issue
Block a user