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

Function compileInjectDependency

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

Source from the content-addressed store, hash-verified

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

Callers 1

injectDependenciesFunction · 0.85

Calls 2

getInjectFnFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected