|
|
@@ -34,72 +34,72 @@ describe('codegen', () => {
|
|
|
it('generate directive', () => {
|
|
|
assertCodegen(
|
|
|
'<p v-custom1:arg1.modifire="value1" v-custom2><p>',
|
|
|
- `with(this){return _h(_e('p',{directives:[{name:"custom1",value:(value1),expression:"value1",arg:"arg1",modifiers:{"modifire":true}},{name:"custom2",arg:"arg1"}]}))}`
|
|
|
+ `with(this){return _h('p',{directives:[{name:"custom1",value:(value1),expression:"value1",arg:"arg1",modifiers:{"modifire":true}},{name:"custom2",arg:"arg1"}]})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate v-for directive', () => {
|
|
|
assertCodegen(
|
|
|
'<li v-for="item in items" :key="item.uid"></li>',
|
|
|
- `with(this){return (items)&&_l((items),function(item){return _h(_e('li',{key:item.uid}))})}`
|
|
|
+ `with(this){return (items)&&_l((items),function(item){return _h('li',{key:item.uid})})}`
|
|
|
)
|
|
|
// iterator syntax
|
|
|
assertCodegen(
|
|
|
'<li v-for="(item, i) in items"></li>',
|
|
|
- `with(this){return (items)&&_l((items),function(item,i){return _h(_e('li'))})}`
|
|
|
+ `with(this){return (items)&&_l((items),function(item,i){return _h('li')})}`
|
|
|
)
|
|
|
assertCodegen(
|
|
|
'<li v-for="(item, key, index) in items"></li>',
|
|
|
- `with(this){return (items)&&_l((items),function(item,key,index){return _h(_e('li'))})}`
|
|
|
+ `with(this){return (items)&&_l((items),function(item,key,index){return _h('li')})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate v-if directive', () => {
|
|
|
assertCodegen(
|
|
|
'<p v-if="show">hello</p>',
|
|
|
- `with(this){return (show)?_h(_e('p'),["hello"]):void 0}`
|
|
|
+ `with(this){return (show)?_h('p',void 0,["hello"]):void 0}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate v-else directive', () => {
|
|
|
assertCodegen(
|
|
|
'<div><p v-if="show">hello</p><p v-else>world</p></div>',
|
|
|
- `with(this){return _h(_e('div'),[(show)?_h(_e('p'),["hello"]):_h(_e('p'),["world"])])}`
|
|
|
+ `with(this){return _h('div',void 0,[(show)?_h('p',void 0,["hello"]):_h('p',void 0,["world"])])}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate ref', () => {
|
|
|
assertCodegen(
|
|
|
'<p ref="component1"></p>',
|
|
|
- `with(this){return _h(_e('p',{ref:"component1"}))}`
|
|
|
+ `with(this){return _h('p',{ref:"component1"})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate ref on v-for', () => {
|
|
|
assertCodegen(
|
|
|
'<ul><li v-for="item in items" ref="component1"></li></ul>',
|
|
|
- `with(this){return _h(_e('ul'),[(items)&&_l((items),function(item){return _h(_e('li',{ref:"component1",refInFor:true}))})])}`
|
|
|
+ `with(this){return _h('ul',void 0,[(items)&&_l((items),function(item){return _h('li',{ref:"component1",refInFor:true})})])}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate v-bind directive', () => {
|
|
|
assertCodegen(
|
|
|
'<p v-bind="test"></p>',
|
|
|
- `with(this){return _h(_e('p',{hook:{"construct":function(n1,n2){_b(n1,test)}}}))}`
|
|
|
+ `with(this){return _h('p',{hook:{"construct":function(n1,n2){_b(n1,test)}}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate template tag', () => {
|
|
|
assertCodegen(
|
|
|
'<template><p>{{hello}}</p></template>',
|
|
|
- `with(this){return [_h(_e('p'),[_s(hello)])]}`
|
|
|
+ `with(this){return [_h('p',void 0,[_s(hello)])]}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate svg tag', () => {
|
|
|
assertCodegen(
|
|
|
'<svg><text>hello world</text></svg>',
|
|
|
- `with(this){return _h(_e('svg',void 0,'svg'),[_h(_e('text',void 0,'svg'),["hello world"])])}`
|
|
|
+ `with(this){return _h('svg',void 0,[_h('text',void 0,["hello world"],'svg')],'svg')}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -109,7 +109,7 @@ describe('codegen', () => {
|
|
|
<matrix>
|
|
|
</matrix>
|
|
|
</math>`,
|
|
|
- `with(this){return _h(_e('math',void 0,'math'),[_h(_e('matrix',void 0,'math'))])}`
|
|
|
+ `with(this){return _h('math',void 0,[_h('matrix',void 0,'math')],'math')}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -131,14 +131,14 @@ describe('codegen', () => {
|
|
|
assertCodegen(
|
|
|
'<slot><div>hi</div></slot>',
|
|
|
`with(this){return ($slots["default"]||[_m(0)])}`,
|
|
|
- [`with(this){return _h(_e('div'),["hi"])}`]
|
|
|
+ [`with(this){return _h('div',void 0,["hi"])}`]
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate slot target', () => {
|
|
|
assertCodegen(
|
|
|
'<p slot="one">hello world</p>',
|
|
|
- `with(this){return _h(_e('p',{slot:"one"}),["hello world"])}`
|
|
|
+ `with(this){return _h('p',{slot:"one"},["hello world"])}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -147,54 +147,54 @@ describe('codegen', () => {
|
|
|
assertCodegen(
|
|
|
'<p class="class1">hello world</p>',
|
|
|
'with(this){return _m(0)}',
|
|
|
- [`with(this){return _h(_e('p',{staticClass:"class1"}),["hello world"])}`]
|
|
|
+ [`with(this){return _h('p',{staticClass:"class1"},["hello world"])}`]
|
|
|
)
|
|
|
// dynamic
|
|
|
assertCodegen(
|
|
|
'<p :class="class1">hello world</p>',
|
|
|
- `with(this){return _h(_e('p',{class:class1}),["hello world"])}`
|
|
|
+ `with(this){return _h('p',{class:class1},["hello world"])}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate style binding', () => {
|
|
|
assertCodegen(
|
|
|
'<p :style="error">hello world</p>',
|
|
|
- `with(this){return _h(_e('p',{style:(error)}),["hello world"])}`
|
|
|
+ `with(this){return _h('p',{style:(error)},["hello world"])}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate transition', () => {
|
|
|
assertCodegen(
|
|
|
'<p transition="expand">hello world</p>',
|
|
|
- `with(this){return _h(_e('p',{transition:"expand"}),["hello world"])}`
|
|
|
+ `with(this){return _h('p',{transition:"expand"},["hello world"])}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate dynamic transition with transition on appear', () => {
|
|
|
assertCodegen(
|
|
|
`<p :transition="{name:'expand',appear:true}">hello world</p>`,
|
|
|
- `with(this){return _h(_e('p',{transition:{name:'expand',appear:true}}),["hello world"])}`
|
|
|
+ `with(this){return _h('p',{transition:{name:'expand',appear:true}},["hello world"])}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate v-show directive', () => {
|
|
|
assertCodegen(
|
|
|
'<p v-show="shown">hello world</p>',
|
|
|
- `with(this){return _h(_e('p',{directives:[{name:"show",value:(shown),expression:"shown"}],show:true}),["hello world"])}`
|
|
|
+ `with(this){return _h('p',{directives:[{name:"show",value:(shown),expression:"shown"}],show:true},["hello world"])}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate props with v-bind directive', () => {
|
|
|
assertCodegen(
|
|
|
'<p :value="msg">',
|
|
|
- `with(this){return _h(_e('p',{props:{"value":msg}}))}`
|
|
|
+ `with(this){return _h('p',{props:{"value":msg}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate attrs with v-bind directive', () => {
|
|
|
assertCodegen(
|
|
|
'<input :name="field1">',
|
|
|
- `with(this){return _h(_e('input',{attrs:{"name":field1}}))}`
|
|
|
+ `with(this){return _h('input',{attrs:{"name":field1}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -202,79 +202,79 @@ describe('codegen', () => {
|
|
|
assertCodegen(
|
|
|
'<input name="field1">',
|
|
|
`with(this){return _m(0)}`,
|
|
|
- [`with(this){return _h(_e('input',{staticAttrs:{"name":"field1"}}))}`]
|
|
|
+ [`with(this){return _h('input',{staticAttrs:{"name":"field1"}})}`]
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate events with v-on directive', () => {
|
|
|
assertCodegen(
|
|
|
'<input @input="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":onInput}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":onInput}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate events with keycode', () => {
|
|
|
assertCodegen(
|
|
|
'<input @input.enter="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function($event){if($event.keyCode!==13)return;onInput($event)}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":function($event){if($event.keyCode!==13)return;onInput($event)}}})}`
|
|
|
)
|
|
|
// multiple keycodes (delete)
|
|
|
assertCodegen(
|
|
|
'<input @input.delete="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function($event){if($event.keyCode!==8&&$event.keyCode!==46)return;onInput($event)}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":function($event){if($event.keyCode!==8&&$event.keyCode!==46)return;onInput($event)}}})}`
|
|
|
)
|
|
|
// number keycode
|
|
|
assertCodegen(
|
|
|
'<input @input.13="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function($event){if($event.keyCode!==13)return;onInput($event)}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":function($event){if($event.keyCode!==13)return;onInput($event)}}})}`
|
|
|
)
|
|
|
// custom keycode
|
|
|
assertCodegen(
|
|
|
'<input @input.custom="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function($event){if($event.keyCode!==_k("custom"))return;onInput($event)}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":function($event){if($event.keyCode!==_k("custom"))return;onInput($event)}}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate events with modifiers', () => {
|
|
|
assertCodegen(
|
|
|
'<input @input.stop="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function($event){$event.stopPropagation();onInput($event)}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":function($event){$event.stopPropagation();onInput($event)}}})}`
|
|
|
)
|
|
|
assertCodegen(
|
|
|
'<input @input.prevent="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function($event){$event.preventDefault();onInput($event)}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":function($event){$event.preventDefault();onInput($event)}}})}`
|
|
|
)
|
|
|
assertCodegen(
|
|
|
'<input @input.self="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function($event){if($event.target !== $event.currentTarget)return;onInput($event)}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":function($event){if($event.target !== $event.currentTarget)return;onInput($event)}}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate events with multiple modifers', () => {
|
|
|
assertCodegen(
|
|
|
'<input @input.stop.prevent.self="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function($event){$event.stopPropagation();$event.preventDefault();if($event.target !== $event.currentTarget)return;onInput($event)}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":function($event){$event.stopPropagation();$event.preventDefault();if($event.target !== $event.currentTarget)return;onInput($event)}}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate events with capture modifier', () => {
|
|
|
assertCodegen(
|
|
|
'<input @input.capture="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"!input":function($event){onInput($event)}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"!input":function($event){onInput($event)}}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate events with inline statement', () => {
|
|
|
assertCodegen(
|
|
|
'<input @input="curent++">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function($event){curent++}}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":function($event){curent++}}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate unhandled events', () => {
|
|
|
assertCodegen(
|
|
|
'<input @input="curent++">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":function(){}}}))}`,
|
|
|
+ `with(this){return _h('input',{on:{"input":function(){}}})}`,
|
|
|
ast => {
|
|
|
ast.events.input = undefined
|
|
|
}
|
|
|
@@ -284,26 +284,26 @@ describe('codegen', () => {
|
|
|
it('generate multiple event handlers', () => {
|
|
|
assertCodegen(
|
|
|
'<input @input="curent++" @input="onInput">',
|
|
|
- `with(this){return _h(_e('input',{on:{"input":[function($event){curent++},onInput]}}))}`
|
|
|
+ `with(this){return _h('input',{on:{"input":[function($event){curent++},onInput]}})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate component', () => {
|
|
|
assertCodegen(
|
|
|
'<my-component name="mycomponent1" :msg="msg" @notify="onNotify"><div>hi</div></my-component>',
|
|
|
- `with(this){return _h(_e('my-component',{attrs:{"msg":msg},staticAttrs:{"name":"mycomponent1"},on:{"notify":onNotify}}),function(){return [_m(0)]})}`,
|
|
|
- [`with(this){return _h(_e('div'),["hi"])}`]
|
|
|
+ `with(this){return _h('my-component',{attrs:{"msg":msg},staticAttrs:{"name":"mycomponent1"},on:{"notify":onNotify}},function(){return [_m(0)]})}`,
|
|
|
+ [`with(this){return _h('div',void 0,["hi"])}`]
|
|
|
)
|
|
|
})
|
|
|
|
|
|
it('generate is attribute', () => {
|
|
|
assertCodegen(
|
|
|
'<div is="component1"></div>',
|
|
|
- `with(this){return _h(_e("component1",{tag:"div"}))}`
|
|
|
+ `with(this){return _h("component1",{tag:"div"})}`
|
|
|
)
|
|
|
assertCodegen(
|
|
|
'<div :is="component1"></div>',
|
|
|
- `with(this){return _h(_e(component1,{tag:"div"}))}`
|
|
|
+ `with(this){return _h(component1,{tag:"div"})}`
|
|
|
)
|
|
|
})
|
|
|
|
|
|
@@ -311,26 +311,26 @@ describe('codegen', () => {
|
|
|
// have "inline-template'"
|
|
|
assertCodegen(
|
|
|
'<my-component inline-template><p>hello world</p></my-component>',
|
|
|
- `with(this){return _h(_e('my-component',{inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _h(_e('p'),["hello world"])}}]}}))}`
|
|
|
+ `with(this){return _h('my-component',{inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _h('p',void 0,["hello world"])}}]}})}`
|
|
|
)
|
|
|
// "have inline-template attrs, but not having extactly one child element
|
|
|
assertCodegen(
|
|
|
'<my-component inline-template><hr><hr></my-component>',
|
|
|
- `with(this){return _h(_e('my-component',{inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _h(_e('hr'))}}]}}))}`
|
|
|
+ `with(this){return _h('my-component',{inlineTemplate:{render:function(){with(this){return _m(0)}},staticRenderFns:[function(){with(this){return _h('hr')}}]}})}`
|
|
|
)
|
|
|
expect('Inline-template components must have exactly one child element.').toHaveBeenWarned()
|
|
|
})
|
|
|
|
|
|
it('not specified ast type', () => {
|
|
|
const res = generate(null, baseOptions)
|
|
|
- expect(res.render).toBe(`with(this){return _h(_e("div"))}`)
|
|
|
+ expect(res.render).toBe(`with(this){return _h("div")}`)
|
|
|
expect(res.staticRenderFns).toEqual([])
|
|
|
})
|
|
|
|
|
|
it('not specified directives option', () => {
|
|
|
assertCodegen(
|
|
|
'<p v-if="show">hello world</p>',
|
|
|
- `with(this){return (show)?_h(_e('p'),["hello world"]):void 0}`,
|
|
|
+ `with(this){return (show)?_h('p',void 0,["hello world"]):void 0}`,
|
|
|
{ isReservedTag }
|
|
|
)
|
|
|
})
|
|
|
@@ -341,7 +341,7 @@ describe('codegen', () => {
|
|
|
assertCodegen(
|
|
|
'<div><p>hello world</p></div>',
|
|
|
`with(this){return _m(0)}`,
|
|
|
- [`with(this){return _h(_e('div'),function(){return [_h(_e('p'),function(){return ["hello world"]})]})}`],
|
|
|
+ [`with(this){return _h('div',void 0,function(){return [_h('p',void 0,function(){return ["hello world"]})]})}`],
|
|
|
{ directives }
|
|
|
)
|
|
|
})
|