@@ -426,6 +426,37 @@ describe('Extend', () => {
426
426
return init ( page3 , { strict : false } )
427
427
. then ( html => expect ( html ) . toBe ( want ) ) ;
428
428
} ) ;
429
+
430
+ /*
431
+ This plugin merges the locals from options.expressions.locals and the
432
+ "locals" attribute into the options.expressions.locals property. Arrays in
433
+ the attribute locals will be copied into options.expressions.locals and when
434
+ the plugin is called again they will be merged again, doubling all array
435
+ entries every time the plugin is called.
436
+ */
437
+ it ( 'should not pollute options.expression.locals ' , async ( ) => {
438
+ mfs . writeFileSync ( './base.html' , `<div class="base">{{ list.join(", ") }}</div>` ) ;
439
+
440
+ const options = {
441
+ expressions : {
442
+ locals : { }
443
+ }
444
+ } ;
445
+
446
+ const preHtml = `
447
+ <extends src="base.html" locals='{"list": ["One", "Two", "Three"]}'>
448
+ </extends>
449
+ ` ;
450
+ const postHtml = `<div class="base">One, Two, Three</div>` ;
451
+
452
+ expect ( await init ( preHtml , options ) ) . toBe ( postHtml ) ;
453
+ expect ( options . expressions . locals ) . toStrictEqual ( { } ) ;
454
+ /*
455
+ Since the entries in "list" have been merged with themselves, the content
456
+ would be "One, Two, Three, One, Two, Three"
457
+ */
458
+ expect ( await init ( preHtml , options ) ) . toBe ( postHtml ) ;
459
+ } ) ;
429
460
} ) ;
430
461
431
462
describe ( 'Messages' , ( ) => {
0 commit comments