fix(ivy): inject() no longer uses default value parameters (#24565)

inject() was changed in da31db7 to not take a default value parameter,
so injectable_compiler_2 should not request the use of one when
using inject().

PR Close #24565
This commit is contained in:
Alex Rickabaugh 2018-06-15 15:27:12 -07:00 committed by Miško Hevery
parent 10da6a45c6
commit 7d3fd4d655
4 changed files with 3 additions and 33 deletions

View File

@ -52,7 +52,6 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
fnOrClass, fnOrClass,
useNew, useNew,
injectFn: Identifiers.inject, injectFn: Identifiers.inject,
useOptionalParam: true,
deps: meta.deps, deps: meta.deps,
}); });
} else if (meta.useClass !== undefined) { } else if (meta.useClass !== undefined) {
@ -94,7 +93,6 @@ export function compileInjectable(meta: R3InjectableMetadata): InjectableDef {
fnOrClass: meta.type, fnOrClass: meta.type,
useNew: true, useNew: true,
injectFn: Identifiers.inject, injectFn: Identifiers.inject,
useOptionalParam: true,
deps: meta.deps, deps: meta.deps,
}); });
} }

View File

@ -55,19 +55,6 @@ export interface R3FactoryMetadata {
*/ */
injectFn: o.ExternalReference; injectFn: o.ExternalReference;
/**
* Whether the `injectFn` given above accepts a 2nd parameter indicating the default value to
* be used to resolve missing @Optional dependencies.
*
* If the optional parameter is used, injectFn for an optional dependency will be invoked as:
* `injectFn(token, null, flags)`.
*
* If it's not used, injectFn for an optional dependency will be invoked as:
* `injectFn(token, flags)`. The Optional flag will indicate that injectFn should select a default
* value if it cannot satisfy the injection request for the token.
*/
useOptionalParam: boolean;
/** /**
* If present, the return of the factory function will be an array with the injected value in the * If present, the return of the factory function will be an array with the injected value in the
* 0th position and the extra results included in subsequent positions. * 0th position and the extra results included in subsequent positions.
@ -162,8 +149,7 @@ export interface R3DependencyMetadata {
*/ */
export function compileFactoryFunction(meta: R3FactoryMetadata): o.Expression { export function compileFactoryFunction(meta: R3FactoryMetadata): o.Expression {
// Each dependency becomes an invocation of an inject*() function. // Each dependency becomes an invocation of an inject*() function.
const args = const args = meta.deps.map(dep => compileInjectDependency(dep, meta.injectFn));
meta.deps.map(dep => compileInjectDependency(dep, meta.injectFn, meta.useOptionalParam));
// The overall result depends on whether this is construction or function invocation. // The overall result depends on whether this is construction or function invocation.
const expr = meta.useNew ? new o.InstantiateExpr(meta.fnOrClass, args) : const expr = meta.useNew ? new o.InstantiateExpr(meta.fnOrClass, args) :
@ -178,8 +164,7 @@ export function compileFactoryFunction(meta: R3FactoryMetadata): o.Expression {
} }
function compileInjectDependency( function compileInjectDependency(
dep: R3DependencyMetadata, injectFn: o.ExternalReference, dep: R3DependencyMetadata, injectFn: o.ExternalReference): o.Expression {
useOptionalParam: boolean): o.Expression {
// Interpret the dependency according to its resolved type. // Interpret the dependency according to its resolved type.
switch (dep.resolved) { switch (dep.resolved) {
case R3ResolvedDependencyType.Token: case R3ResolvedDependencyType.Token:
@ -202,18 +187,7 @@ function compileInjectDependency(
// parameters describing how to inject the dependency must be passed to the inject function // parameters describing how to inject the dependency must be passed to the inject function
// that's being used. // that's being used.
if (flags !== InjectFlags.Default || dep.optional) { if (flags !== InjectFlags.Default || dep.optional) {
// Either the dependency is optional, or non-default flags are in use. Either of these cases injectArgs.push(o.literal(flags));
// necessitates adding an argument for the default value if such an argument is required
// by the inject function (useOptionalParam === true).
if (useOptionalParam) {
// The inject function requires a default value parameter.
injectArgs.push(dep.optional ? o.NULL_EXPR : o.literal(undefined));
}
// The last parameter is always the InjectFlags, which only need to be specified if they're
// non-default.
if (flags !== InjectFlags.Default) {
injectArgs.push(o.literal(flags));
}
} }
return o.importExpr(injectFn).callFn(injectArgs); return o.importExpr(injectFn).callFn(injectArgs);
} }

View File

@ -37,7 +37,6 @@ export function compilePipe(
fnOrClass: outputCtx.importExpr(pipe.type.reference), deps, fnOrClass: outputCtx.importExpr(pipe.type.reference), deps,
useNew: true, useNew: true,
injectFn: R3.directiveInject, injectFn: R3.directiveInject,
useOptionalParam: false,
}); });
definitionMapValues.push({key: 'factory', value: templateFactory, quoted: false}); definitionMapValues.push({key: 'factory', value: templateFactory, quoted: false});

View File

@ -49,7 +49,6 @@ function baseDirectiveFields(
deps: meta.deps, deps: meta.deps,
useNew: true, useNew: true,
injectFn: R3.directiveInject, injectFn: R3.directiveInject,
useOptionalParam: false,
extraResults: queryDefinitions, extraResults: queryDefinitions,
})); }));