Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef75875

Browse files
AndrewKushniratscott
authored andcommitted
fix(core): handle <ng-template> with local refs in i18n blocks (#35758)
This commit extends the range of tNode types that may have local refs to include `TNodeType.Container` to account for `<ng-template>`s. Original changes in #33415 didn't include that type and as a result, an error is thrown at runtime in case an i18n block contains an `<ng-template>` with local refs. PR Close #35758
1 parent 4003538 commit ef75875

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

‎packages/core/src/render3/i18n.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,8 @@ function i18nEndFirstPass(tView: TView, lView: LView) {
701701
}
702702
// Check if an element has any local refs and skip them
703703
const tNode = getTNode(tView, index);
704-
if (tNode && (tNode.type === TNodeType.Element || tNode.type === TNodeType.ElementContainer) &&
704+
if (tNode && (tNode.type === TNodeType.Container || tNode.type === TNodeType.Element ||
705+
tNode.type === TNodeType.ElementContainer) &&
705706
tNode.localNames !== null) {
706707
// Divide by 2 to get the number of local refs,
707708
// since they are stored as an array that also includes directive indexes,

‎packages/core/test/acceptance/i18n_spec.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,28 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => {
299299
[computeMsgId(
300300
'{$START_TAG_NG_CONTAINER} One {$CLOSE_TAG_NG_CONTAINER}' +
301301
'{$START_TAG_DIV} Two {$CLOSE_TAG_DIV}' +
302-
'{$START_TAG_SPAN} Three {$CLOSE_TAG_SPAN}')]:
302+
'{$START_TAG_SPAN} Three {$CLOSE_TAG_SPAN}' +
303+
'{$START_TAG_NG_TEMPLATE} Four {$CLOSE_TAG_NG_TEMPLATE}' +
304+
'{$START_TAG_NG_CONTAINER_1}{$CLOSE_TAG_NG_CONTAINER}')]:
305+
303306
'{$START_TAG_NG_CONTAINER} Une {$CLOSE_TAG_NG_CONTAINER}' +
304307
'{$START_TAG_DIV} Deux {$CLOSE_TAG_DIV}' +
305-
'{$START_TAG_SPAN} Trois {$CLOSE_TAG_SPAN}'
308+
'{$START_TAG_SPAN} Trois {$CLOSE_TAG_SPAN}' +
309+
'{$START_TAG_NG_TEMPLATE} Quatre {$CLOSE_TAG_NG_TEMPLATE}' +
310+
'{$START_TAG_NG_CONTAINER_1}{$CLOSE_TAG_NG_CONTAINER}'
311+
306312
});
307313
const fixture = initWithTemplate(AppComp, `
308314
<div i18n>
309315
<ng-container #localRefA> One </ng-container>
310316
<div #localRefB> Two </div>
311317
<span #localRefC> Three </span>
318+
319+
<ng-template #localRefD> Four </ng-template>
320+
<ng-container *ngTemplateOutlet="localRefD"></ng-container>
312321
</div>
313322
`);
314-
expect(fixture.nativeElement.textContent).toBe(' Une Deux Trois ');
323+
expect(fixture.nativeElement.textContent).toBe(' Une Deux Trois Quatre ');
315324
});
316325

317326
it('should handle local refs correctly in case an element is removed in translation', () => {

0 commit comments

Comments
 (0)