MCPcopy Index your code
hub / github.com/angular/angular / compileInjectDependency

Function compileInjectDependency

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

Source from the content-addressed store, hash-verified

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

Callers 1

injectDependenciesFunction · 0.85

Calls 2

getInjectFnFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…