* Ingest an `@if` block into the given `ViewCompilation`.
(unit: ViewCompilationUnit, ifBlock: t.IfBlock)
| 620 | * Ingest an `@if` block into the given `ViewCompilation`. |
| 621 | */ |
| 622 | function ingestIfBlock(unit: ViewCompilationUnit, ifBlock: t.IfBlock): void { |
| 623 | let firstXref: ir.XrefId | null = null; |
| 624 | let conditions: Array<ir.ConditionalCaseExpr> = []; |
| 625 | for (let i = 0; i < ifBlock.branches.length; i++) { |
| 626 | const ifCase = ifBlock.branches[i]; |
| 627 | const cView = unit.job.allocateView(unit.xref); |
| 628 | const tagName = ingestControlFlowInsertionPoint(unit, cView.xref, ifCase); |
| 629 | |
| 630 | if (ifCase.expressionAlias !== null) { |
| 631 | cView.contextVariables.set(ifCase.expressionAlias.name, ir.CTX_REF); |
| 632 | } |
| 633 | |
| 634 | let ifCaseI18nMeta: i18n.BlockPlaceholder | undefined = undefined; |
| 635 | if (ifCase.i18n !== undefined) { |
| 636 | if (!(ifCase.i18n instanceof i18n.BlockPlaceholder)) { |
| 637 | throw Error(`Unhandled i18n metadata type for if block: ${ifCase.i18n?.constructor.name}`); |
| 638 | } |
| 639 | ifCaseI18nMeta = ifCase.i18n; |
| 640 | } |
| 641 | |
| 642 | const createOp = i === 0 ? ir.createConditionalCreateOp : ir.createConditionalBranchCreateOp; |
| 643 | |
| 644 | const conditionalCreateOp = createOp( |
| 645 | cView.xref, |
| 646 | ir.TemplateKind.Block, |
| 647 | tagName, |
| 648 | 'Conditional', |
| 649 | ir.Namespace.HTML, |
| 650 | ifCaseI18nMeta, |
| 651 | ifCase.startSourceSpan, |
| 652 | ifCase.sourceSpan, |
| 653 | ); |
| 654 | unit.create.push(conditionalCreateOp); |
| 655 | |
| 656 | if (firstXref === null) { |
| 657 | firstXref = cView.xref; |
| 658 | } |
| 659 | |
| 660 | const caseExpr = ifCase.expression ? convertAst(ifCase.expression, unit.job, null) : null; |
| 661 | const conditionalCaseExpr = new ir.ConditionalCaseExpr( |
| 662 | caseExpr, |
| 663 | conditionalCreateOp.xref, |
| 664 | conditionalCreateOp.handle, |
| 665 | ifCase.expressionAlias, |
| 666 | ); |
| 667 | conditions.push(conditionalCaseExpr); |
| 668 | ingestNodes(cView, ifCase.children); |
| 669 | } |
| 670 | unit.update.push(ir.createConditionalOp(firstXref!, null, conditions, ifBlock.sourceSpan)); |
| 671 | } |
| 672 | |
| 673 | /** |
| 674 | * Ingest an `@switch` block into the given `ViewCompilation`. |
no test coverage detected