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

Function ingestBoundText

packages/compiler/src/template/pipeline/src/ingest.ts:456–501  ·  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

454 * Ingest an interpolated text node from the AST into the given `ViewCompilation`.
455 */
456function ingestBoundText(
457 unit: ViewCompilationUnit,
458 text: t.BoundText,
459 icuPlaceholder: string | null,
460): void {
461 let value = text.value;
462 if (value instanceof e.ASTWithSource) {
463 value = value.ast;
464 }
465 if (!(value instanceof e.Interpolation)) {
466 throw new Error(
467 `AssertionError: expected Interpolation for BoundText node, got ${value.constructor.name}`,
468 );
469 }
470 if (text.i18n !== undefined && !(text.i18n instanceof i18n.Container)) {
471 throw Error(
472 `Unhandled i18n metadata type for text interpolation: ${text.i18n?.constructor.name}`,
473 );
474 }
475
476 const i18nPlaceholders =
477 text.i18n instanceof i18n.Container
478 ? text.i18n.children
479 .filter((node): node is i18n.Placeholder => node instanceof i18n.Placeholder)
480 .map((placeholder) => placeholder.name)
481 : [];
482 if (i18nPlaceholders.length > 0 && i18nPlaceholders.length !== value.expressions.length) {
483 throw Error(
484 `Unexpected number of i18n placeholders (${value.expressions.length}) for BoundText with ${value.expressions.length} expressions`,
485 );
486 }
487
488 const textXref = unit.job.allocateXrefId();
489 unit.create.push(ir.createTextOp(textXref, '', icuPlaceholder, text.sourceSpan));
490 unit.update.push(
491 ir.createInterpolateTextOp(
492 textXref,
493 new ir.Interpolation(
494 value.strings,
495 value.expressions.map((expr) => convertAst(expr, unit.job, null)),
496 i18nPlaceholders,
497 ),
498 text.sourceSpan,
499 ),
500 );
501}
502
503/**
504 * 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