* Ingest an `@if` block into the given `ViewCompilation`.
(unit: ViewCompilationUnit, ifBlock: t.IfBlock)
| 504 | * Ingest an `@if` block into the given `ViewCompilation`. |
| 505 | */ |
| 506 | function ingestIfBlock(unit: ViewCompilationUnit, ifBlock: t.IfBlock): void { |
| 507 | let firstXref: ir.XrefId | null = null; |
| 508 | let conditions: Array<ir.ConditionalCaseExpr> = []; |
| 509 | for (let i = 0; i < ifBlock.branches.length; i++) { |
| 510 | const ifCase = ifBlock.branches[i]; |
| 511 | const cView = unit.job.allocateView(unit.xref); |
| 512 | const tagName = ingestControlFlowInsertionPoint(unit, cView.xref, ifCase); |
| 513 | |
| 514 | if (ifCase.expressionAlias !== null) { |
| 515 | cView.contextVariables.set(ifCase.expressionAlias.name, ir.CTX_REF); |
| 516 | } |
| 517 | |
| 518 | let ifCaseI18nMeta: i18n.BlockPlaceholder | undefined = undefined; |
| 519 | if (ifCase.i18n !== undefined) { |
| 520 | if (!(ifCase.i18n instanceof i18n.BlockPlaceholder)) { |
| 521 | throw Error(`Unhandled i18n metadata type for if block: ${ifCase.i18n?.constructor.name}`); |
| 522 | } |
| 523 | ifCaseI18nMeta = ifCase.i18n; |
| 524 | } |
| 525 | |
| 526 | const createOp = i === 0 ? ir.createConditionalCreateOp : ir.createConditionalBranchCreateOp; |
| 527 | |
| 528 | const conditionalCreateOp = createOp( |
| 529 | cView.xref, |
| 530 | ir.TemplateKind.Block, |
| 531 | tagName, |
| 532 | 'Conditional', |
| 533 | ir.Namespace.HTML, |
| 534 | ifCaseI18nMeta, |
| 535 | ifCase.startSourceSpan, |
| 536 | ifCase.sourceSpan, |
| 537 | ); |
| 538 | unit.create.push(conditionalCreateOp); |
| 539 | |
| 540 | if (firstXref === null) { |
| 541 | firstXref = cView.xref; |
| 542 | } |
| 543 | |
| 544 | const caseExpr = ifCase.expression ? convertAst(ifCase.expression, unit.job, null) : null; |
| 545 | const conditionalCaseExpr = new ir.ConditionalCaseExpr( |
| 546 | caseExpr, |
| 547 | conditionalCreateOp.xref, |
| 548 | conditionalCreateOp.handle, |
| 549 | ifCase.expressionAlias, |
| 550 | ); |
| 551 | conditions.push(conditionalCaseExpr); |
| 552 | ingestNodes(cView, ifCase.children); |
| 553 | } |
| 554 | unit.update.push(ir.createConditionalOp(firstXref!, null, conditions, ifBlock.sourceSpan)); |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Ingest an `@switch` block into the given `ViewCompilation`. |
no test coverage detected