@@ -172,22 +172,140 @@ describe('compiler: transform v-bind', () => {
172172 const node = parseWithVBind ( `<div v-bind:[foo(bar)].camel="id"/>` , {
173173 prefixIdentifiers : true
174174 } )
175+ const props = ( node . codegenNode as VNodeCall ) . props as CallExpression
176+ expect ( props ) . toMatchObject ( {
177+ type : NodeTypes . JS_CALL_EXPRESSION ,
178+ callee : NORMALIZE_PROPS ,
179+ arguments : [
180+ {
181+ type : NodeTypes . JS_OBJECT_EXPRESSION ,
182+ properties : [
183+ {
184+ key : {
185+ children : [
186+ `_${ helperNameMap [ CAMELIZE ] } (` ,
187+ `(` ,
188+ { content : `_ctx.foo` } ,
189+ `(` ,
190+ { content : `_ctx.bar` } ,
191+ `)` ,
192+ `) || ""` ,
193+ `)`
194+ ]
195+ } ,
196+ value : {
197+ content : `_ctx.id` ,
198+ isStatic : false
199+ }
200+ }
201+ ]
202+ }
203+ ]
204+ } )
205+ } )
206+
207+ test ( '.prop modifier' , ( ) => {
208+ const node = parseWithVBind ( `<div v-bind:fooBar.prop="id"/>` )
175209 const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
176210 expect ( props . properties [ 0 ] ) . toMatchObject ( {
177211 key : {
178- children : [
179- `_${ helperNameMap [ CAMELIZE ] } (` ,
180- `(` ,
181- { content : `_ctx.foo` } ,
182- `(` ,
183- { content : `_ctx.bar` } ,
184- `)` ,
185- `) || ""` ,
186- `)`
187- ]
212+ content : `.fooBar` ,
213+ isStatic : true
188214 } ,
189215 value : {
190- content : `_ctx.id` ,
216+ content : `id` ,
217+ isStatic : false
218+ }
219+ } )
220+ } )
221+
222+ test ( '.prop modifier w/ dynamic arg' , ( ) => {
223+ const node = parseWithVBind ( `<div v-bind:[fooBar].prop="id"/>` )
224+ const props = ( node . codegenNode as VNodeCall ) . props as CallExpression
225+ expect ( props ) . toMatchObject ( {
226+ type : NodeTypes . JS_CALL_EXPRESSION ,
227+ callee : NORMALIZE_PROPS ,
228+ arguments : [
229+ {
230+ type : NodeTypes . JS_OBJECT_EXPRESSION ,
231+ properties : [
232+ {
233+ key : {
234+ content : '`.${fooBar || ""}`' ,
235+ isStatic : false
236+ } ,
237+ value : {
238+ content : `id` ,
239+ isStatic : false
240+ }
241+ }
242+ ]
243+ }
244+ ]
245+ } )
246+ } )
247+
248+ test ( '.prop modifier w/ dynamic arg + prefixIdentifiers' , ( ) => {
249+ const node = parseWithVBind ( `<div v-bind:[foo(bar)].prop="id"/>` , {
250+ prefixIdentifiers : true
251+ } )
252+ const props = ( node . codegenNode as VNodeCall ) . props as CallExpression
253+ expect ( props ) . toMatchObject ( {
254+ type : NodeTypes . JS_CALL_EXPRESSION ,
255+ callee : NORMALIZE_PROPS ,
256+ arguments : [
257+ {
258+ type : NodeTypes . JS_OBJECT_EXPRESSION ,
259+ properties : [
260+ {
261+ key : {
262+ children : [
263+ `'.' + (` ,
264+ `(` ,
265+ { content : `_ctx.foo` } ,
266+ `(` ,
267+ { content : `_ctx.bar` } ,
268+ `)` ,
269+ `) || ""` ,
270+ `)`
271+ ]
272+ } ,
273+ value : {
274+ content : `_ctx.id` ,
275+ isStatic : false
276+ }
277+ }
278+ ]
279+ }
280+ ]
281+ } )
282+ } )
283+
284+ test ( '.prop modifier (shorthand)' , ( ) => {
285+ const node = parseWithVBind ( `<div .fooBar="id"/>` )
286+ const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
287+ expect ( props . properties [ 0 ] ) . toMatchObject ( {
288+ key : {
289+ content : `.fooBar` ,
290+ isStatic : true
291+ } ,
292+ value : {
293+ content : `id` ,
294+ isStatic : false
295+ }
296+ } )
297+ } )
298+
299+ test ( '.attr modifier' , ( ) => {
300+ const node = parseWithVBind ( `<div v-bind:foo-bar.attr="id"/>` )
301+ const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
302+ expect ( props . properties [ 0 ] ) . toMatchObject ( {
303+ key : {
304+ content : `^foo-bar` ,
305+ isStatic : true
306+ } ,
307+ value : {
308+ content : `id` ,
191309 isStatic : false
192310 }
193311 } )
0 commit comments