File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
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 @@ -150,6 +150,15 @@ export function processIf(
150150 createCompilerError ( ErrorCodes . X_V_ELSE_NO_ADJACENT_IF , node . loc ) ,
151151 )
152152 }
153+ // Check that there should not be two adjacent v-else
154+ if (
155+ dir . name === 'else' &&
156+ sibling . branches [ sibling . branches . length - 1 ] . condition === undefined
157+ ) {
158+ context . onError (
159+ createCompilerError ( ErrorCodes . X_V_ELSE_NO_ADJACENT_IF , node . loc ) ,
160+ )
161+ }
153162
154163 // move the node to the if node's branches
155164 context . removeNode ( )
You can’t perform that action at this time.
0 commit comments