-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): avoid duplicate i18n blocks for i18n attrs on elements…
… with structural directives (#40077) Currently when `ɵɵtemplate` and `ɵɵelement` instructions are generated by compiler, all static attributes are duplicated for both instructions. As a part of this duplication, i18n translation blocks for static i18n attributes are generated twice as well, causing duplicate entries in extracted translation files (when Ivy extraction mechanisms are used). This commit fixes this issue by introducing a cache for i18n translation blocks (for static attributes only). Also this commit further aligns `ɵɵtemplate` and `ɵɵelement` instruction attributes, which should help implement more effective attributes deduplication logic. Closes #39942. PR Close #40077
- Loading branch information
1 parent
245dccc
commit caa4666
Showing
6 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...iance/test_cases/r3_view_compiler_i18n/element_attributes/static_attributes_structural.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function MyComponent_div_0_Template(rf, ctx) { | ||
if (rf & 1) { | ||
$r3$.ɵɵelement(0, "div", 1); | ||
} | ||
} | ||
… | ||
consts: function() { | ||
__i18nMsg__('introduction', [], {meaning: 'm', desc: 'd'}) | ||
return [ | ||
["id", "static", "title", $i18n_0$, __AttributeMarker.Template__, "ngIf"], | ||
["id", "static", "title", $i18n_0$] | ||
]; | ||
}, | ||
template: function MyComponent_Template(rf, ctx) { | ||
if (rf & 1) { | ||
$r3$.ɵɵtemplate(0, MyComponent_div_0_Template, 1, 0, "div", 0); | ||
} | ||
if (rf & 2) { | ||
$r3$.ɵɵproperty("ngIf", ctx.exp); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...iance/test_cases/r3_view_compiler_i18n/element_attributes/static_attributes_structural.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {Component, NgModule} from '@angular/core'; | ||
|
||
@Component({ | ||
selector: 'my-component', | ||
template: ` | ||
<div *ngIf="exp" id="static" i18n-title="m|d" title="introduction"></div> | ||
` | ||
}) | ||
export class MyComponent { | ||
exp = true; | ||
} | ||
|
||
@NgModule({declarations: [MyComponent]}) | ||
export class MyModule { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters