* Ingest a content node from the AST into the given `ViewCompilation`.
(unit: ViewCompilationUnit, content: t.Content)
| 392 | * Ingest a content node from the AST into the given `ViewCompilation`. |
| 393 | */ |
| 394 | function ingestContent(unit: ViewCompilationUnit, content: t.Content): void { |
| 395 | if (content.i18n !== undefined && !(content.i18n instanceof i18n.TagPlaceholder)) { |
| 396 | throw Error(`Unhandled i18n metadata type for element: ${content.i18n.constructor.name}`); |
| 397 | } |
| 398 | |
| 399 | let fallbackView: ViewCompilationUnit | null = null; |
| 400 | |
| 401 | // Don't capture default content that's only made up of empty text nodes and comments. |
| 402 | // Note that we process the default content before the projection in order to match the |
| 403 | // insertion order at runtime. |
| 404 | if ( |
| 405 | content.children.some( |
| 406 | (child) => |
| 407 | !(child instanceof t.Comment) && |
| 408 | (!(child instanceof t.Text) || child.value.trim().length > 0), |
| 409 | ) |
| 410 | ) { |
| 411 | fallbackView = unit.job.allocateView(unit.xref); |
| 412 | ingestNodes(fallbackView, content.children); |
| 413 | } |
| 414 | |
| 415 | const id = unit.job.allocateXrefId(); |
| 416 | const op = ir.createProjectionOp( |
| 417 | id, |
| 418 | content.selector, |
| 419 | content.i18n, |
| 420 | fallbackView?.xref ?? null, |
| 421 | content.sourceSpan, |
| 422 | ); |
| 423 | for (const attr of content.attributes) { |
| 424 | const securityContext = domSchema.securityContext(content.name, attr.name, true); |
| 425 | unit.update.push( |
| 426 | ir.createBindingOp( |
| 427 | op.xref, |
| 428 | ir.BindingKind.Attribute, |
| 429 | attr.name, |
| 430 | o.literal(attr.value), |
| 431 | null, |
| 432 | securityContext, |
| 433 | true, |
| 434 | false, |
| 435 | null, |
| 436 | asMessage(attr.i18n), |
| 437 | attr.sourceSpan, |
| 438 | ), |
| 439 | ); |
| 440 | } |
| 441 | unit.create.push(op); |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * Ingest a literal text node from the AST into the given `ViewCompilation`. |
no test coverage detected