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', () => {
301301 ] )
302302 } )
303303
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+
304323 test ( 'error on user key' , ( ) => {
305324 const onError = vi . fn ( )
306325 // dynamic
Original file line number Diff line number Diff line change @@ -141,9 +141,9 @@ export function processIf(
141141 }
142142
143143 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
145145 if (
146- dir . name === 'else-if' &&
146+ ( dir . name === 'else-if' || dir . name === 'else' ) &&
147147 sibling . branches [ sibling . branches . length - 1 ] . condition === undefined
148148 ) {
149149 context . onError (
You can’t perform that action at this time.
0 commit comments