Skip to content

Commit

Permalink
refactor(compiler): listeners should be ingested before i18nStart
Browse files Browse the repository at this point in the history
Listener instructions should not be inside the i18n block. Listeners are the only kind of binding that gets ingested into the create block, so we previously missed this case.
  • Loading branch information
dylhunn committed Dec 6, 2023
1 parent ca08fd2 commit b6f03f2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,19 @@
],
"expectations": [
{
"files": [
{
"generated": "event_listeners.js",
"expected": "event_listeners_template.js",
"templatePipelineExpected": "event_listeners_template.pipeline.js"
}
],
"extraChecks": [
"verifyPlaceholdersIntegrity",
"verifyUniqueConsts"
]
}
],
"skipForTemplatePipeline": true
]
},
{
"description": "should handle ng-content in i18n block",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
consts: () => {
__i18nMsg__('Hello', [], {}, {})
return [
$i18n_0$,
[__AttributeMarker.Bindings__, "click"]
];
},
template: function MyComponent_Template(rf, ctx) {
if (rf & 1) {
$r3$.ɵɵelementStart(0, "div", 1);
$r3$.ɵɵlistener("click", function MyComponent_Template_div_click_0_listener() { return ctx.onClick(); });
$r3$.ɵɵi18n(1, 0);
$r3$.ɵɵelementEnd();
}
}

12 changes: 9 additions & 3 deletions packages/compiler/src/template/pipeline/src/ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ function ingestElement(unit: ViewCompilationUnit, element: t.Element): void {

ingestBindings(unit, startOp, element);
ingestReferences(startOp, element);

// Start i18n, if needed, goes after the element create and bindings, but before the nodes
let i18nBlockId: ir.XrefId|null = null;
if (element.i18n instanceof i18n.Message) {
i18nBlockId = unit.job.allocateXrefId();
unit.create.push(ir.createI18nStartOp(i18nBlockId, element.i18n));
}

ingestNodes(unit, element.children);

// The source span for the end op is typically the element closing tag. However, if no closing tag
Expand All @@ -178,9 +186,7 @@ function ingestElement(unit: ViewCompilationUnit, element: t.Element): void {
unit.create.push(endOp);

// If there is an i18n message associated with this element, insert i18n start and end ops.
if (element.i18n instanceof i18n.Message) {
const i18nBlockId = unit.job.allocateXrefId();
ir.OpList.insertAfter<ir.CreateOp>(ir.createI18nStartOp(i18nBlockId, element.i18n), startOp);
if (i18nBlockId !== null) {
ir.OpList.insertBefore<ir.CreateOp>(ir.createI18nEndOp(i18nBlockId), endOp);
}
}
Expand Down

0 comments on commit b6f03f2

Please sign in to comment.