const compiler = require('../lib') function assertCodegen (template, generatedCode, ...args) { const compiled = compiler.compile(template, { mp: { platform: 'app-plus' }, view: true }) expect(compiled.render).toBe(generatedCode) } /* eslint-disable quotes */ describe('codegen', () => { it('generate directive', () => { assertCodegen( '

', `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:arg1.modifier",value:($r['0']['v-custom1']),expression:"$r['0']['v-custom1']",arg:"arg1",modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` ) // extra assertCodegen( '

', `with(this){return _c('v-uni-view',{directives:[{name:"custom1",rawName:"v-custom1:[arg1].modifier",value:($r['0']['v-custom1']),expression:"$r['0']['v-custom1']",arg:$r['0']['v-custom1-arg'],modifiers:{"modifier":true}},{name:"custom2",rawName:"v-custom2"}],attrs:{"_i":0}})}` ) }) it('generate filters', () => { assertCodegen( '
{{ d | e | f }}
', `with(this){return _c('v-uni-view',{attrs:{"id":$r['0']['a-id'],"_i":0}},[_v(($r['0']['t0']))])}` ) }) it('generate filters with no arguments', () => { assertCodegen( '
{{ d | e() }}
', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_v(($r['0']['t0']))])}` ) }) it('generate v-for directive', () => { assertCodegen( '
  • ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function(item,$i){return _c('v-uni-view',{key:item,attrs:{"_i":("1-"+$i)}})}),1)}` ) // iterator syntax assertCodegen( '
  • ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function(item,i){return _c('v-uni-view',{key:item,attrs:{"_i":("1-"+i)}})}),1)}` ) assertCodegen( '
  • ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function(item,index){return _c('v-uni-view',{key:item,attrs:{"_i":("1-"+index)}})}),1)}` ) // destructuring assertCodegen( '
  • ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function($item,$i){return _c('v-uni-view',{key:$item,attrs:{"_i":("1-"+$i)}})}),1)}` ) assertCodegen( '
  • ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function($item,index){return _c('v-uni-view',{key:$item,attrs:{"_i":("1-"+index)}})}),1)}` ) // v-for with extra element assertCodegen( '

  • ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_c('v-uni-view',{attrs:{"_i":1}}),_l(($r['2']['v-for']),function(item,$i){return _c('v-uni-view',{key:item,attrs:{"_i":("2-"+$i)}})})],2)}` ) }) it('generate v-if directive', () => { assertCodegen( '

    hello

    ', `with(this){return ($r['0']['v-if'])?_c('v-uni-view',{attrs:{"_i":0}},[_v("hello")]):_e()}` ) }) it('generate v-else directive', () => { assertCodegen( '

    hello

    world

    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):_c('v-uni-view',{attrs:{"_i":2}},[_v("world")])],1)}` ) }) it('generate v-else-if directive', () => { assertCodegen( '

    hello

    world

    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):($r['2']['v-else-if'])?_c('v-uni-view',{attrs:{"_i":2}},[_v("world")]):_e()],1)}` ) }) it('generate v-else-if with v-else directive', () => { assertCodegen( '

    hello

    world

    bye

    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):($r['2']['v-else-if'])?_c('v-uni-view',{attrs:{"_i":2}},[_v("world")]):_c('v-uni-view',{attrs:{"_i":3}},[_v("bye")])],1)}` ) }) it('generate multi v-else-if with v-else directive', () => { assertCodegen( '

    hello

    world

    elseif

    bye

    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v("hello")]):($r['2']['v-else-if'])?_c('v-uni-view',{attrs:{"_i":2}},[_v("world")]):(3)?_c('v-uni-view',{attrs:{"_i":3}},[_v("elseif")]):_c('v-uni-view',{attrs:{"_i":4}},[_v("bye")])],1)}` ) }) it('generate ref', () => { assertCodegen( '

    ', `with(this){return _c('v-uni-view',{ref:"component1",attrs:{"_i":0}})}` ) }) it('generate ref on v-for', () => { assertCodegen( '', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l(($r['1']['v-for']),function(item,$i){return _c('v-uni-view',{key:item,ref:"component1",refInFor:true,attrs:{"_i":("1-"+$i)}})}),1)}` ) }) it('generate v-bind directive', () => { assertCodegen( '

    ', `with(this){return _c('v-uni-view',_b({attrs:{"_i":0}},'v-uni-view',$r['0']['v-bind'],false))}` ) }) it('generate v-bind with prop directive', () => { assertCodegen( '

    ', `with(this){return _c('v-uni-view',_b({attrs:{"_i":0}},'v-uni-view',$r['0']['v-bind'],true))}` ) }) it('generate v-bind directive with sync modifier', () => { assertCodegen( '

    ', `with(this){return _c('v-uni-view',_b({attrs:{"_i":0}},'v-uni-view',$r['0']['v-bind'],false,true))}` ) }) it('generate v-model directive', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:($r['0']['v-model']),callback:function ($$v) {},expression:"$r['0']['v-model']"}})}` ) }) it('generate multiline v-model directive', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},model:{value:($r['0']['v-model']),callback:function ($$v) {},expression:"$r['0']['v-model']"}})}` ) }) it('generate multiline v-model directive on custom component', () => { assertCodegen( '', `with(this){return _c('my-component',{attrs:{"_i":0},model:{value:($r['0']['v-model']),callback:function ($$v) {},expression:"$r['0']['v-model']"}})}` ) }) it('generate template tag', () => { assertCodegen( '
    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[[_c('v-uni-view',{attrs:{"_i":2}},[_v(($r['2']['t0']))])]],2)}` ) }) it('generate single slot', () => { assertCodegen( '
    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_t("default",null,{"_i":1})],2)}` ) }) it('generate named slot', () => { assertCodegen( '
    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_t("one",null,{"_i":1})],2)}` ) }) it('generate slot fallback content', () => { assertCodegen( '
    hi
    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_t("default",[_c('v-uni-view',{attrs:{"_i":2}},[_v("hi")])],{"_i":1})],2)}` ) }) it('generate slot target', () => { assertCodegen( '

    hello world

    ', `with(this){return _c('v-uni-view',{attrs:{"slot":"one","_i":0},slot:"one"},[_v("hello world")])}` ) }) it('generate scoped slot', () => { assertCodegen( '', `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar){return [_v(($r['1']['t0']))]}}])})}` ) assertCodegen( '
    {{ bar }}
    ', `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar){return _c('v-uni-view',{attrs:{"_i":1}},[_v(($r['1']['t0']))])}}])})}` ) }) it('generate named scoped slot', () => { assertCodegen( '', `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar){return [_v(($r['1']['t0']))]}}])})}` ) assertCodegen( '
    {{ bar }}
    ', `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar){return _c('v-uni-view',{attrs:{"_i":1}},[_v(($r['1']['t0']))])}}])})}` ) }) it('generate dynamic scoped slot', () => { assertCodegen( '', `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:foo,fn:function(bar){return [_v(($r['1']['t0']))]}}],null,true)})}` ) }) it('generate scoped slot with multiline v-if', () => { assertCodegen( '', `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function(bar){return ($r['1']['v-if'])?[_v(($r['1']['t0']))]:undefined}}],null,true)})}` ) assertCodegen( '
    {{ bar }}
    ', `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([{key:"foo",fn:function(bar){return ($r['1']['v-if'])?_c('v-uni-view',{attrs:{"_i":1}},[_v(($r['1']['t0']))]):_e()}}],null,true)})}` ) }) it('generate scoped slot with new slot syntax', () => { assertCodegen( '', `with(this){return _c('foo',{attrs:{"_i":0},scopedSlots:_u([($r['1']['v-if'])?{key:"default",fn:function(bar){return [_v(($r['1']['t0']))]}}:null],null,true)})}` ) }) it('generate class binding', () => { // static assertCodegen( '

    hello world

    ', `with(this){return _c('v-uni-view',{staticClass:"class1",attrs:{"_i":0}},[_v("hello world")])}` ) // dynamic assertCodegen( '

    hello world

    ', `with(this){return _c('v-uni-view',{class:$r['0']['c'],attrs:{"_i":0}},[_v("hello world")])}` ) }) it('generate style binding', () => { assertCodegen( '

    hello world

    ', `with(this){return _c('v-uni-view',{style:($r['0']['s']),attrs:{"_i":0}},[_v("hello world")])}` ) }) it('generate v-show directive', () => { assertCodegen( '

    hello world

    ', `with(this){return _c('v-uni-view',{directives:[{name:"show",rawName:"v-show",value:($r['0']['v-show']),expression:"$r['0']['v-show']"}],attrs:{"_i":0}},[_v("hello world")])}` ) }) it('generate DOM props with v-bind directive', () => { // input + value assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},domProps:{"value":$r['0']['a-value']}})}` ) // non input assertCodegen( '

    ', `with(this){return _c('v-uni-view',{attrs:{"value":$r['0']['a-value'],"_i":0}})}` ) }) it('generate attrs with v-bind directive', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"name":$r['0']['a-name'],"_i":0}})}` ) }) it('generate static attrs', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"name":"field1","_i":0}})}` ) }) it('generate events with v-on directive', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) }) it('generate events with method call', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // empty arguments assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // without semicolon assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // multiple args assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // expression in args assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // tricky symbols in args assertCodegen( ``, `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // function name including a `function` part (#9920) // 2.6.10 暂未修复此 bug // assertCodegen( // '', // `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return functionName()}}})}` // ) }) it('generate events with multiple statements', () => { // normal function assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // function with multiple args assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) }) it('generate events with keycode', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"enter":true})}}})}` ) // multiple keycodes (delete) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"delete":true})}}})}` ) // multiple keycodes (esc) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"esc":true})}}})}` ) // multiple keycodes (space) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"space":true})}}})}` ) // multiple keycodes (chained) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"keydown":function($event){return $handleViewEvent($event,{"enter":true,"delete":true})}}})}` ) // number keycode assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"13":true})}}})}` ) // custom keycode assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"custom":true})}}})}` ) }) it('generate events with generic modifiers', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"stop":true})}}})}` ) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"prevent":true})}}})}` ) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"self":true})}}})}` ) }) // GitHub Issues #5146 it('generate events with generic modifiers and keycode correct order', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"keydown":function($event){return $handleViewEvent($event,{"enter":true,"prevent":true})}}})}` ) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"keydown":function($event){return $handleViewEvent($event,{"enter":true,"stop":true})}}})}` ) }) it('generate events with mouse event modifiers', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"click":function($event){return $handleViewEvent($event,{"ctrl":true})}}})}` ) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"click":function($event){return $handleViewEvent($event,{"shift":true})}}})}` ) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"click":function($event){return $handleViewEvent($event,{"alt":true})}}})}` ) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"click":function($event){return $handleViewEvent($event,{"meta":true})}}})}` ) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"click":function($event){return $handleViewEvent($event,{"exact":true})}}})}` ) assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"click":function($event){return $handleViewEvent($event,{"ctrl":true,"exact":true})}}})}` ) }) it('generate events with multiple modifiers', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"stop":true,"prevent":true,"self":true})}}})}` ) }) it('generate events with capture modifier', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"!input":function($event){return $handleViewEvent($event,{"capture":true})}}})}` ) }) it('generate events with once modifier', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"~input":function($event){return $handleViewEvent($event,{"once":true})}}})}` ) }) it('generate events with capture and once modifier', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"~!input":function($event){return $handleViewEvent($event,{"once":true,"capture":true})}}})}` ) }) it('generate events with once and capture modifier', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"~!input":function($event){return $handleViewEvent($event,{"once":true,"capture":true})}}})}` ) }) it('generate events with inline statement', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) }) it('generate events with inline function expression', () => { // normal function assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // normal named function assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // arrow with no args assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // arrow with parens, single arg assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // arrow with parens, multi args assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // arrow with destructuring assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // arrow single arg no parens assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) // with modifiers assertCodegen( ``, `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"keyup":function($event){return $handleViewEvent($event,{"enter":true})}}})}` ) }) // #3893 it('should not treat handler with unexpected whitespace as inline statement', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}` ) }) it('generate unhandled events', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event)}}})}`, ast => { ast.events.input = undefined } ) }) it('generate multiple event handlers', () => { assertCodegen( '', `with(this){return _c('v-uni-input',{attrs:{"_i":0},on:{"input":function($event){return $handleViewEvent($event,{"stop":true})}}})}` ) }) it('generate component', () => { assertCodegen( '

    hi
    ', `with(this){return _c('my-component',{attrs:{"_i":0},on:{"notify":function($event){return $handleViewEvent($event)}}},[_c('v-uni-view',{attrs:{"_i":1}},[_v("hi")])],1)}` ) }) it('generate svg component with children', () => { assertCodegen( '', `with(this){return _c('svg',{attrs:{"_i":0}},[_c('my-comp',{attrs:{"_i":1}},[_c('circle',{attrs:{"_i":2}})])],1)}` ) }) it('generate is attribute', () => { assertCodegen( '
    ', `with(this){return _c("component1",{tag:"v-uni-view",attrs:{"_i":0}})}` ) assertCodegen( '
    ', `with(this){return _c(component1,{tag:"v-uni-view",attrs:{"_i":0}})}` ) // maybe a component and normalize type should be 1 assertCodegen( '
    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_c("component1",{tag:"v-uni-view",attrs:{"_i":1}})],1)}` ) }) it('generate component with inline-template', () => { // have "inline-template'" assertCodegen( '

    hello world

    ', `with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _c('v-uni-view',{attrs:{"_i":1}},[_c('v-uni-label',{attrs:{"_i":2}},[_v("hello world")])],1)}},staticRenderFns:[]}})}` ) // "have inline-template attrs, but not having exactly one child element assertCodegen( '

    ', `with(this){return _c('my-component',{attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _c('v-uni-view',{attrs:{"_i":1}})}},staticRenderFns:[]}})}` ) assertCodegen( '', `with(this){return _c('my-component',{attrs:{"_i":0}})}` ) // have "is" attribute assertCodegen( '
    ', `with(this){return _c("myComponent",{tag:"v-uni-view",attrs:{"_i":0},inlineTemplate:{render:function(){with(this){return _c('v-uni-view',{attrs:{"_i":1}})}},staticRenderFns:[]}})}` ) assertCodegen( '
    ', `with(this){return _c("myComponent",{tag:"v-uni-view",attrs:{"_i":0}})}` ) // expect('Inline-template components must have exactly one child element.').toHaveBeenWarned() // expect(console.error.calls.count()).toBe(3) }) it('generate static trees inside v-for', () => { assertCodegen( `

    `, `with(this){return _c('v-uni-view',{attrs:{"_i":0}},_l((10),function(i,$i){return _c('v-uni-view',{attrs:{"_i":("1-"+$i)}},[_c('v-uni-view',{attrs:{"_i":("2-"+$i)}},[_c('v-uni-label',{attrs:{"_i":("3-"+$i)}})],1)],1)}),1)}` // [`with(this){return _c('v-uni-view',{attrs:{"_i":("2-"+$i)}},[_c('v-uni-view',{attrs:{"_i":("3-"+$i)}})])}`] ) }) it('generate component with v-for', () => { // normalize type: 2 assertCodegen( '
    ', `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[_c('child',{attrs:{"_i":1}}),_l(($r['2']['v-for']),function(item,$i){return [_v(($r[("2-"+$i)]['t0']))]})],2)}` ) }) // it('generate component with comment', () => { // const options = extend({ // comments: true // }, baseOptions) // const template = '
    ' // const generatedCode = `with(this){return _c('v-uni-view',{attrs:{"_i":0}})}` // const ast = parse(template, options) // optimize(ast, options) // const res = generate(ast, options) // expect(res.render).toBe(generatedCode) // }) // #6150 // it('generate comments with special characters', () => { // const options = extend({ // comments: true // }, baseOptions) // const template = '
    ' // const generatedCode = `with(this){return _c('v-uni-view',{attrs:{"_i":0}})}` // const ast = parse(template, options) // optimize(ast, options) // const res = generate(ast, options) // expect(res.render).toBe(generatedCode) // }) // #8041 it('does not squash templates inside v-pre', () => { assertCodegen( '
    ', `with(this){return _c('v-uni-view',{pre:true,attrs:{"_i":0}},[[_c('v-uni-view',{pre:true,attrs:{"_i":2}},[_v("{{msg}}")])]],2)}` ) // const template = '
    ' // const generatedCode = `with(this){return _m(0)}` // // const renderFn = `with(this){return _c('v-uni-view',{pre:true},[_c('template',[_c('v-uni-view',[_v("{{msg}}")])])],2)}` // const ast = parse(template, baseOptions) // optimize(ast, baseOptions) // const res = generate(ast, baseOptions) // expect(res.render).toBe(generatedCode) // // expect(res.staticRenderFns).toEqual([renderFn]) }) it('not specified ast type', () => { assertCodegen( '', `with(this){return _c("div")}` ) // const res = generate(null, baseOptions) // expect(res.render).toBe(`with(this){return _c("v-uni-view")}`) // expect(res.staticRenderFns).toEqual([]) }) it('not specified directives option', () => { assertCodegen( '

    hello world

    ', `with(this){return ($r['0']['v-if'])?_c('v-uni-view',{attrs:{"_i":0}},[_v("hello world")]):_e()}`, { // isReservedTag } ) }) // #9142 it('should compile single v-for component inside template', () => { assertCodegen( `
    `, `with(this){return _c('v-uni-view',{attrs:{"_i":0}},[($r['1']['v-if'])?_l((1),function(i,$i){return _c('foo',{key:i,attrs:{"_i":("2-"+$i)}})}):_e()],2)}` ) }) }) /* eslint-enable quotes */