@@ -174,6 +174,188 @@ describe('compiler: element transform', () => {
174174 } ,
175175 ] )
176176 } )
177+
178+ test ( 'generate single root component' , ( ) => {
179+ const { code } = compileWithElementTransform ( `<Comp/>` , {
180+ bindingMetadata : { Comp : BindingTypes . SETUP_CONST } ,
181+ } )
182+ expect ( code ) . toMatchSnapshot ( )
183+ expect ( code ) . contains ( '_createComponent(_ctx.Comp, null, true)' )
184+ } )
185+
186+ test ( 'generate multi root component' , ( ) => {
187+ const { code } = compileWithElementTransform ( `<Comp/>123` , {
188+ bindingMetadata : { Comp : BindingTypes . SETUP_CONST } ,
189+ } )
190+ expect ( code ) . toMatchSnapshot ( )
191+ expect ( code ) . contains ( '_createComponent(_ctx.Comp)' )
192+ } )
193+
194+ test ( 'static props' , ( ) => {
195+ const { code, ir } = compileWithElementTransform (
196+ `<Foo id="foo" class="bar" />` ,
197+ )
198+
199+ expect ( code ) . toMatchSnapshot ( )
200+ expect ( code ) . contains ( '_createComponent(_resolveComponent("Foo"), [{' )
201+ expect ( code ) . contains ( ' id: () => ("foo")' )
202+ expect ( code ) . contains ( ' class: () => ("bar")' )
203+ expect ( code ) . contains ( '}], true)' )
204+
205+ expect ( ir . block . operation ) . toMatchObject ( [
206+ {
207+ type : IRNodeTypes . CREATE_COMPONENT_NODE ,
208+ tag : 'Foo' ,
209+ resolve : true ,
210+ root : true ,
211+ props : [
212+ [
213+ {
214+ key : {
215+ type : NodeTypes . SIMPLE_EXPRESSION ,
216+ content : 'id' ,
217+ isStatic : true ,
218+ } ,
219+ values : [
220+ {
221+ type : NodeTypes . SIMPLE_EXPRESSION ,
222+ content : 'foo' ,
223+ isStatic : true ,
224+ } ,
225+ ] ,
226+ } ,
227+ {
228+ key : {
229+ type : NodeTypes . SIMPLE_EXPRESSION ,
230+ content : 'class' ,
231+ isStatic : true ,
232+ } ,
233+ values : [
234+ {
235+ type : NodeTypes . SIMPLE_EXPRESSION ,
236+ content : 'bar' ,
237+ isStatic : true ,
238+ } ,
239+ ] ,
240+ } ,
241+ ] ,
242+ ] ,
243+ } ,
244+ ] )
245+ } )
246+
247+ test ( 'v-bind="obj"' , ( ) => {
248+ const { code, ir } = compileWithElementTransform ( `<Foo v-bind="obj" />` )
249+ expect ( code ) . toMatchSnapshot ( )
250+ expect ( code ) . contains ( '[() => (_ctx.obj)]' )
251+ expect ( ir . block . operation ) . toMatchObject ( [
252+ {
253+ type : IRNodeTypes . CREATE_COMPONENT_NODE ,
254+ tag : 'Foo' ,
255+ props : [ { content : 'obj' , isStatic : false } ] ,
256+ } ,
257+ ] )
258+ } )
259+
260+ test ( 'v-bind="obj" after static prop' , ( ) => {
261+ const { code, ir } = compileWithElementTransform (
262+ `<Foo id="foo" v-bind="obj" />` ,
263+ )
264+ expect ( code ) . toMatchSnapshot ( )
265+ expect ( code ) . contains ( 'id: () => ("foo")' )
266+ expect ( code ) . contains ( '}, () => (_ctx.obj)]' )
267+ expect ( ir . block . operation ) . toMatchObject ( [
268+ {
269+ type : IRNodeTypes . CREATE_COMPONENT_NODE ,
270+ tag : 'Foo' ,
271+ props : [
272+ [ { key : { content : 'id' } , values : [ { content : 'foo' } ] } ] ,
273+ { content : 'obj' } ,
274+ ] ,
275+ } ,
276+ ] )
277+ } )
278+
279+ test ( 'v-bind="obj" before static prop' , ( ) => {
280+ const { code, ir } = compileWithElementTransform (
281+ `<Foo v-bind="obj" id="foo" />` ,
282+ )
283+ expect ( code ) . toMatchSnapshot ( )
284+ expect ( code ) . contains ( '[() => (_ctx.obj), {' )
285+ expect ( code ) . contains ( 'id: () => ("foo")' )
286+ expect ( ir . block . operation ) . toMatchObject ( [
287+ {
288+ type : IRNodeTypes . CREATE_COMPONENT_NODE ,
289+ tag : 'Foo' ,
290+ props : [
291+ { content : 'obj' } ,
292+ [ { key : { content : 'id' } , values : [ { content : 'foo' } ] } ] ,
293+ ] ,
294+ } ,
295+ ] )
296+ } )
297+
298+ test ( 'v-bind="obj" between static props' , ( ) => {
299+ const { code, ir } = compileWithElementTransform (
300+ `<Foo id="foo" v-bind="obj" class="bar" />` ,
301+ )
302+ expect ( code ) . toMatchSnapshot ( )
303+ expect ( code ) . contains ( 'id: () => ("foo")' )
304+ expect ( code ) . contains ( '}, () => (_ctx.obj), {' )
305+ expect ( code ) . contains ( 'class: () => ("bar")' )
306+ expect ( ir . block . operation ) . toMatchObject ( [
307+ {
308+ type : IRNodeTypes . CREATE_COMPONENT_NODE ,
309+ tag : 'Foo' ,
310+ props : [
311+ [ { key : { content : 'id' } , values : [ { content : 'foo' } ] } ] ,
312+ { content : 'obj' } ,
313+ [ { key : { content : 'class' } , values : [ { content : 'bar' } ] } ] ,
314+ ] ,
315+ } ,
316+ ] )
317+ } )
318+
319+ test ( 'props merging: event handlers' , ( ) => {
320+ const { code, ir } = compileWithElementTransform (
321+ `<Foo @click.foo="a" @click.bar="b" />` ,
322+ )
323+ expect ( code ) . toMatchSnapshot ( )
324+ expect ( code ) . contains ( 'onClick: () => (_ctx.a)' )
325+ expect ( ir . block . operation ) . toMatchObject ( [
326+ {
327+ type : IRNodeTypes . CREATE_COMPONENT_NODE ,
328+ tag : 'Foo' ,
329+ props : [
330+ [
331+ {
332+ key : { content : 'onClick' , isStatic : true } ,
333+ values : [ { content : 'a' } ] ,
334+ } ,
335+ ] ,
336+ ] ,
337+ } ,
338+ ] )
339+ } )
340+
341+ test . todo ( 'props merging: style' , ( ) => {
342+ const { code } = compileWithElementTransform (
343+ `<Foo style="color: green" :style="{ color: 'red' }" />` ,
344+ )
345+ expect ( code ) . toMatchSnapshot ( )
346+ } )
347+
348+ test . todo ( 'props merging: class' , ( ) => {
349+ const { code } = compileWithElementTransform (
350+ `<Foo class="foo" :class="{ bar: isBar }" />` ,
351+ )
352+ expect ( code ) . toMatchSnapshot ( )
353+ } )
354+
355+ test . todo ( 'v-on="obj"' , ( ) => {
356+ const { code } = compileWithElementTransform ( `<Foo v-on="obj" />` )
357+ expect ( code ) . toMatchSnapshot ( )
358+ } )
177359 } )
178360
179361 test ( 'static props' , ( ) => {
0 commit comments