fix(compiler): avoid generating i18n attributes in plain form (#36422)

Prior to this change, there was a problem while matching template attributes, which mistakenly took i18n attributes (that might be present in attrs array after template ones) into account. This commit updates the logic to avoid template attribute matching logic from entering the i18n section and as a result this also allows generating proper i18n attributes sections instead of keeping these attribute in plain form (with their values) in attribute arrays.

PR Close #36422
This commit is contained in:
Andrew Kushnir
2020-04-03 12:58:20 -07:00
committed by atscott
parent 1d4af3f734
commit 08b8b51486
6 changed files with 54 additions and 20 deletions

View File

@ -337,8 +337,6 @@ describe('i18n support in the template compiler', () => {
<ng-template i18n-title title="Hello"></ng-template>
`;
// TODO (FW-1942): update the code to avoid adding `title` attribute in plain form
// into the `consts` array on Component def.
const output = String.raw`
var $I18N_0$;
if (typeof ngI18nClosureMode !== "undefined" && ngI18nClosureMode) {
@ -350,7 +348,7 @@ describe('i18n support in the template compiler', () => {
}
const $_c2$ = ["title", $I18N_0$];
consts: [["title", "Hello"]],
consts: [[${AttributeMarker.I18n}, "title"]],
template: function MyComponent_Template(rf, ctx) {
if (rf & 1) {
$r3$.ɵɵtemplate(0, MyComponent_ng_template_0_Template, 0, 0, "ng-template", 0);
@ -367,8 +365,6 @@ describe('i18n support in the template compiler', () => {
<ng-template *ngIf="visible" i18n-title title="Hello">Test</ng-template>
`;
// TODO (FW-1942): update the code to avoid adding `title` attribute in plain form
// into the `consts` array on Component def.
const output = String.raw`
var $I18N_0$;
if (typeof ngI18nClosureMode !== "undefined" && ngI18nClosureMode) {
@ -391,7 +387,7 @@ describe('i18n support in the template compiler', () => {
}
}
consts: [[${AttributeMarker.Template}, "ngIf"], ["title", "Hello"]],
consts: [[${AttributeMarker.Template}, "ngIf"], [${AttributeMarker.I18n}, "title"]],
template: function MyComponent_Template(rf, ctx) {
if (rf & 1) {
$r3$.ɵɵtemplate(0, MyComponent_0_Template, 2, 0, undefined, 0);