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

Function wrapInStaticStylingKey

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

Source from the content-addressed store, hash-verified

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