Skip to content

Commit 38aab6a

Browse files
mmalerbathePunderWoman
authored andcommitted
refactor(compiler): Handle trailing spaces in ICU placeholders (#52698)
In some cases ICU expression placeholders may have trailing spaces that need to be trimmed when matching the placeholder to its corresponding text binding. PR Close #52698
1 parent 12ffb25 commit 38aab6a

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/icu_logic/TEST_CASES.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@
222222
"verifyUniqueConsts"
223223
]
224224
}
225-
],
226-
"skipForTemplatePipeline": true
225+
]
227226
},
228227
{
229228
"description": "should produce proper messages when `select` or `plural` keywords have spaces after them",
@@ -237,8 +236,7 @@
237236
"verifyUniqueConsts"
238237
]
239238
}
240-
],
241-
"skipForTemplatePipeline": true
239+
]
242240
}
243241
]
244242
}

packages/compiler/src/template/pipeline/src/ingest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ function ingestIcu(unit: ViewCompilationUnit, icu: t.Icu) {
492492
const xref = unit.job.allocateXrefId();
493493
const icuNode = icu.i18n.nodes[0];
494494
unit.create.push(ir.createIcuStartOp(xref, icu.i18n, icuFromI18nMessage(icu.i18n).name, null!));
495-
const {expressionPlaceholder} = icuNode;
495+
const expressionPlaceholder = icuNode.expressionPlaceholder?.trimEnd();
496496
if (expressionPlaceholder === undefined || icu.vars[expressionPlaceholder] === undefined) {
497497
throw Error('ICU should have a text binding');
498498
}

packages/compiler/src/template/pipeline/src/phases/i18n_const_collection.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,14 @@ function i18nGenerateClosureVar(
204204
* Asserts that all of the message's placeholders have values.
205205
*/
206206
function assertAllParamsResolved(op: ir.I18nMessageOp): asserts op is ir.I18nMessageOp {
207-
for (const placeholder in op.message.placeholders) {
207+
for (let placeholder in op.message.placeholders) {
208+
placeholder = placeholder.trimEnd();
208209
if (!op.params.has(placeholder) && !op.postprocessingParams.has(placeholder)) {
209210
throw Error(`Failed to resolve i18n placeholder: ${placeholder}`);
210211
}
211212
}
212-
for (const placeholder in op.message.placeholderToMessage) {
213+
for (let placeholder in op.message.placeholderToMessage) {
214+
placeholder = placeholder.trimEnd();
213215
if (!op.params.has(placeholder) && !op.postprocessingParams.has(placeholder)) {
214216
throw Error(`Failed to resolve i18n message placeholder: ${placeholder}`);
215217
}

0 commit comments

Comments
 (0)