@@ -18,6 +18,7 @@ import {serializeIcuNode} from '../../../src/render3/view/i18n/icu_serializer';
1818import { serializeI18nMessageForLocalize } from '../../../src/render3/view/i18n/localize_utils' ;
1919import { I18nMeta , parseI18nMeta } from '../../../src/render3/view/i18n/meta' ;
2020import { formatI18nPlaceholderName } from '../../../src/render3/view/i18n/util' ;
21+ import { LEADING_TRIVIA_CHARS } from '../../../src/render3/view/template' ;
2122
2223import { parseR3 as parse } from './util' ;
2324
@@ -355,7 +356,7 @@ describe('serializeI18nMessageForGetMsg', () => {
355356
356357describe ( 'serializeI18nMessageForLocalize' , ( ) => {
357358 const serialize = ( input : string ) => {
358- const tree = parse ( `<div i18n>${ input } </div>` ) ;
359+ const tree = parse ( `<div i18n>${ input } </div>` , { leadingTriviaChars : LEADING_TRIVIA_CHARS } ) ;
359360 const root = tree . nodes [ 0 ] as t . Element ;
360361 return serializeI18nMessageForLocalize ( root . i18n as i18n . Message ) ;
361362 } ;
@@ -446,7 +447,7 @@ describe('serializeI18nMessageForLocalize', () => {
446447 expect ( messageParts [ 3 ] . text ) . toEqual ( '' ) ;
447448 expect ( messageParts [ 3 ] . sourceSpan . toString ( ) ) . toEqual ( '' ) ;
448449 expect ( messageParts [ 4 ] . text ) . toEqual ( ' D' ) ;
449- expect ( messageParts [ 4 ] . sourceSpan . toString ( ) ) . toEqual ( ' D' ) ;
450+ expect ( messageParts [ 4 ] . sourceSpan . toString ( ) ) . toEqual ( 'D' ) ;
450451
451452 expect ( placeHolders [ 0 ] . text ) . toEqual ( 'START_TAG_SPAN' ) ;
452453 expect ( placeHolders [ 0 ] . sourceSpan . toString ( ) ) . toEqual ( '<span>' ) ;
@@ -478,6 +479,26 @@ describe('serializeI18nMessageForLocalize', () => {
478479 expect ( humanizeSourceSpan ( placeHolders [ 2 ] . sourceSpan ) ) . toEqual ( '"</b>" (22-26)' ) ;
479480 } ) ;
480481
482+ it ( 'should create the correct placeholder source-spans when there is skipped leading whitespace' ,
483+ ( ) => {
484+ const { messageParts, placeHolders} = serialize ( '<b> {{value}}</b>' ) ;
485+ expect ( messageParts [ 0 ] . text ) . toEqual ( '' ) ;
486+ expect ( humanizeSourceSpan ( messageParts [ 0 ] . sourceSpan ) ) . toEqual ( '"" (10-10)' ) ;
487+ expect ( messageParts [ 1 ] . text ) . toEqual ( ' ' ) ;
488+ expect ( humanizeSourceSpan ( messageParts [ 1 ] . sourceSpan ) ) . toEqual ( '" " (13-16)' ) ;
489+ expect ( messageParts [ 2 ] . text ) . toEqual ( '' ) ;
490+ expect ( humanizeSourceSpan ( messageParts [ 2 ] . sourceSpan ) ) . toEqual ( '"" (25-25)' ) ;
491+ expect ( messageParts [ 3 ] . text ) . toEqual ( '' ) ;
492+ expect ( humanizeSourceSpan ( messageParts [ 3 ] . sourceSpan ) ) . toEqual ( '"" (29-29)' ) ;
493+
494+ expect ( placeHolders [ 0 ] . text ) . toEqual ( 'START_BOLD_TEXT' ) ;
495+ expect ( humanizeSourceSpan ( placeHolders [ 0 ] . sourceSpan ) ) . toEqual ( '"<b> " (10-16)' ) ;
496+ expect ( placeHolders [ 1 ] . text ) . toEqual ( 'INTERPOLATION' ) ;
497+ expect ( humanizeSourceSpan ( placeHolders [ 1 ] . sourceSpan ) ) . toEqual ( '"{{value}}" (16-25)' ) ;
498+ expect ( placeHolders [ 2 ] . text ) . toEqual ( 'CLOSE_BOLD_TEXT' ) ;
499+ expect ( humanizeSourceSpan ( placeHolders [ 2 ] . sourceSpan ) ) . toEqual ( '"</b>" (25-29)' ) ;
500+ } ) ;
501+
481502 it ( 'should serialize simple ICU for `$localize()`' , ( ) => {
482503 expect ( serialize ( '{age, plural, 10 {ten} other {other}}' ) ) . toEqual ( {
483504 messageParts : [ literal ( '{VAR_PLURAL, plural, 10 {ten} other {other}}' ) ] ,
0 commit comments