diff --git a/packages/compiler-core/__tests__/transforms/vIf.spec.ts b/packages/compiler-core/__tests__/transforms/vIf.spec.ts index 9d4619aa..a93c6053 100644 --- a/packages/compiler-core/__tests__/transforms/vIf.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vIf.spec.ts @@ -285,10 +285,23 @@ describe('compiler: v-if', () => { test('error on user key', () => { const onError = jest.fn() - parseWithIfTransform(`
`, { onError }) + // dynamic + parseWithIfTransform( + `
`, + { onError } + ) expect(onError.mock.calls[0]).toMatchObject([ { - code: ErrorCodes.X_V_IF_KEY + code: ErrorCodes.X_V_IF_SAME_KEY + } + ]) + // static + parseWithIfTransform(`
`, { + onError + }) + expect(onError.mock.calls[1]).toMatchObject([ + { + code: ErrorCodes.X_V_IF_SAME_KEY } ]) }) diff --git a/packages/compiler-core/src/ast.ts b/packages/compiler-core/src/ast.ts index 6b85e150..42c93402 100644 --- a/packages/compiler-core/src/ast.ts +++ b/packages/compiler-core/src/ast.ts @@ -243,6 +243,7 @@ export interface IfBranchNode extends Node { type: NodeTypes.IF_BRANCH condition: ExpressionNode | undefined // else children: TemplateChildNode[] + userKey?: AttributeNode | DirectiveNode } export interface ForNode extends Node { diff --git a/packages/compiler-core/src/errors.ts b/packages/compiler-core/src/errors.ts index 58b10259..28c603a8 100644 --- a/packages/compiler-core/src/errors.ts +++ b/packages/compiler-core/src/errors.ts @@ -63,7 +63,7 @@ export const enum ErrorCodes { // transform errors X_V_IF_NO_EXPRESSION, - X_V_IF_KEY, + X_V_IF_SAME_KEY, X_V_ELSE_NO_ADJACENT_IF, X_V_FOR_NO_EXPRESSION, X_V_FOR_MALFORMED_EXPRESSION, @@ -136,10 +136,7 @@ export const errorMessages: { [code: number]: string } = { // transform errors [ErrorCodes.X_V_IF_NO_EXPRESSION]: `v-if/v-else-if is missing expression.`, - [ErrorCodes.X_V_IF_KEY]: - `v-if branches must use compiler generated keys. ` + - `In many cases, you can simply remove this key. ` + - `If this tag is inside of a