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

Function icuStart

packages/core/src/render3/i18n/i18n_parse.ts:573–634  ·  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

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