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

Function wrapInStaticStylingKey

packages/core/src/render3/instructions/styling.ts:406–484  ·  view source on GitHub ↗
(
  tData: TData,
  tNode: TNode,
  stylingKey: TStylingKey,
  isClassBased: boolean,
)

Source from the content-addressed store, hash-verified

404 * @param isClassBased `true` if `class` (`false` if `style`)
405 */
406export function wrapInStaticStylingKey(
407 tData: TData,
408 tNode: TNode,
409 stylingKey: TStylingKey,
410 isClassBased: boolean,
411): TStylingKey {
412 const hostDirectiveDef = getCurrentDirectiveDef(tData);
413 let residual = isClassBased ? tNode.residualClasses : tNode.residualStyles;
414 if (hostDirectiveDef === null) {
415 // We are in template node.
416 // If template node already had styling instruction then it has already collected the static
417 // styling and there is no need to collect them again. We know that we are the first styling
418 // instruction because the `TNode.*Bindings` points to 0 (nothing has been inserted yet).
419 const isFirstStylingInstructionInTemplate =
420 ((isClassBased ? tNode.classBindings : tNode.styleBindings) as any as number) === 0;
421 if (isFirstStylingInstructionInTemplate) {
422 // It would be nice to be able to get the statics from `mergeAttrs`, however, at this point
423 // they are already merged and it would not be possible to figure which property belongs where
424 // in the priority.
425 stylingKey = collectStylingFromDirectives(null, tData, tNode, stylingKey, isClassBased);
426 stylingKey = collectStylingFromTAttrs(stylingKey, tNode.attrs, isClassBased);
427 // We know that if we have styling binding in template we can't have residual.
428 residual = null;
429 }
430 } else {
431 // We are in host binding node and there was no binding instruction in template node.
432 // This means that we need to compute the residual.
433 const directiveStylingLast = tNode.directiveStylingLast;
434 const isFirstStylingInstructionInHostBinding =
435 directiveStylingLast === -1 || tData[directiveStylingLast] !== hostDirectiveDef;
436 if (isFirstStylingInstructionInHostBinding) {
437 stylingKey = collectStylingFromDirectives(
438 hostDirectiveDef,
439 tData,
440 tNode,
441 stylingKey,
442 isClassBased,
443 );
444 if (residual === null) {
445 // - If `null` than either:
446 // - Template styling instruction already ran and it has consumed the static
447 // styling into its `TStylingKey` and so there is no need to update residual. Instead
448 // we need to update the `TStylingKey` associated with the first template node
449 // instruction. OR
450 // - Some other styling instruction ran and determined that there are no residuals
451 let templateStylingKey = getTemplateHeadTStylingKey(tData, tNode, isClassBased);
452 if (templateStylingKey !== undefined && Array.isArray(templateStylingKey)) {
453 // Only recompute if `templateStylingKey` had static values. (If no static value found
454 // then there is nothing to do since this operation can only produce less static keys, not
455 // more.)
456 templateStylingKey = collectStylingFromDirectives(
457 null,
458 tData,
459 tNode,
460 templateStylingKey[1] /* unwrap previous statics */,
461 isClassBased,
462 );
463 templateStylingKey = collectStylingFromTAttrs(

Callers 1

stylingFirstUpdatePassFunction · 0.85

Calls 7

getCurrentDirectiveDefFunction · 0.90
collectStylingFromTAttrsFunction · 0.85
collectResidualFunction · 0.85
isArrayMethod · 0.80

Tested by

no test coverage detected