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

Function icuStart

packages/core/src/render3/i18n/i18n_parse.ts:584–645  ·  view source on GitHub ↗

* Generate the OpCodes for ICU expressions. * * @param icuExpression * @param index Index where the anchor is stored and an optional `TIcuContainerNode` * - `lView[anchorIdx]` points to a `Comment` node representing the anchor for the ICU. * - `tView.data[anchorIdx]` points to the `TIcuCont

(
  ast: I18nNode[],
  tView: TView,
  lView: LView,
  updateOpCodes: I18nUpdateOpCodes,
  parentIdx: number,
  icuExpression: IcuExpression,
  anchorIdx: number,
)

Source from the content-addressed store, hash-verified

582 * - `tView.data[anchorIdx]` points to the `TIcuContainerNode` if ICU is root (`null` otherwise)
583 */
584function icuStart(
585 ast: I18nNode[],
586 tView: TView,
587 lView: LView,
588 updateOpCodes: I18nUpdateOpCodes,
589 parentIdx: number,
590 icuExpression: IcuExpression,
591 anchorIdx: number,
592) {
593 ngDevMode && assertDefined(icuExpression, 'ICU expression must be defined');
594 let bindingMask = 0;
595 const tIcu: TIcu = {
596 type: icuExpression.type,
597 currentCaseLViewIndex: allocExpando(tView, lView, 1, null),
598 anchorIdx,
599 cases: [],
600 create: [],
601 remove: [],
602 update: [],
603 };
604 addUpdateIcuSwitch(updateOpCodes, icuExpression, anchorIdx);
605 setTIcu(tView, anchorIdx, tIcu);
606 const values = icuExpression.values;
607 const cases: I18nNode[][] = [];
608 for (let i = 0; i < values.length; i++) {
609 // Each value is an array of strings & other ICU expressions
610 const valueArr = values[i];
611 const nestedIcus: IcuExpression[] = [];
612 for (let j = 0; j < valueArr.length; j++) {
613 const value = valueArr[j];
614 if (typeof value !== 'string') {
615 // It is an nested ICU expression
616 const icuIndex = nestedIcus.push(value as IcuExpression) - 1;
617 // Replace nested ICU expression by a comment node
618 valueArr[j] = `<!--�${icuIndex}�-->`;
619 }
620 }
621 const caseAst: I18nNode[] = [];
622 cases.push(caseAst);
623 bindingMask =
624 parseIcuCase(
625 caseAst,
626 tView,
627 tIcu,
628 lView,
629 updateOpCodes,
630 parentIdx,
631 icuExpression.cases[i],
632 valueArr.join(''),
633 nestedIcus,
634 ) | bindingMask;
635 }
636 if (bindingMask) {
637 addUpdateIcuUpdate(updateOpCodes, bindingMask, anchorIdx);
638 }
639 ast.push({
640 kind: I18nNodeKind.ICU,
641 index: anchorIdx,

Callers 2

i18nStartFirstCreatePassFunction · 0.85
walkIcuTreeFunction · 0.85

Calls 8

assertDefinedFunction · 0.90
allocExpandoFunction · 0.90
setTIcuFunction · 0.90
addUpdateIcuSwitchFunction · 0.85
parseIcuCaseFunction · 0.85
addUpdateIcuUpdateFunction · 0.85
joinMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected