1
1
import { describe , expect , test } from 'vitest'
2
+ import { BindingTypes } from '@vue/compiler-dom'
2
3
import { type CompilerOptions , compile as _compile } from '../src/core/compiler'
3
4
4
5
export function compile ( template : string , options : CompilerOptions = { } ) {
@@ -14,11 +15,13 @@ describe('compile', () => {
14
15
const { code } = compile (
15
16
`<div>
16
17
<div>hello</div>
18
+ <input />
19
+ <span />
17
20
</div>` ,
18
21
)
19
22
expect ( code ) . toMatchInlineSnapshot ( `
20
23
"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>")
22
25
23
26
export function render(_ctx) {
24
27
const n0 = t0()
@@ -28,16 +31,46 @@ describe('compile', () => {
28
31
} )
29
32
30
33
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>` )
32
47
expect ( code ) . toMatchInlineSnapshot ( `
33
48
"import { renderEffect as _renderEffect, setText as _setText, template as _template } from 'vue/vapor';
34
49
const t0 = _template("<div></div>")
35
50
36
51
export function render(_ctx) {
37
52
const n0 = t0()
38
- _renderEffect(() => _setText(n0, 1 + a_ctx. ))
53
+ _renderEffect(() => _setText(n0, _ctx.a +_ctx.b + _ctx.c ))
39
54
return n0
40
55
}"
41
56
` )
42
57
} )
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
+ } )
43
76
} )
0 commit comments