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

Function ingestBoundText

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

* Ingest an interpolated text node from the AST into the given `ViewCompilation`.

(
  unit: ViewCompilationUnit,
  text: t.BoundText,
  icuPlaceholder: string | null,
)

Source from the content-addressed store, hash-verified

570 * Ingest an interpolated text node from the AST into the given `ViewCompilation`.
571 */
572function ingestBoundText(
573 unit: ViewCompilationUnit,
574 text: t.BoundText,
575 icuPlaceholder: string | null,
576): void {
577 let value = text.value;
578 if (value instanceof e.ASTWithSource) {
579 value = value.ast;
580 }
581 if (!(value instanceof e.Interpolation)) {
582 throw new Error(
583 `AssertionError: expected Interpolation for BoundText node, got ${value.constructor.name}`,
584 );
585 }
586 if (text.i18n !== undefined && !(text.i18n instanceof i18n.Container)) {
587 throw Error(
588 `Unhandled i18n metadata type for text interpolation: ${text.i18n?.constructor.name}`,
589 );
590 }
591
592 const i18nPlaceholders =
593 text.i18n instanceof i18n.Container
594 ? text.i18n.children
595 .filter((node): node is i18n.Placeholder => node instanceof i18n.Placeholder)
596 .map((placeholder) => placeholder.name)
597 : [];
598 if (i18nPlaceholders.length > 0 && i18nPlaceholders.length !== value.expressions.length) {
599 throw Error(
600 `Unexpected number of i18n placeholders (${value.expressions.length}) for BoundText with ${value.expressions.length} expressions`,
601 );
602 }
603
604 const textXref = unit.job.allocateXrefId();
605 unit.create.push(ir.createTextOp(textXref, '', icuPlaceholder, text.sourceSpan));
606 unit.update.push(
607 ir.createInterpolateTextOp(
608 textXref,
609 new ir.Interpolation(
610 value.strings,
611 value.expressions.map((expr) => convertAst(expr, unit.job, null)),
612 i18nPlaceholders,
613 ),
614 text.sourceSpan,
615 ),
616 );
617}
618
619/**
620 * Ingest an `@if` block into the given `ViewCompilation`.

Callers 2

ingestNodesFunction · 0.85
ingestIcuFunction · 0.85

Calls 5

ErrorInterface · 0.85
convertAstFunction · 0.85
mapMethod · 0.80
filterMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected