Skip to content

Commit cfde36d

Browse files
vicbmatsko
authored andcommitted
fix(compiler): generate constant array for i18n attributes (#23837)
PR Close #23837
1 parent d889f57 commit cfde36d

File tree

3 files changed

+9
-20
lines changed

3 files changed

+9
-20
lines changed

packages/compiler/src/constant_pool.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,9 @@ class KeyVisitor implements o.ExpressionVisitor {
295295
`EX:${ast.value.runtime.name}`;
296296
}
297297

298+
visitReadVarExpr(node: o.ReadVarExpr) { return `VAR:${node.name}`; }
299+
298300
visitWrappedNodeExpr = invalid;
299-
visitReadVarExpr = invalid;
300301
visitWriteVarExpr = invalid;
301302
visitWriteKeyExpr = invalid;
302303
visitWritePropExpr = invalid;

packages/compiler/src/render3/view/template.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,11 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
257257
// Add the attributes
258258
const i18nMessages: o.Statement[] = [];
259259
const attributes: o.Expression[] = [];
260-
let hasI18nAttr = false;
261260

262261
Object.getOwnPropertyNames(outputAttrs).forEach(name => {
263262
const value = outputAttrs[name];
264263
attributes.push(o.literal(name));
265264
if (attrI18nMetas.hasOwnProperty(name)) {
266-
hasI18nAttr = true;
267265
const meta = parseI18nMeta(attrI18nMetas[name]);
268266
const variable = this.constantPool.getTranslation(value, meta);
269267
attributes.push(variable);
@@ -272,13 +270,9 @@ export class TemplateDefinitionBuilder implements t.Visitor<void>, LocalResolver
272270
}
273271
});
274272

275-
let attrArg: o.Expression = o.TYPED_NULL_EXPR;
276-
277-
if (attributes.length > 0) {
278-
attrArg = hasI18nAttr ? getLiteralFactory(this.constantPool, o.literalArr(attributes)) :
279-
this.constantPool.getConstLiteral(o.literalArr(attributes), true);
280-
}
281-
273+
const attrArg: o.Expression = attributes.length > 0 ?
274+
this.constantPool.getConstLiteral(o.literalArr(attributes), true) :
275+
o.TYPED_NULL_EXPR;
282276
parameters.push(attrArg);
283277

284278
if (element.references && element.references.length > 0) {

packages/compiler/test/render3/r3_view_compiler_i18n_spec.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ describe('i18n support in the view compiler', () => {
9393
* @desc desc
9494
*/
9595
const $msg_1$ = goog.getMsg('introduction');
96-
97-
const $c1$ = ($a1$:any) => {
98-
return ['title', $a1$];
99-
};
96+
const $c1$ = ['title', $msg_1$];
10097
10198
/**
10299
* @desc desc
@@ -106,7 +103,7 @@ describe('i18n support in the view compiler', () => {
106103
107104
template: function MyComponent_Template(rf: IDENT, ctx: IDENT) {
108105
if (rf & 1) {
109-
$r3$.ɵE(0, 'div', $r3$.ɵf1($c1$, $msg_1$));
106+
$r3$.ɵE(0, 'div', $c1$);
110107
$r3$.ɵT(1, $msg_2$);
111108
$r3$.ɵe();
112109
}
@@ -147,14 +144,11 @@ describe('i18n support in the view compiler', () => {
147144
* @meaning m
148145
*/
149146
const $msg_1$ = goog.getMsg('introduction');
150-
151-
const $c1$ = ($a1$:any) => {
152-
return ['id', 'static', 'title', $a1$];
153-
};
147+
const $c1$ = ['id', 'static', 'title', $msg_1$];
154148
155149
template: function MyComponent_Template(rf: IDENT, ctx: IDENT) {
156150
if (rf & 1) {
157-
$r3$.ɵE(0, 'div', $r3$.ɵf1($c1$, $msg_1$));
151+
$r3$.ɵE(0, 'div', $c1$);
158152
$r3$.ɵe();
159153
}
160154
}

0 commit comments

Comments
 (0)