fix(ivy): avoid unnecessary i18n instructions generation for <ng-template> with structural directives (#32623)
If an <ng-template> contains a structural directive (for example *ngIf), Ngtsc generates extra template function with 1 template instruction call. When <ng-template> tag also contains i18n attribute on it, we generate i18nStart and i18nEnd instructions around it, which is unnecessary and breaking runtime. This commit adds a logic to make sure we do not generate i18n instructions in case only `template` is present. PR Close #32623
This commit is contained in:

committed by
Kara Erickson

parent
0477bfc8ed
commit
5328bb223a
@ -301,6 +301,17 @@ onlyInIvy('Ivy i18n logic')
|
||||
expect(element).toHaveText('Bonjour Angular');
|
||||
});
|
||||
|
||||
// Note: applying structural directives to <ng-template> is typically user error, but it
|
||||
// is technically allowed, so we need to support it.
|
||||
it('should handle structural directives on ng-template', () => {
|
||||
loadTranslations({'Hello {$INTERPOLATION}': 'Bonjour {$INTERPOLATION}'});
|
||||
const fixture = initWithTemplate(
|
||||
AppComp, `<ng-template *ngIf="name" i18n tplRef>Hello {{ name }}</ng-template>`);
|
||||
|
||||
const element = fixture.nativeElement;
|
||||
expect(element).toHaveText('Bonjour Angular');
|
||||
});
|
||||
|
||||
it('should be able to act as child elements inside i18n block (plain text content)', () => {
|
||||
loadTranslations({
|
||||
|
||||
|
Reference in New Issue
Block a user