@@ -53,7 +53,7 @@ function parseWithSlots(template: string, options: CompilerOptions = {}) {
53
53
}
54
54
}
55
55
56
- function createSlotMatcher ( obj : Record < string , any > ) {
56
+ function createSlotMatcher ( obj : Record < string , any > , isDynamic = false ) {
57
57
return {
58
58
type : NodeTypes . JS_OBJECT_EXPRESSION ,
59
59
properties : Object . keys ( obj )
@@ -70,7 +70,7 @@ function createSlotMatcher(obj: Record<string, any>) {
70
70
} )
71
71
. concat ( {
72
72
key : { content : `_` } ,
73
- value : { content : `1` , isStatic : false }
73
+ value : { content : isDynamic ? `2` : `1` , isStatic : false }
74
74
} )
75
75
}
76
76
}
@@ -230,29 +230,32 @@ describe('compiler: transform component slots', () => {
230
230
{ prefixIdentifiers : true }
231
231
)
232
232
expect ( slots ) . toMatchObject (
233
- createSlotMatcher ( {
234
- '[_ctx.named]' : {
235
- type : NodeTypes . JS_FUNCTION_EXPRESSION ,
236
- params : {
237
- type : NodeTypes . COMPOUND_EXPRESSION ,
238
- children : [ `{ ` , { content : `foo` } , ` }` ]
239
- } ,
240
- returns : [
241
- {
242
- type : NodeTypes . INTERPOLATION ,
243
- content : {
244
- content : `foo`
245
- }
233
+ createSlotMatcher (
234
+ {
235
+ '[_ctx.named]' : {
236
+ type : NodeTypes . JS_FUNCTION_EXPRESSION ,
237
+ params : {
238
+ type : NodeTypes . COMPOUND_EXPRESSION ,
239
+ children : [ `{ ` , { content : `foo` } , ` }` ]
246
240
} ,
247
- {
248
- type : NodeTypes . INTERPOLATION ,
249
- content : {
250
- content : `_ctx.bar`
241
+ returns : [
242
+ {
243
+ type : NodeTypes . INTERPOLATION ,
244
+ content : {
245
+ content : `foo`
246
+ }
247
+ } ,
248
+ {
249
+ type : NodeTypes . INTERPOLATION ,
250
+ content : {
251
+ content : `_ctx.bar`
252
+ }
251
253
}
252
- }
253
- ]
254
- }
255
- } )
254
+ ]
255
+ }
256
+ } ,
257
+ true
258
+ )
256
259
)
257
260
expect ( generate ( root , { prefixIdentifiers : true } ) . code ) . toMatchSnapshot ( )
258
261
} )
@@ -307,50 +310,53 @@ describe('compiler: transform component slots', () => {
307
310
{ prefixIdentifiers : true }
308
311
)
309
312
expect ( slots ) . toMatchObject (
310
- createSlotMatcher ( {
311
- '[_ctx.one]' : {
312
- type : NodeTypes . JS_FUNCTION_EXPRESSION ,
313
- params : {
314
- type : NodeTypes . COMPOUND_EXPRESSION ,
315
- children : [ `{ ` , { content : `foo` } , ` }` ]
316
- } ,
317
- returns : [
318
- {
319
- type : NodeTypes . INTERPOLATION ,
320
- content : {
321
- content : `foo`
322
- }
313
+ createSlotMatcher (
314
+ {
315
+ '[_ctx.one]' : {
316
+ type : NodeTypes . JS_FUNCTION_EXPRESSION ,
317
+ params : {
318
+ type : NodeTypes . COMPOUND_EXPRESSION ,
319
+ children : [ `{ ` , { content : `foo` } , ` }` ]
323
320
} ,
324
- {
325
- type : NodeTypes . INTERPOLATION ,
326
- content : {
327
- content : `_ctx.bar`
321
+ returns : [
322
+ {
323
+ type : NodeTypes . INTERPOLATION ,
324
+ content : {
325
+ content : `foo`
326
+ }
327
+ } ,
328
+ {
329
+ type : NodeTypes . INTERPOLATION ,
330
+ content : {
331
+ content : `_ctx.bar`
332
+ }
328
333
}
329
- }
330
- ]
331
- } ,
332
- '[_ctx.two]' : {
333
- type : NodeTypes . JS_FUNCTION_EXPRESSION ,
334
- params : {
335
- type : NodeTypes . COMPOUND_EXPRESSION ,
336
- children : [ `{ ` , { content : `bar` } , ` }` ]
334
+ ]
337
335
} ,
338
- returns : [
339
- {
340
- type : NodeTypes . INTERPOLATION ,
341
- content : {
342
- content : `_ctx.foo`
343
- }
336
+ '[_ctx.two]' : {
337
+ type : NodeTypes . JS_FUNCTION_EXPRESSION ,
338
+ params : {
339
+ type : NodeTypes . COMPOUND_EXPRESSION ,
340
+ children : [ `{ ` , { content : `bar` } , ` }` ]
344
341
} ,
345
- {
346
- type : NodeTypes . INTERPOLATION ,
347
- content : {
348
- content : `bar`
342
+ returns : [
343
+ {
344
+ type : NodeTypes . INTERPOLATION ,
345
+ content : {
346
+ content : `_ctx.foo`
347
+ }
348
+ } ,
349
+ {
350
+ type : NodeTypes . INTERPOLATION ,
351
+ content : {
352
+ content : `bar`
353
+ }
349
354
}
350
- }
351
- ]
352
- }
353
- } )
355
+ ]
356
+ }
357
+ } ,
358
+ true
359
+ )
354
360
)
355
361
expect ( generate ( root , { prefixIdentifiers : true } ) . code ) . toMatchSnapshot ( )
356
362
} )
@@ -382,35 +388,38 @@ describe('compiler: transform component slots', () => {
382
388
type : NodeTypes . VNODE_CALL ,
383
389
tag : `_component_Inner` ,
384
390
props : undefined ,
385
- children : createSlotMatcher ( {
386
- default : {
387
- type : NodeTypes . JS_FUNCTION_EXPRESSION ,
388
- params : {
389
- type : NodeTypes . COMPOUND_EXPRESSION ,
390
- children : [ `{ ` , { content : `bar` } , ` }` ]
391
- } ,
392
- returns : [
393
- {
394
- type : NodeTypes . INTERPOLATION ,
395
- content : {
396
- content : `foo`
397
- }
398
- } ,
399
- {
400
- type : NodeTypes . INTERPOLATION ,
401
- content : {
402
- content : `bar`
403
- }
391
+ children : createSlotMatcher (
392
+ {
393
+ default : {
394
+ type : NodeTypes . JS_FUNCTION_EXPRESSION ,
395
+ params : {
396
+ type : NodeTypes . COMPOUND_EXPRESSION ,
397
+ children : [ `{ ` , { content : `bar` } , ` }` ]
404
398
} ,
405
- {
406
- type : NodeTypes . INTERPOLATION ,
407
- content : {
408
- content : `_ctx.baz`
399
+ returns : [
400
+ {
401
+ type : NodeTypes . INTERPOLATION ,
402
+ content : {
403
+ content : `foo`
404
+ }
405
+ } ,
406
+ {
407
+ type : NodeTypes . INTERPOLATION ,
408
+ content : {
409
+ content : `bar`
410
+ }
411
+ } ,
412
+ {
413
+ type : NodeTypes . INTERPOLATION ,
414
+ content : {
415
+ content : `_ctx.baz`
416
+ }
409
417
}
410
- }
411
- ]
412
- }
413
- } ) ,
418
+ ]
419
+ }
420
+ } ,
421
+ true
422
+ ) ,
414
423
// nested slot should be forced dynamic, since scope variables
415
424
// are not tracked as dependencies of the slot.
416
425
patchFlag : genFlagText ( PatchFlags . DYNAMIC_SLOTS )
@@ -522,7 +531,7 @@ describe('compiler: transform component slots', () => {
522
531
callee : CREATE_SLOTS ,
523
532
arguments : [
524
533
createObjectMatcher ( {
525
- _ : `[1 ]`
534
+ _ : `[2 ]`
526
535
} ) ,
527
536
{
528
537
type : NodeTypes . JS_ARRAY_EXPRESSION ,
@@ -564,7 +573,7 @@ describe('compiler: transform component slots', () => {
564
573
callee : CREATE_SLOTS ,
565
574
arguments : [
566
575
createObjectMatcher ( {
567
- _ : `[1 ]`
576
+ _ : `[2 ]`
568
577
} ) ,
569
578
{
570
579
type : NodeTypes . JS_ARRAY_EXPRESSION ,
@@ -613,7 +622,7 @@ describe('compiler: transform component slots', () => {
613
622
callee : CREATE_SLOTS ,
614
623
arguments : [
615
624
createObjectMatcher ( {
616
- _ : `[1 ]`
625
+ _ : `[2 ]`
617
626
} ) ,
618
627
{
619
628
type : NodeTypes . JS_ARRAY_EXPRESSION ,
@@ -672,7 +681,7 @@ describe('compiler: transform component slots', () => {
672
681
callee : CREATE_SLOTS ,
673
682
arguments : [
674
683
createObjectMatcher ( {
675
- _ : `[1 ]`
684
+ _ : `[2 ]`
676
685
} ) ,
677
686
{
678
687
type : NodeTypes . JS_ARRAY_EXPRESSION ,
0 commit comments