File tree 3 files changed +27
-2
lines changed
3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -248,7 +248,7 @@ describe('compiler: v-if', () => {
248
248
] )
249
249
} )
250
250
251
- test ( 'error on v-else-if missing adjacent v-if' , ( ) => {
251
+ test ( 'error on v-else-if missing adjacent v-if or v-else-if ' , ( ) => {
252
252
const onError = jest . fn ( )
253
253
254
254
const { node : node1 } = parseWithIfTransform ( `<div v-else-if="foo"/>` , {
@@ -284,6 +284,21 @@ describe('compiler: v-if', () => {
284
284
loc : node3 . loc
285
285
}
286
286
] )
287
+
288
+ const {
289
+ node : { branches }
290
+ } = parseWithIfTransform (
291
+ `<div v-if="notOk"/><div v-else/><div v-else-if="ok"/>` ,
292
+ { onError } ,
293
+ 0
294
+ )
295
+
296
+ expect ( onError . mock . calls [ 3 ] ) . toMatchObject ( [
297
+ {
298
+ code : ErrorCodes . X_V_ELSE_NO_ADJACENT_IF ,
299
+ loc : branches [ branches . length - 1 ] . loc
300
+ }
301
+ ] )
287
302
} )
288
303
289
304
test ( 'error on user key' , ( ) => {
Original file line number Diff line number Diff line change @@ -149,7 +149,7 @@ export const errorMessages: Record<ErrorCodes, string> = {
149
149
// transform errors
150
150
[ ErrorCodes . X_V_IF_NO_EXPRESSION ] : `v-if/v-else-if is missing expression.` ,
151
151
[ ErrorCodes . X_V_IF_SAME_KEY ] : `v-if/else branches must use unique keys.` ,
152
- [ ErrorCodes . X_V_ELSE_NO_ADJACENT_IF ] : `v-else/v-else-if has no adjacent v-if.` ,
152
+ [ ErrorCodes . X_V_ELSE_NO_ADJACENT_IF ] : `v-else/v-else-if has no adjacent v-if or v-else-if .` ,
153
153
[ ErrorCodes . X_V_FOR_NO_EXPRESSION ] : `v-for is missing expression.` ,
154
154
[ ErrorCodes . X_V_FOR_MALFORMED_EXPRESSION ] : `v-for has invalid expression.` ,
155
155
[ ErrorCodes . X_V_FOR_TEMPLATE_KEY_PLACEMENT ] : `<template v-for> key should be placed on the <template> tag.` ,
Original file line number Diff line number Diff line change @@ -145,6 +145,16 @@ export function processIf(
145
145
}
146
146
147
147
if ( sibling && sibling . type === NodeTypes . IF ) {
148
+ // Check if v-else was followed by v-else-if
149
+ if (
150
+ dir . name === 'else-if' &&
151
+ sibling . branches [ sibling . branches . length - 1 ] . condition === undefined
152
+ ) {
153
+ context . onError (
154
+ createCompilerError ( ErrorCodes . X_V_ELSE_NO_ADJACENT_IF , node . loc )
155
+ )
156
+ }
157
+
148
158
// move the node to the if node's branches
149
159
context . removeNode ( )
150
160
const branch = createIfBranch ( node , dir )
You can’t perform that action at this time.
0 commit comments