fix(compiler): allow tree-shakeable injectables to depend on string tokens (#22376)

Previously the injectable compiler assumed all tree-shakeable injectables
would have dependencies that were injectables or InjectionTokens. However
old code still uses string tokens (e.g. NgUpgrade and '$injector'). Using
such tokens would cause the injectable compiler to crash.

Now, the injectable compiler can properly generate a dependency on such a
string token.

PR Close #22376
This commit is contained in:
Alex Rickabaugh
2018-02-22 10:29:01 -08:00
committed by Alex Eagle
parent 8bb2f5c71d
commit dd534471ec
3 changed files with 52 additions and 2 deletions

View File

@ -55,10 +55,11 @@ export class InjectableCompiler {
}
}
}
const tokenExpr = typeof token === 'string' ? o.literal(token) : ctx.importExpr(token);
if (flags !== InjectFlags.Default || defaultValue !== undefined) {
args = [ctx.importExpr(token), o.literal(defaultValue), o.literal(flags)];
args = [tokenExpr, o.literal(defaultValue), o.literal(flags)];
} else {
args = [ctx.importExpr(token)];
args = [tokenExpr];
}
return o.importExpr(Identifiers.inject).callFn(args);
});