Skip to content

Commit

Permalink
refactor(compiler): Ingest host attribute bindings in template pipeli…
Browse files Browse the repository at this point in the history
…ne (#51188)

Host property bindings beginning with `attr.` should have `Attribute` binding kind, and result in an `attribute` instruction.

This should really be handled in the parser in the future.

PR Close #51188
  • Loading branch information
dylhunn authored and alxhub committed Jul 28, 2023
1 parent a42c91e commit 5061311
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
"host_attribute_bindings.js"
]
}
],
"skipForTemplatePipeline": true
]
},
{
"description": "should support host attributes",
Expand Down
11 changes: 9 additions & 2 deletions packages/compiler/src/template/pipeline/src/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function ingestHostBinding(
return job;
}

// TODO: We should refactor the parser to use the same types and structures for host bindings as
// with ordinary components. This would allow us to share a lot more ingestion code.
export function ingestHostProperty(
job: HostBindingCompilationJob, property: e.ParsedProperty): void {
let expression: o.Expression|ir.Interpolation;
Expand All @@ -65,9 +67,14 @@ export function ingestHostProperty(
} else {
expression = convertAst(ast, job);
}
let bindingKind = ir.BindingKind.Property;
// TODO: this should really be handled in the parser.
if (property.name.startsWith('attr.')) {
property.name = property.name.substring('attr.'.length);
bindingKind = ir.BindingKind.Attribute;
}
job.update.push(ir.createBindingOp(
job.root.xref, ir.BindingKind.Property, property.name, expression, null, false,
property.sourceSpan));
job.root.xref, bindingKind, property.name, expression, null, false, property.sourceSpan));
}

export function ingestHostEvent(job: HostBindingCompilationJob, event: e.ParsedEvent) {}
Expand Down

0 comments on commit 5061311

Please sign in to comment.