fix(ivy): ngUpgrade should distinguish element and module injectors (#28313)
There are cases where we should check an element injector but don't go into the associated module injector if a token is not found. In both the view engine and ngIvy this is acheived by passing the `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR` as the `notFoundValue`. Before this fix the view engine and ngIvy were using different objects to represent `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR`. This was causing problems as ngUpgrade is using `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR` const in its `NgAdapterInjector` to prevent searching of module injectors. This commit makes sure that ngIvy is using the same object to represent `NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR` as the view engine. PR Close #28313
This commit is contained in:
parent
22a43cff4d
commit
32c61f434c
|
@ -19,6 +19,7 @@ import {RendererFactory2} from '../render/api';
|
||||||
import {Sanitizer} from '../sanitization/security';
|
import {Sanitizer} from '../sanitization/security';
|
||||||
import {assertDefined} from '../util/assert';
|
import {assertDefined} from '../util/assert';
|
||||||
import {VERSION} from '../version';
|
import {VERSION} from '../version';
|
||||||
|
import {NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR} from '../view/provider';
|
||||||
|
|
||||||
import {assertComponentType} from './assert';
|
import {assertComponentType} from './assert';
|
||||||
import {LifecycleHooksFeature, createRootComponent, createRootComponentView, createRootContext} from './component';
|
import {LifecycleHooksFeature, createRootComponent, createRootComponentView, createRootContext} from './component';
|
||||||
|
@ -74,8 +75,6 @@ export const SCHEDULER = new InjectionToken<((fn: () => void) => void)>('SCHEDUL
|
||||||
factory: () => defaultScheduler,
|
factory: () => defaultScheduler,
|
||||||
});
|
});
|
||||||
|
|
||||||
const NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR = {};
|
|
||||||
|
|
||||||
function createChainedInjector(rootViewInjector: Injector, moduleInjector: Injector): Injector {
|
function createChainedInjector(rootViewInjector: Injector, moduleInjector: Injector): Injector {
|
||||||
return {
|
return {
|
||||||
get: <T>(token: Type<T>| InjectionToken<T>, notFoundValue?: T): T => {
|
get: <T>(token: Type<T>| InjectionToken<T>, notFoundValue?: T): T => {
|
||||||
|
|
|
@ -736,9 +736,7 @@ withEachNg1Version(() => {
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
fixmeIvy(
|
it('should work with ng2 lazy loaded components', async(() => {
|
||||||
'FW-717: Injector on lazy loaded components are not the same as their NgModule\'s injector')
|
|
||||||
.it('should work with ng2 lazy loaded components', async(() => {
|
|
||||||
let componentInjector: Injector;
|
let componentInjector: Injector;
|
||||||
|
|
||||||
@Component({selector: 'ng2', template: ''})
|
@Component({selector: 'ng2', template: ''})
|
||||||
|
@ -778,8 +776,8 @@ withEachNg1Version(() => {
|
||||||
const compiler = modInjector.get(Compiler);
|
const compiler = modInjector.get(Compiler);
|
||||||
const modFactory = compiler.compileModuleSync(LazyLoadedModule);
|
const modFactory = compiler.compileModuleSync(LazyLoadedModule);
|
||||||
const childMod = modFactory.create(modInjector);
|
const childMod = modFactory.create(modInjector);
|
||||||
const cmpFactory = childMod.componentFactoryResolver.resolveComponentFactory(
|
const cmpFactory =
|
||||||
LazyLoadedComponent) !;
|
childMod.componentFactoryResolver.resolveComponentFactory(LazyLoadedComponent) !;
|
||||||
const lazyCmp = cmpFactory.create(componentInjector);
|
const lazyCmp = cmpFactory.create(componentInjector);
|
||||||
|
|
||||||
expect(lazyCmp.instance.module.injector === childMod.injector).toBe(true);
|
expect(lazyCmp.instance.module.injector === childMod.injector).toBe(true);
|
||||||
|
|
|
@ -416,8 +416,7 @@ withEachNg1Version(() => {
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
fixmeIvy('FW-873: projected component injector hierarchy not wired up correctly')
|
it('should correctly traverse the injector tree of downgraded components (from different modules)',
|
||||||
.it('should correctly traverse the injector tree of downgraded components (from different modules)',
|
|
||||||
async(() => {
|
async(() => {
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ng2A',
|
selector: 'ng2A',
|
||||||
|
@ -532,8 +531,7 @@ withEachNg1Version(() => {
|
||||||
// Standalone component B.
|
// Standalone component B.
|
||||||
$rootScope.$apply('showB2 = true');
|
$rootScope.$apply('showB2 = true');
|
||||||
expect(multiTrim(element.children[1].textContent))
|
expect(multiTrim(element.children[1].textContent))
|
||||||
.toBe(
|
.toBe('FOO:CompB-foo BAR:ModB-bar BAZ:ModB-baz QUX:Plat-qux QUUX:Plat-quux');
|
||||||
'FOO:CompB-foo BAR:ModB-bar BAZ:ModB-baz QUX:Plat-qux QUUX:Plat-quux');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Reference in New Issue