fix(ivy): properly inject all special token types (#24862)

Previously ngtsc had a few bugs handling special token types:

* Injector was not properly translated to INJECTOR
* ChangeDetectorRef was not injected via injectChangeDetectorRef()

This commit fixes these two bugs, and also adds a test to ensure
they continue to work correctly.

PR Close #24862
This commit is contained in:
Alex Rickabaugh
2018-07-10 09:57:48 -07:00
committed by Victor Berchet
parent 53a16006d6
commit f9a6a175bf
5 changed files with 59 additions and 1 deletions

View File

@ -106,6 +106,11 @@ export enum R3ResolvedDependencyType {
* The dependency is for `ViewContainerRef`.
*/
ViewContainerRef = 5,
/**
* The dependency is for `ChangeDetectorRef`.
*/
ChangeDetectorRef = 6,
}
/**
@ -182,7 +187,7 @@ function compileInjectDependency(
}
// Build up the arguments to the injectFn call.
const injectArgs = [dep.token];
const injectArgs = [token];
// If this dependency is optional or otherwise has non-default flags, then additional
// parameters describing how to inject the dependency must be passed to the inject function
// that's being used.
@ -200,6 +205,8 @@ function compileInjectDependency(
return o.importExpr(R3.injectTemplateRef).callFn([]);
case R3ResolvedDependencyType.ViewContainerRef:
return o.importExpr(R3.injectViewContainerRef).callFn([]);
case R3ResolvedDependencyType.ChangeDetectorRef:
return o.importExpr(R3.injectChangeDetectorRef).callFn([]);
default:
return unsupported(
`Unknown R3ResolvedDependencyType: ${R3ResolvedDependencyType[dep.resolved]}`);

View File

@ -97,6 +97,9 @@ export class Identifiers {
static injectViewContainerRef:
o.ExternalReference = {name: 'ɵinjectViewContainerRef', moduleName: CORE};
static injectChangeDetectorRef:
o.ExternalReference = {name: 'ɵinjectChangeDetectorRef', moduleName: CORE};
static directiveInject: o.ExternalReference = {name: 'ɵdirectiveInject', moduleName: CORE};
static defineComponent: o.ExternalReference = {name: 'ɵdefineComponent', moduleName: CORE};