@@ -72,6 +72,60 @@ describe('compiler: transform v-bind', () => {
72
72
} )
73
73
} )
74
74
75
+ test ( 'no expression' , ( ) => {
76
+ const node = parseWithVBind ( `<div v-bind:id />` )
77
+ const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
78
+ expect ( props . properties [ 0 ] ) . toMatchObject ( {
79
+ key : {
80
+ content : `id` ,
81
+ isStatic : true ,
82
+ loc : {
83
+ start : {
84
+ line : 1 ,
85
+ column : 13 ,
86
+ offset : 12
87
+ } ,
88
+ end : {
89
+ line : 1 ,
90
+ column : 15 ,
91
+ offset : 14
92
+ }
93
+ }
94
+ } ,
95
+ value : {
96
+ content : `id` ,
97
+ isStatic : false ,
98
+ loc : {
99
+ start : {
100
+ line : 1 ,
101
+ column : 1 ,
102
+ offset : 0
103
+ } ,
104
+ end : {
105
+ line : 1 ,
106
+ column : 1 ,
107
+ offset : 0
108
+ }
109
+ }
110
+ }
111
+ } )
112
+ } )
113
+
114
+ test ( 'no expression (shorthand)' , ( ) => {
115
+ const node = parseWithVBind ( `<div :id />` )
116
+ const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
117
+ expect ( props . properties [ 0 ] ) . toMatchObject ( {
118
+ key : {
119
+ content : `id` ,
120
+ isStatic : true
121
+ } ,
122
+ value : {
123
+ content : `id` ,
124
+ isStatic : false
125
+ }
126
+ } )
127
+ } )
128
+
75
129
test ( 'dynamic arg' , ( ) => {
76
130
const node = parseWithVBind ( `<div v-bind:[id]="id"/>` )
77
131
const props = ( node . codegenNode as VNodeCall ) . props as CallExpression
@@ -98,9 +152,9 @@ describe('compiler: transform v-bind', () => {
98
152
} )
99
153
} )
100
154
101
- test ( 'should error if no expression' , ( ) => {
155
+ test ( 'should error if empty expression' , ( ) => {
102
156
const onError = vi . fn ( )
103
- const node = parseWithVBind ( `<div v-bind:arg />` , { onError } )
157
+ const node = parseWithVBind ( `<div v-bind:arg="" />` , { onError } )
104
158
const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
105
159
expect ( onError . mock . calls [ 0 ] [ 0 ] ) . toMatchObject ( {
106
160
code : ErrorCodes . X_V_BIND_NO_EXPRESSION ,
@@ -111,7 +165,7 @@ describe('compiler: transform v-bind', () => {
111
165
} ,
112
166
end : {
113
167
line : 1 ,
114
- column : 16
168
+ column : 19
115
169
}
116
170
}
117
171
} )
@@ -142,6 +196,21 @@ describe('compiler: transform v-bind', () => {
142
196
} )
143
197
} )
144
198
199
+ test ( '.camel modifier w/ no expression' , ( ) => {
200
+ const node = parseWithVBind ( `<div v-bind:foo-bar.camel />` )
201
+ const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
202
+ expect ( props . properties [ 0 ] ) . toMatchObject ( {
203
+ key : {
204
+ content : `fooBar` ,
205
+ isStatic : true
206
+ } ,
207
+ value : {
208
+ content : `fooBar` ,
209
+ isStatic : false
210
+ }
211
+ } )
212
+ } )
213
+
145
214
test ( '.camel modifier w/ dynamic arg' , ( ) => {
146
215
const node = parseWithVBind ( `<div v-bind:[foo].camel="id"/>` )
147
216
const props = ( node . codegenNode as VNodeCall ) . props as CallExpression
@@ -219,6 +288,21 @@ describe('compiler: transform v-bind', () => {
219
288
} )
220
289
} )
221
290
291
+ test ( '.prop modifier w/ no expression' , ( ) => {
292
+ const node = parseWithVBind ( `<div v-bind:fooBar.prop />` )
293
+ const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
294
+ expect ( props . properties [ 0 ] ) . toMatchObject ( {
295
+ key : {
296
+ content : `.fooBar` ,
297
+ isStatic : true
298
+ } ,
299
+ value : {
300
+ content : `fooBar` ,
301
+ isStatic : false
302
+ }
303
+ } )
304
+ } )
305
+
222
306
test ( '.prop modifier w/ dynamic arg' , ( ) => {
223
307
const node = parseWithVBind ( `<div v-bind:[fooBar].prop="id"/>` )
224
308
const props = ( node . codegenNode as VNodeCall ) . props as CallExpression
@@ -296,6 +380,21 @@ describe('compiler: transform v-bind', () => {
296
380
} )
297
381
} )
298
382
383
+ test ( '.prop modifier (shortband) w/ no expression' , ( ) => {
384
+ const node = parseWithVBind ( `<div .fooBar />` )
385
+ const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
386
+ expect ( props . properties [ 0 ] ) . toMatchObject ( {
387
+ key : {
388
+ content : `.fooBar` ,
389
+ isStatic : true
390
+ } ,
391
+ value : {
392
+ content : `fooBar` ,
393
+ isStatic : false
394
+ }
395
+ } )
396
+ } )
397
+
299
398
test ( '.attr modifier' , ( ) => {
300
399
const node = parseWithVBind ( `<div v-bind:foo-bar.attr="id"/>` )
301
400
const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
@@ -310,4 +409,19 @@ describe('compiler: transform v-bind', () => {
310
409
}
311
410
} )
312
411
} )
412
+
413
+ test ( '.attr modifier w/ no expression' , ( ) => {
414
+ const node = parseWithVBind ( `<div v-bind:foo-bar.attr />` )
415
+ const props = ( node . codegenNode as VNodeCall ) . props as ObjectExpression
416
+ expect ( props . properties [ 0 ] ) . toMatchObject ( {
417
+ key : {
418
+ content : `^foo-bar` ,
419
+ isStatic : true
420
+ } ,
421
+ value : {
422
+ content : `fooBar` ,
423
+ isStatic : false
424
+ }
425
+ } )
426
+ } )
313
427
} )
0 commit comments