diff --git a/packages/compiler-core/__tests__/transforms/vIf.spec.ts b/packages/compiler-core/__tests__/transforms/vIf.spec.ts index dcf8d186001..5c36885670f 100644 --- a/packages/compiler-core/__tests__/transforms/vIf.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vIf.spec.ts @@ -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(`
`, { @@ -284,6 +284,21 @@ describe('compiler: v-if', () => { loc: node3.loc } ]) + + const { + node: { branches } + } = parseWithIfTransform( + `
`, + { 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', () => { diff --git a/packages/compiler-core/src/errors.ts b/packages/compiler-core/src/errors.ts index 1f2afac7e66..a6f2f3f8566 100644 --- a/packages/compiler-core/src/errors.ts +++ b/packages/compiler-core/src/errors.ts @@ -149,7 +149,7 @@ export const errorMessages: Record = { // transform errors [ErrorCodes.X_V_IF_NO_EXPRESSION]: `v-if/v-else-if is missing expression.`, [ErrorCodes.X_V_IF_SAME_KEY]: `v-if/else branches must use unique keys.`, - [ErrorCodes.X_V_ELSE_NO_ADJACENT_IF]: `v-else/v-else-if has no adjacent v-if.`, + [ErrorCodes.X_V_ELSE_NO_ADJACENT_IF]: `v-else/v-else-if has no adjacent v-if or v-else-if.`, [ErrorCodes.X_V_FOR_NO_EXPRESSION]: `v-for is missing expression.`, [ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION]: `v-for has invalid expression.`, [ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT]: `