diff --git a/packages/compiler/src/render3/view/i18n/localize_utils.ts b/packages/compiler/src/render3/view/i18n/localize_utils.ts index 444139ecac..b57593e4d8 100644 --- a/packages/compiler/src/render3/view/i18n/localize_utils.ts +++ b/packages/compiler/src/render3/view/i18n/localize_utils.ts @@ -120,7 +120,7 @@ function processMessagePieces(pieces: o.MessagePiece[]): placeHolders.push(part); if (pieces[i - 1] instanceof o.PlaceholderPiece) { // There were two placeholders in a row, so we need to add an empty message part. - messageParts.push(createEmptyMessagePart(part.sourceSpan.end)); + messageParts.push(createEmptyMessagePart(pieces[i - 1].sourceSpan.end)); } } } diff --git a/packages/compiler/test/render3/view/i18n_spec.ts b/packages/compiler/test/render3/view/i18n_spec.ts index 2ed1dba0f7..2e8ca157b6 100644 --- a/packages/compiler/test/render3/view/i18n_spec.ts +++ b/packages/compiler/test/render3/view/i18n_spec.ts @@ -489,6 +489,26 @@ describe('serializeI18nMessageForLocalize', () => { expect(placeHolders[3].sourceSpan.toString()).toEqual(''); }); + it('should create the correct source-spans when there are two placeholders next to each other', + () => { + const {messageParts, placeHolders} = serialize('{{value}}'); + expect(messageParts[0].text).toEqual(''); + expect(humanizeSourceSpan(messageParts[0].sourceSpan)).toEqual('"" (10-10)'); + expect(messageParts[1].text).toEqual(''); + expect(humanizeSourceSpan(messageParts[1].sourceSpan)).toEqual('"" (13-13)'); + expect(messageParts[2].text).toEqual(''); + expect(humanizeSourceSpan(messageParts[2].sourceSpan)).toEqual('"" (22-22)'); + expect(messageParts[3].text).toEqual(''); + expect(humanizeSourceSpan(messageParts[3].sourceSpan)).toEqual('"" (26-26)'); + + expect(placeHolders[0].text).toEqual('START_BOLD_TEXT'); + expect(humanizeSourceSpan(placeHolders[0].sourceSpan)).toEqual('"" (10-13)'); + expect(placeHolders[1].text).toEqual('INTERPOLATION'); + expect(humanizeSourceSpan(placeHolders[1].sourceSpan)).toEqual('"{{value}}" (13-22)'); + expect(placeHolders[2].text).toEqual('CLOSE_BOLD_TEXT'); + expect(humanizeSourceSpan(placeHolders[2].sourceSpan)).toEqual('"" (22-26)'); + }); + it('should serialize simple ICU for `$localize()`', () => { expect(serialize('{age, plural, 10 {ten} other {other}}')).toEqual({ messageParts: [literal('{VAR_PLURAL, plural, 10 {ten} other {other}}')], @@ -496,7 +516,6 @@ describe('serializeI18nMessageForLocalize', () => { }); }); - it('should serialize nested ICUs for `$localize()`', () => { expect(serialize( '{age, plural, 10 {ten {size, select, 1 {one} 2 {two} other {2+}}} other {other}}')) @@ -509,7 +528,6 @@ describe('serializeI18nMessageForLocalize', () => { }); }); - it('should serialize ICU with embedded HTML for `$localize()`', () => { expect(serialize('{age, plural, 10 {ten} other {