11import { describe , expect , test } from 'vitest'
2+ import { BindingTypes } from '@vue/compiler-dom'
23import { type CompilerOptions , compile as _compile } from '../src/core/compiler'
34
45export function compile ( template : string , options : CompilerOptions = { } ) {
@@ -14,11 +15,13 @@ describe('compile', () => {
1415 const { code } = compile (
1516 `<div>
1617 <div>hello</div>
18+ <input />
19+ <span />
1720 </div>` ,
1821 )
1922 expect ( code ) . toMatchInlineSnapshot ( `
2023 "import { template as _template } from 'vue/vapor';
21- const t0 = _template("<div><div>hello</div></div>")
24+ const t0 = _template("<div><div>hello</div> <input> <span></span> </div>")
2225
2326 export function render(_ctx) {
2427 const n0 = t0()
@@ -28,16 +31,46 @@ describe('compile', () => {
2831 } )
2932
3033 test ( 'dynamic root' , ( ) => {
31- const { code } = compile ( `<><div>{1 + a}</div></>` )
34+ const { code } = compile ( `<>{ 1 }{ 2 }</>` )
35+ expect ( code ) . toMatchInlineSnapshot ( `
36+ "import { createTextNode as _createTextNode } from 'vue/vapor';
37+
38+ export function render(_ctx) {
39+ const n0 = _createTextNode([1, 2])
40+ return n0
41+ }"
42+ ` )
43+ } )
44+
45+ test ( 'dynamic root' , ( ) => {
46+ const { code } = compile ( `<div>{a +b + c }</div>` )
3247 expect ( code ) . toMatchInlineSnapshot ( `
3348 "import { renderEffect as _renderEffect, setText as _setText, template as _template } from 'vue/vapor';
3449 const t0 = _template("<div></div>")
3550
3651 export function render(_ctx) {
3752 const n0 = t0()
38- _renderEffect(() => _setText(n0, 1 + a_ctx. ))
53+ _renderEffect(() => _setText(n0, _ctx.a +_ctx.b + _ctx.c ))
3954 return n0
4055 }"
4156 ` )
4257 } )
58+
59+ describe ( 'expression parsing' , ( ) => {
60+ test ( 'interpolation' , ( ) => {
61+ const { code } = compile ( `<>{ a + b }</>` , {
62+ inline : true ,
63+ bindingMetadata : {
64+ b : BindingTypes . SETUP_REF ,
65+ } ,
66+ } )
67+ expect ( code ) . toMatchInlineSnapshot ( `
68+ "(() => {
69+ const n0 = _createTextNode(() => [a + b.value])
70+ return n0
71+ })()"
72+ ` )
73+ // expect(code).contains('a + b.value')
74+ } )
75+ } )
4376} )
0 commit comments