* Ingest an `ng-template` node from the AST into the given `ViewCompilation`.
(unit: ViewCompilationUnit, tmpl: t.Template)
| 330 | * Ingest an `ng-template` node from the AST into the given `ViewCompilation`. |
| 331 | */ |
| 332 | function ingestTemplate(unit: ViewCompilationUnit, tmpl: t.Template): void { |
| 333 | if ( |
| 334 | tmpl.i18n !== undefined && |
| 335 | !(tmpl.i18n instanceof i18n.Message || tmpl.i18n instanceof i18n.TagPlaceholder) |
| 336 | ) { |
| 337 | throw Error(`Unhandled i18n metadata type for template: ${tmpl.i18n.constructor.name}`); |
| 338 | } |
| 339 | |
| 340 | const childView = unit.job.allocateView(unit.xref); |
| 341 | |
| 342 | let tagNameWithoutNamespace = tmpl.tagName; |
| 343 | let namespacePrefix: string | null = ''; |
| 344 | if (tmpl.tagName) { |
| 345 | [namespacePrefix, tagNameWithoutNamespace] = splitNsName(tmpl.tagName); |
| 346 | } |
| 347 | |
| 348 | const i18nPlaceholder = tmpl.i18n instanceof i18n.TagPlaceholder ? tmpl.i18n : undefined; |
| 349 | const namespace = namespaceForKey(namespacePrefix); |
| 350 | const functionNameSuffix = |
| 351 | tagNameWithoutNamespace === null ? '' : prefixWithNamespace(tagNameWithoutNamespace, namespace); |
| 352 | const templateKind = isPlainTemplate(tmpl) |
| 353 | ? ir.TemplateKind.NgTemplate |
| 354 | : ir.TemplateKind.Structural; |
| 355 | const templateOp = ir.createTemplateOp( |
| 356 | childView.xref, |
| 357 | templateKind, |
| 358 | tagNameWithoutNamespace, |
| 359 | functionNameSuffix, |
| 360 | namespace, |
| 361 | i18nPlaceholder, |
| 362 | tmpl.startSourceSpan, |
| 363 | tmpl.sourceSpan, |
| 364 | ); |
| 365 | unit.create.push(templateOp); |
| 366 | |
| 367 | ingestTemplateBindings(unit, templateOp, tmpl, templateKind); |
| 368 | ingestReferences(templateOp, tmpl); |
| 369 | ingestNodes(childView, tmpl.children); |
| 370 | |
| 371 | for (const {name, value} of tmpl.variables) { |
| 372 | childView.contextVariables.set(name, value !== '' ? value : '$implicit'); |
| 373 | } |
| 374 | |
| 375 | // If this is a plain template and there is an i18n message associated with it, insert i18n start |
| 376 | // and end ops. For structural directive templates, the i18n ops will be added when ingesting the |
| 377 | // element/template the directive is placed on. |
| 378 | if (templateKind === ir.TemplateKind.NgTemplate && tmpl.i18n instanceof i18n.Message) { |
| 379 | const id = unit.job.allocateXrefId(); |
| 380 | ir.OpList.insertAfter( |
| 381 | ir.createI18nStartOp(id, tmpl.i18n, undefined, tmpl.startSourceSpan), |
| 382 | childView.create.head, |
| 383 | ); |
| 384 | ir.OpList.insertBefore( |
| 385 | ir.createI18nEndOp(id, tmpl.endSourceSpan ?? tmpl.startSourceSpan), |
| 386 | childView.create.tail, |
| 387 | ); |
| 388 | } |
| 389 | } |
no test coverage detected
searching dependent graphs…