fix(compiler-core): add check when v-else-if is behind v-else (#4603)

This commit is contained in:
就是喜欢陈粒
2021-09-22 00:59:38 +08:00
committed by GitHub
parent 5aa4255808
commit 5addef8ecd
3 changed files with 27 additions and 2 deletions

View File

@@ -248,7 +248,7 @@ describe('compiler: v-if', () => {
])
})
test('error on v-else-if missing adjacent v-if', () => {
test('error on v-else-if missing adjacent v-if or v-else-if', () => {
const onError = jest.fn()
const { node: node1 } = parseWithIfTransform(`<div v-else-if="foo"/>`, {
@@ -284,6 +284,21 @@ describe('compiler: v-if', () => {
loc: node3.loc
}
])
const {
node: { branches }
} = parseWithIfTransform(
`<div v-if="notOk"/><div v-else/><div v-else-if="ok"/>`,
{ onError },
0
)
expect(onError.mock.calls[3]).toMatchObject([
{
code: ErrorCodes.X_V_ELSE_NO_ADJACENT_IF,
loc: branches[branches.length - 1].loc
}
])
})
test('error on user key', () => {