1- // import {
2- // type BindingMetadata,
3- // NodeTypes,
4- // } from '@vue/compiler-dom'
51import { describe , expect , test } from 'vitest'
62import {
7- // IRDynamicPropsKind,
8- // IRNodeTypes,
93 transformChildren ,
104 transformElement ,
115 transformText ,
126 transformVBind ,
7+ transformVFor ,
138 transformVOn ,
149} from '../../src'
1510import { makeCompile } from './_utils'
1611
1712const compileWithElementTransform = makeCompile ( {
18- nodeTransforms : [ transformElement , transformChildren , transformText ] ,
13+ nodeTransforms : [
14+ transformVFor ,
15+ transformElement ,
16+ transformChildren ,
17+ transformText ,
18+ ] ,
1919 directiveTransforms : {
2020 bind : transformVBind ,
2121 on : transformVOn ,
@@ -28,7 +28,7 @@ describe('compiler: element transform', () => {
2828 const { code, helpers } = compileWithElementTransform ( `<Foo/>` )
2929 expect ( code ) . toMatchInlineSnapshot ( `
3030 "
31- const n0 = _createComponent(Foo)
31+ const n0 = _createComponent(Foo, null, null, true )
3232 return n0
3333 "
3434 ` )
@@ -42,7 +42,7 @@ describe('compiler: element transform', () => {
4242 } )
4343 expect ( code ) . toMatchInlineSnapshot ( `
4444 "
45- const n0 = _createComponent(Foo.Example)
45+ const n0 = _createComponent(Foo.Example, null, null, true )
4646 return n0
4747 "
4848 ` )
@@ -63,4 +63,24 @@ describe('compiler: element transform', () => {
6363 )
6464 expect ( code ) . toMatchSnapshot ( )
6565 } )
66+
67+ test ( 'generate single root component' , ( ) => {
68+ const { code } = compileWithElementTransform ( `<Comp/>` )
69+ expect ( code ) . toMatchSnapshot ( )
70+ expect ( code ) . contains ( '_createComponent(Comp, null, null, true)' )
71+ } )
72+
73+ test ( 'Fragment should not mark as single root' , ( ) => {
74+ const { code } = compileWithElementTransform ( `<><Comp/></>` )
75+ expect ( code ) . toMatchSnapshot ( )
76+ expect ( code ) . contains ( '_createComponent(Comp)' )
77+ } )
78+
79+ test ( 'v-for on component should not mark as single root' , ( ) => {
80+ const { code } = compileWithElementTransform (
81+ `<Comp v-for={item in items} key={item}/>` ,
82+ )
83+ expect ( code ) . toMatchSnapshot ( )
84+ expect ( code ) . contains ( '_createComponent(Comp)' )
85+ } )
6686} )
0 commit comments