MCPcopy Create free account
hub / github.com/angular/angular / compileInjectDependency

Function compileInjectDependency

packages/compiler/src/render3/r3_factory.ts:236–277  ·  view source on GitHub ↗
(
  dep: R3DependencyMetadata,
  target: FactoryTarget,
  index: number,
)

Source from the content-addressed store, hash-verified

234}
235
236function compileInjectDependency(
237 dep: R3DependencyMetadata,
238 target: FactoryTarget,
239 index: number,
240): o.Expression {
241 // Interpret the dependency according to its resolved type.
242 if (dep.token === null) {
243 return o.importExpr(R3.invalidFactoryDep).callFn([o.literal(index)]);
244 } else if (dep.attributeNameType === null) {
245 // Build up the injection flags according to the metadata.
246 const flags =
247 InjectFlags.Default |
248 (dep.self ? InjectFlags.Self : 0) |
249 (dep.skipSelf ? InjectFlags.SkipSelf : 0) |
250 (dep.host ? InjectFlags.Host : 0) |
251 (dep.optional ? InjectFlags.Optional : 0) |
252 (target === FactoryTarget.Pipe ? InjectFlags.ForPipe : 0);
253
254 // If this dependency is optional or otherwise has non-default flags, then additional
255 // parameters describing how to inject the dependency must be passed to the inject function
256 // that's being used.
257 let flagsParam: o.LiteralExpr | null =
258 flags !== InjectFlags.Default || dep.optional ? o.literal(flags) : null;
259
260 // Build up the arguments to the injectFn call.
261 const injectArgs = [dep.token];
262 if (flagsParam) {
263 injectArgs.push(flagsParam);
264 }
265 const injectFn = getInjectFn(target);
266 return o.importExpr(injectFn).callFn(injectArgs);
267 } else {
268 // The `dep.attributeTypeName` value is defined, which indicates that this is an `@Attribute()`
269 // type dependency. For the generated JS we still want to use the `dep.token` value in case the
270 // name given for the attribute is not a string literal. For example given `@Attribute(foo())`,
271 // we want to generate `ɵɵinjectAttribute(foo())`.
272 //
273 // The `dep.attributeTypeName` is only actually used (in `createCtorDepType()`) to generate
274 // typings.
275 return o.importExpr(R3.injectAttribute).callFn([dep.token]);
276 }
277}
278
279function createCtorDepsType(deps: R3DependencyMetadata[]): o.Type {
280 let hasTypes = false;

Callers 1

injectDependenciesFunction · 0.85

Calls 2

getInjectFnFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected