])
})
+ test('error on adjacent v-else', () => {
+ const onError = vi.fn()
+
+ const {
+ node: { branches },
+ } = parseWithIfTransform(
+ `<div v-if="false"/><div v-else/><div v-else/>`,
+ { onError },
+ 0,
+ )
+
+ expect(onError.mock.calls[0]).toMatchObject([
+ {
+ code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
+ loc: branches[branches.length - 1].loc,
+ },
+ ])
+ })
+
test('error on user key', () => {
const onError = vi.fn()
// dynamic
}
if (sibling && sibling.type === NodeTypes.IF) {
- // Check if v-else was followed by v-else-if
+ // Check if v-else was followed by v-else-if or there are two adjacent v-else
if (
- dir.name === 'else-if' &&
+ (dir.name === 'else-if' || dir.name === 'else') &&
sibling.branches[sibling.branches.length - 1].condition === undefined
) {
context.onError(