Skip to content

Commit

Permalink
wip: structural directives
Browse files Browse the repository at this point in the history
  • Loading branch information
dylhunn committed Dec 6, 2023
1 parent b6f03f2 commit 340ed4d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,19 @@
],
"expectations": [
{
"files": [
{
"generated": "self_closing.js",
"expected": "self_closing_template.js",
"templatePipelineExpected": "self_closing_template.pipeline.js"
}
],
"extraChecks": [
"verifyPlaceholdersIntegrity",
"verifyUniqueConsts"
]
}
],
"skipForTemplatePipeline": true
]
},
{
"description": "should handle i18n context in nested templates",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
function MyComponent_img_1_Template(rf, ctx) {
if (rf & 1) {
$r3$.ɵɵelement(0, "img", 1);
}
}
function MyComponent_img_2_Template(rf, ctx) {
if (rf & 1) {
$r3$.ɵɵelementStart(0, "img", 4);
$r3$.ɵɵi18nAttributes(1, 0);
$r3$.ɵɵelementEnd();
}
if (rf & 2) {
const $ctx_r1$ = $r3$.ɵɵnextContext();
$r3$.ɵɵi18nExp($ctx_r1$.id);
$r3$.ɵɵi18nApply(1);
}
}
decls: 3,
vars: 2,
consts: () => {
__i18nMsg__('App logo #{$interpolation}', [['interpolation', String.raw`\uFFFD0\uFFFD`]], {original_code: {'interpolation': '{{ id }}'}}, {})
return [
["title", $i18n_0$],
["src", "logo.png"],
["src", "logo.png", __AttributeMarker.Template__, "ngIf"],
["src", "logo.png", __AttributeMarker.Bindings__, "title",
__AttributeMarker.Template__, "ngIf"],
["src", "logo.png", __AttributeMarker.I18n__, "title"]
];
},
template: function MyComponent_Template(rf, ctx) {
if (rf & 1) {
$r3$.ɵɵelement(0, "img", 1);
$r3$.ɵɵtemplate(1, MyComponent_img_1_Template, 1, 0, "img", 2)(2, MyComponent_img_2_Template, 2, 1, "img", 3);
}
if (rf & 2) {
$r3$.ɵɵadvance(1);
$r3$.ɵɵproperty("ngIf", ctx.visible);
$r3$.ɵɵadvance(1);
$r3$.ɵɵproperty("ngIf", ctx.visible);
}
}

19 changes: 10 additions & 9 deletions packages/compiler/src/template/pipeline/src/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,16 @@ function ingestBinding(
value = value.ast;
}


if (flags & BindingFlags.OnNgTemplateElement && !(flags & BindingFlags.BindingTargetsTemplate) &&
type === e.BindingType.Property) {
// This binding only exists for later const extraction, and is not an actual binding to be
// created.
view.create.push(
ir.createExtractedAttributeOp(xref, ir.BindingKind.Property, name, null, null));
return;
}

let i18nContext: ir.XrefId|null = null;
if (i18nMeta !== undefined) {
if (!(i18nMeta instanceof i18n.Message)) {
Expand All @@ -903,15 +913,6 @@ function ingestBinding(
ir.createI18nContextOp(ir.I18nContextKind.Attr, i18nContext, null, i18nMeta, null!));
}

if (flags & BindingFlags.OnNgTemplateElement && !(flags & BindingFlags.BindingTargetsTemplate) &&
type === e.BindingType.Property) {
// This binding only exists for later const extraction, and is not an actual binding to be
// created.
view.create.push(
ir.createExtractedAttributeOp(xref, ir.BindingKind.Property, name, null, i18nContext));
return;
}

let expression: o.Expression|ir.Interpolation;
// TODO: We could easily generate source maps for subexpressions in these cases, but
// TemplateDefinitionBuilder does not. Should we do so?
Expand Down

0 comments on commit 340ed4d

Please sign in to comment.