From 0d4f8c7dd9d40ca81e8f648df7f90164e51b337c Mon Sep 17 00:00:00 2001 From: Olivier Combe Date: Tue, 4 Jun 2019 15:04:38 +0200 Subject: [PATCH] fix(ivy): allow empty cases for ICU expressions (#30846) We used to ignore empty strings for optimization purposes, but it turns out that empty strings are also valid values for ICU cases and we shouldn't ignore those. FW-1290 #resolve PR Close #30846 --- packages/core/src/render3/i18n.ts | 9 +++------ packages/core/test/acceptance/i18n_spec.ts | 7 +++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/core/src/render3/i18n.ts b/packages/core/src/render3/i18n.ts index ae8008fafe..e3291dcfa8 100644 --- a/packages/core/src/render3/i18n.ts +++ b/packages/core/src/render3/i18n.ts @@ -123,7 +123,7 @@ function extractParts(pattern: string): (string | IcuExpression)[] { const block = pattern.substring(prevPos, pos); if (ICU_BLOCK_REGEXP.test(block)) { results.push(parseICUBlock(block)); - } else if (block) { // Don't push empty strings + } else { results.push(block); } @@ -140,10 +140,7 @@ function extractParts(pattern: string): (string | IcuExpression)[] { } const substring = pattern.substring(prevPos); - if (substring != '') { - results.push(substring); - } - + results.push(substring); return results; } @@ -182,7 +179,7 @@ function parseICUBlock(pattern: string): IcuExpression { } const blocks = extractParts(parts[pos++]) as string[]; - if (blocks.length) { + if (cases.length > values.length) { values.push(blocks); } } diff --git a/packages/core/test/acceptance/i18n_spec.ts b/packages/core/test/acceptance/i18n_spec.ts index a71d17304c..4e9bc759b5 100644 --- a/packages/core/test/acceptance/i18n_spec.ts +++ b/packages/core/test/acceptance/i18n_spec.ts @@ -618,6 +618,13 @@ onlyInIvy('Ivy i18n logic').describe('runtime i18n', () => { expect(fixture.nativeElement.innerHTML).toContain('at least'); }); + + it('with empty values', () => { + const fixture = initWithTemplate(AppComp, `{count, select, 10 {} 20 {twenty} other {other}}`); + + const element = fixture.nativeElement; + expect(element).toHaveText('other'); + }); }); describe('should support attributes', () => {