@@ -74,6 +74,62 @@ describe('codegen', () => {
7474 )
7575 } )
7676
77+ it ( 'generate v-local directive' , ( ) => {
78+ assertCodegen (
79+ '<div v-local:value="some.deep.prop">{{value}}</div>' ,
80+ `with(this){return ((function(value){return _c('div',{},[_v(_s(value))])})(some.deep.prop))}`
81+ )
82+ } )
83+
84+ it ( 'generate multi v-local directive' , ( ) => {
85+ assertCodegen (
86+ '<div v-local:foo="some.deep.prop" v-local:bar="other.deep.prop">{{foo}}{{bar}}</div>' ,
87+ `with(this){return ((function(foo,bar){return _c('div',{},[_v(_s(foo)+_s(bar))])})(some.deep.prop,other.deep.prop))}`
88+ )
89+ } )
90+
91+ it ( 'generate v-local directive with v-if' , ( ) => {
92+ assertCodegen (
93+ '<div v-local:foo="some.deep.prop" v-if="foo.show">{{foo.value}}</div>' ,
94+ `with(this){return ((function(foo){return (foo.show)?_c('div',{},[_v(_s(foo.value))]):_e()})(some.deep.prop))}`
95+ )
96+ } )
97+
98+ it ( 'generate v-local directive with v-for' , ( ) => {
99+ assertCodegen (
100+ '<div><span v-for="item in items" v-local:foo="item.deep.prop">{{foo}}</span></div>' ,
101+ `with(this){return _c('div',_l((items),function(item){return ((function(foo){return _c('span',{},[_v(_s(foo))])})(item.deep.prop))}))}`
102+ )
103+ } )
104+
105+ it ( 'generate v-local directive with other v-local' , ( ) => {
106+ assertCodegen (
107+ '<div v-local:foo="some.deep.prop"><span v-local:bar="foo.deep.prop">{{bar}}</span></div>' ,
108+ `with(this){return ((function(foo){return _c('div',{},[((function(bar){return _c('span',{},[_v(_s(bar))])})(foo.deep.prop))])})(some.deep.prop))}`
109+ )
110+ } )
111+
112+ it ( 'generate v-local directive with scoped-slot' , ( ) => {
113+ assertCodegen (
114+ '<foo><div v-local:baz="bar.deep.prop" slot-scope="bar">{{baz}}</div></foo>' ,
115+ `with(this){return _c('foo',{scopedSlots:_u([{key:"default",fn:function(bar){return ((function(baz){return _c('div',{},[_v(_s(baz))])})(bar.deep.prop))}}])})}`
116+ )
117+ } )
118+
119+ it ( 'generate v-local directive with template tag' , ( ) => {
120+ assertCodegen (
121+ '<div><template v-local:v="some.deep.prop"><span>{{ v }}</span></template></div>' ,
122+ `with(this){return _c('div',[((function(v){return [_c('span',[_v(_s(v))])]})(some.deep.prop))],2)}`
123+ )
124+ } )
125+
126+ it ( 'generate v-local directive with scoped-slot and template tag' , ( ) => {
127+ assertCodegen (
128+ '<test><template slot="item" slot-scope="props" v-local:v="props.text"><span>{{ v }}</span></template></test>' ,
129+ `with(this){return _c('test',{scopedSlots:_u([{key:"item",fn:function(props){return ((function(v){return [_c('span',[_v(_s(v))])]})(props.text))}}])})}`
130+ )
131+ } )
132+
77133 it ( 'generate v-if directive' , ( ) => {
78134 assertCodegen (
79135 '<p v-if="show">hello</p>' ,
0 commit comments