@@ -4,12 +4,14 @@ import {
4
4
createCSSVarsObjCode ,
5
5
createUCVCOptionUnHas ,
6
6
createUCVCSetupUnHas ,
7
- createUseCssVarsCode , injectCSSVars ,
7
+ createUseCssVarsCode ,
8
+ injectCSSVars ,
8
9
injectCSSVarsOnServer ,
9
10
injectUseCssVarsOption ,
10
11
injectUseCssVarsSetup ,
11
12
} from '../inject-cssvars'
12
13
import { parserCompiledSfc } from '../../parser'
14
+ import { CSSVarsBindingTypes } from '../../parser/utils'
13
15
14
16
describe ( 'inject-cssvars' , ( ) => {
15
17
describe ( 'createUCVCOptionUnHas' , ( ) => {
@@ -370,5 +372,163 @@ describe('inject-cssvars', () => {
370
372
mgcStr )
371
373
expect ( res2 . mgcStr . toString ( ) ) . toContain ( mockContent )
372
374
} )
375
+
376
+ test ( 'bindingTypes' , ( ) => {
377
+ const mockContent = `
378
+ const _sfc_main = /* @__PURE__ */ _defineComponent({
379
+ __name: "App",
380
+ props: {
381
+ pcolor: {
382
+ type: String
383
+ }
384
+ },
385
+ setup(__props, { expose }) {
386
+ const color = ref('red')
387
+ let foo = ref('foo')
388
+ const color2 = reactive({ color: 'red' })
389
+ let foo2 = reactive({ foo: 'foo' })
390
+ const head2 = new Map()
391
+ const color3 = 'red'
392
+ const foo3 = { foo: 'foo' }
393
+ const bar3 = 100
394
+ const head3 = [1]
395
+
396
+ let color4 = 'red'
397
+ let foo4 = { foo: 'foo' }
398
+ let bar4 = 100
399
+ let head4 = [1]
400
+
401
+ const fn = () => {}
402
+ const fn2 = function (){}
403
+ function fn3(){}
404
+ let fn4 = () => {}
405
+ let fn5 = function (){}
406
+ const fn6 = () => {}
407
+ const fn7 = fn()
408
+ let fn8 = () => {}
409
+ let fn9 = fn4()
410
+ const a = {foo: 'foo', bar:'bar', head:{heads: 'hh'}}
411
+ const {foo: fooAlias, bar, head: {heads: hh} } = a
412
+ return {
413
+ color,
414
+ foo,
415
+ color2,
416
+ foo2,
417
+ head2,
418
+ color3,
419
+ foo3,
420
+ bar3,
421
+ head3,
422
+ color4,
423
+ foo4,
424
+ bar4,
425
+ head4,
426
+ fn1,
427
+ fn2,
428
+ fn3,
429
+ fn4,
430
+ fn5,
431
+ fn6,
432
+ fn7,
433
+ fn8,
434
+ fn9,
435
+ a,
436
+ fooAlias,
437
+ bar,
438
+ hh,
439
+ }
440
+ }
441
+ })
442
+ `
443
+ const parseRes = parserCompiledSfc ( mockContent )
444
+ const mgcStr = new MagicString ( mockContent )
445
+ const res = injectCSSVars (
446
+ [
447
+ { value : 'color' , has : true , isRef : true } ,
448
+ { value : 'foo' , has : true , isRef : true } ,
449
+ { value : 'color2' , has : true , isRef : false } ,
450
+ { value : 'foo2' , has : true , isRef : false } ,
451
+ { value : 'head2' , has : true , isRef : false } ,
452
+ { value : 'color3' , has : true , isRef : false } ,
453
+ { value : 'foo3' , has : true , isRef : false } ,
454
+ { value : 'bar3' , has : true , isRef : false } ,
455
+ { value : 'head3' , has : true , isRef : false } ,
456
+ { value : 'color4' , has : true , isRef : false } ,
457
+ { value : 'foo4' , has : true , isRef : false } ,
458
+ { value : 'bar4' , has : true , isRef : false } ,
459
+ { value : 'head4' , has : true , isRef : false } ,
460
+ { value : 'fn1' , has : true , isRef : false } ,
461
+ { value : 'fn2' , has : true , isRef : false } ,
462
+ { value : 'fn3' , has : true , isRef : false } ,
463
+ { value : 'fn4' , has : true , isRef : false } ,
464
+ { value : 'fn5' , has : true , isRef : false } ,
465
+ { value : 'fn6' , has : true , isRef : false } ,
466
+ { value : 'fn7' , has : true , isRef : false } ,
467
+ { value : 'fn8' , has : true , isRef : false } ,
468
+ { value : 'fn9' , has : true , isRef : false } ,
469
+ { value : 'a' , has : true , isRef : false } ,
470
+ { value : 'fooAlias' , has : true , isRef : false } ,
471
+ { value : 'bar' , has : true , isRef : false } ,
472
+ { value : 'hh' , has : true , isRef : false } ,
473
+ ] as any ,
474
+ true ,
475
+ parseRes ,
476
+ mgcStr ,
477
+ {
478
+ color : CSSVarsBindingTypes . SETUP_REF ,
479
+ foo : CSSVarsBindingTypes . SETUP_LET ,
480
+ color2 : CSSVarsBindingTypes . SETUP_REACTIVE_CONST ,
481
+ foo2 : CSSVarsBindingTypes . SETUP_LET ,
482
+ head2 : CSSVarsBindingTypes . SETUP_MAYBE_REF ,
483
+ color3 : CSSVarsBindingTypes . LITERAL_CONST ,
484
+ foo3 : CSSVarsBindingTypes . SETUP_CONST ,
485
+ bar3 : CSSVarsBindingTypes . LITERAL_CONST ,
486
+ head3 : CSSVarsBindingTypes . SETUP_CONST ,
487
+ color4 : CSSVarsBindingTypes . SETUP_LET ,
488
+ foo4 : CSSVarsBindingTypes . SETUP_LET ,
489
+ bar4 : CSSVarsBindingTypes . SETUP_LET ,
490
+ head4 : CSSVarsBindingTypes . SETUP_LET ,
491
+ fn : CSSVarsBindingTypes . SETUP_CONST ,
492
+ fn2 : CSSVarsBindingTypes . SETUP_CONST ,
493
+ fn3 : CSSVarsBindingTypes . SETUP_CONST ,
494
+ fn4 : CSSVarsBindingTypes . SETUP_LET ,
495
+ fn5 : CSSVarsBindingTypes . SETUP_LET ,
496
+ fn6 : CSSVarsBindingTypes . SETUP_CONST ,
497
+ fn7 : CSSVarsBindingTypes . SETUP_MAYBE_REF ,
498
+ fn8 : CSSVarsBindingTypes . SETUP_LET ,
499
+ fn9 : CSSVarsBindingTypes . SETUP_LET ,
500
+ a : CSSVarsBindingTypes . SETUP_CONST ,
501
+ fooAlias :CSSVarsBindingTypes . SETUP_MAYBE_REF ,
502
+ bar : CSSVarsBindingTypes . SETUP_MAYBE_REF ,
503
+ hh : CSSVarsBindingTypes . SETUP_MAYBE_REF ,
504
+ } )
505
+ expect ( res . mgcStr . toString ( ) ) . toContain ( ' "75f73e04": _unref(hh),\n' +
506
+ ' "0104392a": _unref(bar),\n' +
507
+ ' "2bbe40ae": _unref(fooAlias),\n' +
508
+ ' "770ddb39": a,\n' +
509
+ ' "33bad66e": _unref(fn9),\n' +
510
+ ' "33d70570": _unref(fn8),\n' +
511
+ ' "33f33472": _unref(fn7),\n' +
512
+ ' "340f6374": fn6,\n' +
513
+ ' "342b9276": _unref(fn5),\n' +
514
+ ' "3447c178": _unref(fn4),\n' +
515
+ ' "3463f07a": fn3,\n' +
516
+ ' "34801f7c": fn2,\n' +
517
+ ' "349c4e7e": _ctx.fn1,\n' +
518
+ ' "e29ebaa8": _unref(head4),\n' +
519
+ ' "268cecf6": _unref(bar4),\n' +
520
+ ' "6bb6f0b2": _unref(foo4),\n' +
521
+ ' "6f79c2b5": _unref(color4),\n' +
522
+ ' "e2bae9aa": head3,\n' +
523
+ ' "26a91bf8": bar3,\n' +
524
+ ' "6ba8d931": foo3,\n' +
525
+ ' "6f6bab34": color3,\n' +
526
+ ' "e2d718ac": _unref(head2),\n' +
527
+ ' "6b9ac1b0": _unref(foo2),\n' +
528
+ ' "6f5d93b3": color2,\n' +
529
+ ' "2a5f3ac4": _unref(foo),\n' +
530
+ ' "1439c43b": color.value,' )
531
+ expect ( res . mgcStr . toString ( ) ) . toContain ( '_useCssVars' )
532
+ } )
373
533
} )
374
534
} )
0 commit comments