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