File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -301,6 +301,25 @@ describe('compiler: v-if', () => {
301
301
] )
302
302
} )
303
303
304
+ test ( 'error on adjacent v-else' , ( ) => {
305
+ const onError = vi . fn ( )
306
+
307
+ const {
308
+ node : { branches } ,
309
+ } = parseWithIfTransform (
310
+ `<div v-if="false"/><div v-else/><div v-else/>` ,
311
+ { onError } ,
312
+ 0 ,
313
+ )
314
+
315
+ expect ( onError . mock . calls [ 0 ] ) . toMatchObject ( [
316
+ {
317
+ code : ErrorCodes . X_V_ELSE_NO_ADJACENT_IF ,
318
+ loc : branches [ branches . length - 1 ] . loc ,
319
+ } ,
320
+ ] )
321
+ } )
322
+
304
323
test ( 'error on user key' , ( ) => {
305
324
const onError = vi . fn ( )
306
325
// dynamic
Original file line number Diff line number Diff line change @@ -141,9 +141,9 @@ export function processIf(
141
141
}
142
142
143
143
if ( sibling && sibling . type === NodeTypes . IF ) {
144
- // Check if v-else was followed by v-else-if
144
+ // Check if v-else was followed by v-else-if or there are two adjacent v-else
145
145
if (
146
- dir . name === 'else-if' &&
146
+ ( dir . name === 'else-if' || dir . name === 'else' ) &&
147
147
sibling . branches [ sibling . branches . length - 1 ] . condition === undefined
148
148
) {
149
149
context . onError (
You can’t perform that action at this time.
0 commit comments