@@ -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
@@ -386,7 +387,7 @@ describe('serializeI18nMessageForGetMsg', () => {
386387
387388describe ( 'serializeI18nMessageForLocalize' , ( ) => {
388389 const serialize = ( input : string ) => {
389- const tree = parse ( `<div i18n>${ input } </div>` ) ;
390+ const tree = parse ( `<div i18n>${ input } </div>` , { leadingTriviaChars : LEADING_TRIVIA_CHARS } ) ;
390391 const root = tree . nodes [ 0 ] as t . Element ;
391392 return serializeI18nMessageForLocalize ( root . i18n as i18n . Message ) ;
392393 } ;
@@ -477,7 +478,7 @@ describe('serializeI18nMessageForLocalize', () => {
477478 expect ( messageParts [ 3 ] . text ) . toEqual ( '' ) ;
478479 expect ( messageParts [ 3 ] . sourceSpan . toString ( ) ) . toEqual ( '' ) ;
479480 expect ( messageParts [ 4 ] . text ) . toEqual ( ' D' ) ;
480- expect ( messageParts [ 4 ] . sourceSpan . toString ( ) ) . toEqual ( ' D' ) ;
481+ expect ( messageParts [ 4 ] . sourceSpan . toString ( ) ) . toEqual ( 'D' ) ;
481482
482483 expect ( placeHolders [ 0 ] . text ) . toEqual ( 'START_TAG_SPAN' ) ;
483484 expect ( placeHolders [ 0 ] . sourceSpan . toString ( ) ) . toEqual ( '<span>' ) ;
@@ -509,6 +510,26 @@ describe('serializeI18nMessageForLocalize', () => {
509510 expect ( humanizeSourceSpan ( placeHolders [ 2 ] . sourceSpan ) ) . toEqual ( '"</b>" (22-26)' ) ;
510511 } ) ;
511512
513+ it ( 'should create the correct placeholder source-spans when there is skipped leading whitespace' ,
514+ ( ) => {
515+ const { messageParts, placeHolders} = serialize ( '<b> {{value}}</b>' ) ;
516+ expect ( messageParts [ 0 ] . text ) . toEqual ( '' ) ;
517+ expect ( humanizeSourceSpan ( messageParts [ 0 ] . sourceSpan ) ) . toEqual ( '"" (10-10)' ) ;
518+ expect ( messageParts [ 1 ] . text ) . toEqual ( ' ' ) ;
519+ expect ( humanizeSourceSpan ( messageParts [ 1 ] . sourceSpan ) ) . toEqual ( '" " (13-16)' ) ;
520+ expect ( messageParts [ 2 ] . text ) . toEqual ( '' ) ;
521+ expect ( humanizeSourceSpan ( messageParts [ 2 ] . sourceSpan ) ) . toEqual ( '"" (25-25)' ) ;
522+ expect ( messageParts [ 3 ] . text ) . toEqual ( '' ) ;
523+ expect ( humanizeSourceSpan ( messageParts [ 3 ] . sourceSpan ) ) . toEqual ( '"" (29-29)' ) ;
524+
525+ expect ( placeHolders [ 0 ] . text ) . toEqual ( 'START_BOLD_TEXT' ) ;
526+ expect ( humanizeSourceSpan ( placeHolders [ 0 ] . sourceSpan ) ) . toEqual ( '"<b> " (10-16)' ) ;
527+ expect ( placeHolders [ 1 ] . text ) . toEqual ( 'INTERPOLATION' ) ;
528+ expect ( humanizeSourceSpan ( placeHolders [ 1 ] . sourceSpan ) ) . toEqual ( '"{{value}}" (16-25)' ) ;
529+ expect ( placeHolders [ 2 ] . text ) . toEqual ( 'CLOSE_BOLD_TEXT' ) ;
530+ expect ( humanizeSourceSpan ( placeHolders [ 2 ] . sourceSpan ) ) . toEqual ( '"</b>" (25-29)' ) ;
531+ } ) ;
532+
512533 it ( 'should serialize simple ICU for `$localize()`' , ( ) => {
513534 expect ( serialize ( '{age, plural, 10 {ten} other {other}}' ) ) . toEqual ( {
514535 messageParts : [ literal ( '{VAR_PLURAL, plural, 10 {ten} other {other}}' ) ] ,
0 commit comments