From 70fe5e60b36a10be7684c27bff138ec1801e7943 Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Wed, 8 Nov 2023 10:50:12 -0800 Subject: [PATCH] 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 --- .../r3_view_compiler_i18n/icu_logic/TEST_CASES.json | 6 ++---- packages/compiler/src/template/pipeline/src/ingest.ts | 2 +- .../template/pipeline/src/phases/i18n_const_collection.ts | 6 ++++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/icu_logic/TEST_CASES.json b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/icu_logic/TEST_CASES.json index c4e48e6e789f5..595a262081e57 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/icu_logic/TEST_CASES.json +++ b/packages/compiler-cli/test/compliance/test_cases/r3_view_compiler_i18n/icu_logic/TEST_CASES.json @@ -222,8 +222,7 @@ "verifyUniqueConsts" ] } - ], - "skipForTemplatePipeline": true + ] }, { "description": "should produce proper messages when `select` or `plural` keywords have spaces after them", @@ -237,8 +236,7 @@ "verifyUniqueConsts" ] } - ], - "skipForTemplatePipeline": true + ] } ] } diff --git a/packages/compiler/src/template/pipeline/src/ingest.ts b/packages/compiler/src/template/pipeline/src/ingest.ts index 78caea7c08449..fd5a2bfd5ddf2 100644 --- a/packages/compiler/src/template/pipeline/src/ingest.ts +++ b/packages/compiler/src/template/pipeline/src/ingest.ts @@ -492,7 +492,7 @@ function ingestIcu(unit: ViewCompilationUnit, icu: t.Icu) { const xref = unit.job.allocateXrefId(); const icuNode = icu.i18n.nodes[0]; unit.create.push(ir.createIcuStartOp(xref, icu.i18n, icuFromI18nMessage(icu.i18n).name, null!)); - const {expressionPlaceholder} = icuNode; + const expressionPlaceholder = icuNode.expressionPlaceholder?.trimEnd(); if (expressionPlaceholder === undefined || icu.vars[expressionPlaceholder] === undefined) { throw Error('ICU should have a text binding'); } diff --git a/packages/compiler/src/template/pipeline/src/phases/i18n_const_collection.ts b/packages/compiler/src/template/pipeline/src/phases/i18n_const_collection.ts index 43606ed3fa389..a6677033907e3 100644 --- a/packages/compiler/src/template/pipeline/src/phases/i18n_const_collection.ts +++ b/packages/compiler/src/template/pipeline/src/phases/i18n_const_collection.ts @@ -204,12 +204,14 @@ function i18nGenerateClosureVar( * Asserts that all of the message's placeholders have values. */ function assertAllParamsResolved(op: ir.I18nMessageOp): asserts op is ir.I18nMessageOp { - for (const placeholder in op.message.placeholders) { + for (let placeholder in op.message.placeholders) { + placeholder = placeholder.trimEnd(); if (!op.params.has(placeholder) && !op.postprocessingParams.has(placeholder)) { throw Error(`Failed to resolve i18n placeholder: ${placeholder}`); } } - for (const placeholder in op.message.placeholderToMessage) { + for (let placeholder in op.message.placeholderToMessage) { + placeholder = placeholder.trimEnd(); if (!op.params.has(placeholder) && !op.postprocessingParams.has(placeholder)) { throw Error(`Failed to resolve i18n message placeholder: ${placeholder}`); }