@@ -18,6 +18,7 @@ import {serializeIcuNode} from '../../../src/render3/view/i18n/icu_serializer';
18
18
import { serializeI18nMessageForLocalize } from '../../../src/render3/view/i18n/localize_utils' ;
19
19
import { I18nMeta , parseI18nMeta } from '../../../src/render3/view/i18n/meta' ;
20
20
import { formatI18nPlaceholderName } from '../../../src/render3/view/i18n/util' ;
21
+ import { LEADING_TRIVIA_CHARS } from '../../../src/render3/view/template' ;
21
22
22
23
import { parseR3 as parse } from './util' ;
23
24
@@ -355,7 +356,7 @@ describe('serializeI18nMessageForGetMsg', () => {
355
356
356
357
describe ( 'serializeI18nMessageForLocalize' , ( ) => {
357
358
const serialize = ( input : string ) => {
358
- const tree = parse ( `<div i18n>${ input } </div>` ) ;
359
+ const tree = parse ( `<div i18n>${ input } </div>` , { leadingTriviaChars : LEADING_TRIVIA_CHARS } ) ;
359
360
const root = tree . nodes [ 0 ] as t . Element ;
360
361
return serializeI18nMessageForLocalize ( root . i18n as i18n . Message ) ;
361
362
} ;
@@ -446,7 +447,7 @@ describe('serializeI18nMessageForLocalize', () => {
446
447
expect ( messageParts [ 3 ] . text ) . toEqual ( '' ) ;
447
448
expect ( messageParts [ 3 ] . sourceSpan . toString ( ) ) . toEqual ( '' ) ;
448
449
expect ( messageParts [ 4 ] . text ) . toEqual ( ' D' ) ;
449
- expect ( messageParts [ 4 ] . sourceSpan . toString ( ) ) . toEqual ( ' D' ) ;
450
+ expect( messageParts [ 4 ] . sourceSpan . toString ( ) ) . toEqual ( 'D' ) ;
450
451
451
452
expect ( placeHolders [ 0 ] . text ) . toEqual ( 'START_TAG_SPAN' ) ;
452
453
expect ( placeHolders [ 0 ] . sourceSpan . toString ( ) ) . toEqual ( '<span>' ) ;
@@ -478,6 +479,26 @@ describe('serializeI18nMessageForLocalize', () => {
478
479
expect ( humanizeSourceSpan ( placeHolders [ 2 ] . sourceSpan ) ) . toEqual ( '"</b>" (22-26)' ) ;
479
480
} ) ;
480
481
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
+
481
502
it ( 'should serialize simple ICU for `$localize()`' , ( ) => {
482
503
expect ( serialize ( '{age, plural, 10 {ten} other {other}}' ) ) . toEqual ( {
483
504
messageParts : [ literal ( '{VAR_PLURAL, plural, 10 {ten} other {other}}' ) ] ,
0 commit comments