* Ingest a content node from the AST into the given `ViewCompilation`.
(unit: ViewCompilationUnit, content: t.Content)
| 508 | * Ingest a content node from the AST into the given `ViewCompilation`. |
| 509 | */ |
| 510 | function ingestContent(unit: ViewCompilationUnit, content: t.Content): void { |
| 511 | if (content.i18n !== undefined && !(content.i18n instanceof i18n.TagPlaceholder)) { |
| 512 | throw Error(`Unhandled i18n metadata type for element: ${content.i18n.constructor.name}`); |
| 513 | } |
| 514 | |
| 515 | let fallbackView: ViewCompilationUnit | null = null; |
| 516 | |
| 517 | // Don't capture default content that's only made up of empty text nodes and comments. |
| 518 | // Note that we process the default content before the projection in order to match the |
| 519 | // insertion order at runtime. |
| 520 | if ( |
| 521 | content.children.some( |
| 522 | (child) => |
| 523 | !(child instanceof t.Comment) && |
| 524 | (!(child instanceof t.Text) || child.value.trim().length > 0), |
| 525 | ) |
| 526 | ) { |
| 527 | fallbackView = unit.job.allocateView(unit.xref); |
| 528 | ingestNodes(fallbackView, content.children); |
| 529 | } |
| 530 | |
| 531 | const id = unit.job.allocateXrefId(); |
| 532 | const op = ir.createProjectionOp( |
| 533 | id, |
| 534 | content.selector, |
| 535 | content.i18n, |
| 536 | fallbackView?.xref ?? null, |
| 537 | content.sourceSpan, |
| 538 | ); |
| 539 | for (const attr of content.attributes) { |
| 540 | const securityContext = domSchema.securityContext(content.name, attr.name, true); |
| 541 | unit.update.push( |
| 542 | ir.createBindingOp( |
| 543 | op.xref, |
| 544 | ir.BindingKind.Attribute, |
| 545 | attr.name, |
| 546 | o.literal(attr.value), |
| 547 | null, |
| 548 | securityContext, |
| 549 | true, |
| 550 | false, |
| 551 | null, |
| 552 | asMessage(attr.i18n), |
| 553 | attr.sourceSpan, |
| 554 | ), |
| 555 | ); |
| 556 | } |
| 557 | unit.create.push(op); |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Ingest a literal text node from the AST into the given `ViewCompilation`. |
no test coverage detected