Skip to content

Commit

Permalink
fix(ivy): allow empty cases for ICU expressions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ocombe committed Jun 4, 2019
1 parent 8154433 commit 276702f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 3 additions & 6 deletions packages/core/src/render3/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,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);
}

Expand All @@ -138,10 +138,7 @@ function extractParts(pattern: string): (string | IcuExpression)[] {
}

const substring = pattern.substring(prevPos);
if (substring != '') {
results.push(substring);
}

results.push(substring);
return results;
}

Expand Down Expand Up @@ -180,7 +177,7 @@ function parseICUBlock(pattern: string): IcuExpression {
}

const blocks = extractParts(parts[pos++]) as string[];
if (blocks.length) {
if (cases.length > values.length) {
values.push(blocks);
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/core/test/acceptance/i18n_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 276702f

Please sign in to comment.