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

Function ingestSwitchBlock

packages/compiler/src/template/pipeline/src/ingest.ts:560–621  ·  view source on GitHub ↗

* Ingest an `@switch` block into the given `ViewCompilation`.

(unit: ViewCompilationUnit, switchBlock: t.SwitchBlock)

Source from the content-addressed store, hash-verified

558 * Ingest an `@switch` block into the given `ViewCompilation`.
559 */
560function ingestSwitchBlock(unit: ViewCompilationUnit, switchBlock: t.SwitchBlock): void {
561 // Don't ingest empty switches since they won't render anything.
562 if (switchBlock.groups.length === 0) {
563 return;
564 }
565
566 let firstXref: ir.XrefId | null = null;
567 let conditions: Array<ir.ConditionalCaseExpr> = [];
568 for (let i = 0; i < switchBlock.groups.length; i++) {
569 const switchCaseGroup = switchBlock.groups[i];
570 const cView = unit.job.allocateView(unit.xref);
571 const tagName = ingestControlFlowInsertionPoint(unit, cView.xref, switchCaseGroup);
572 let switchCaseI18nMeta: i18n.BlockPlaceholder | undefined = undefined;
573 if (switchCaseGroup.i18n !== undefined) {
574 if (!(switchCaseGroup.i18n instanceof i18n.BlockPlaceholder)) {
575 throw Error(
576 `Unhandled i18n metadata type for switch block: ${switchCaseGroup.i18n?.constructor.name}`,
577 );
578 }
579 switchCaseI18nMeta = switchCaseGroup.i18n;
580 }
581
582 const createOp = i === 0 ? ir.createConditionalCreateOp : ir.createConditionalBranchCreateOp;
583
584 const conditionalCreateOp = createOp(
585 cView.xref,
586 ir.TemplateKind.Block,
587 tagName,
588 'Case',
589 ir.Namespace.HTML,
590 switchCaseI18nMeta,
591 switchCaseGroup.startSourceSpan,
592 switchCaseGroup.sourceSpan,
593 );
594 unit.create.push(conditionalCreateOp);
595
596 if (firstXref === null) {
597 firstXref = cView.xref;
598 }
599
600 for (const switchCase of switchCaseGroup.cases) {
601 const caseExpr = switchCase.expression
602 ? convertAst(switchCase.expression, unit.job, switchBlock.startSourceSpan)
603 : null;
604 const conditionalCaseExpr = new ir.ConditionalCaseExpr(
605 caseExpr,
606 conditionalCreateOp.xref,
607 conditionalCreateOp.handle,
608 );
609 conditions.push(conditionalCaseExpr);
610 }
611 ingestNodes(cView, switchCaseGroup.children);
612 }
613 unit.update.push(
614 ir.createConditionalOp(
615 firstXref!,
616 convertAst(switchBlock.expression, unit.job, null),
617 conditions,

Callers 1

ingestNodesFunction · 0.85

Calls 6

ErrorInterface · 0.85
convertAstFunction · 0.85
ingestNodesFunction · 0.85
allocateViewMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected