From 8abc754d5d86d9dfd5a7927b846f1a743f352364 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 1 Dec 2023 11:56:29 +0800 Subject: [PATCH] feat(compiler): lift vnode hooks deprecation warning to error --- .../__tests__/transforms/vOn.spec.ts | 28 +++++++++---------- packages/compiler-core/src/errors.ts | 4 +-- packages/compiler-core/src/transforms/vOn.ts | 4 +-- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/compiler-core/__tests__/transforms/vOn.spec.ts b/packages/compiler-core/__tests__/transforms/vOn.spec.ts index 218281ba762..746cfc2a01d 100644 --- a/packages/compiler-core/__tests__/transforms/vOn.spec.ts +++ b/packages/compiler-core/__tests__/transforms/vOn.spec.ts @@ -437,22 +437,22 @@ describe('compiler: transform v-on', () => { }) }) - // TODO remove in 3.4 - test('case conversion for vnode hooks', () => { - const { node } = parseWithVOn(`
`) - expect((node.codegenNode as VNodeCall).props).toMatchObject({ - properties: [ - { - key: { - content: `onVnodeMounted` - }, - value: { - content: `onMount` - } + test('error for vnode hooks', () => { + const onError = vi.fn() + parseWithVOn(`
`, { onError }) + expect(onError.mock.calls[0][0]).toMatchObject({ + code: ErrorCodes.X_VNODE_HOOKS, + loc: { + start: { + line: 1, + column: 11 + }, + end: { + line: 1, + column: 24 } - ] + } }) - expect('@vnode-* hooks in templates are deprecated').toHaveBeenWarned() }) test('vue: prefixed events', () => { diff --git a/packages/compiler-core/src/errors.ts b/packages/compiler-core/src/errors.ts index ac11b7e3d55..7090a5a26d5 100644 --- a/packages/compiler-core/src/errors.ts +++ b/packages/compiler-core/src/errors.ts @@ -90,6 +90,7 @@ export enum ErrorCodes { X_V_MODEL_ON_PROPS, X_INVALID_EXPRESSION, X_KEEP_ALIVE_INVALID_CHILDREN, + X_VNODE_HOOKS, // generic errors X_PREFIX_ID_NOT_SUPPORTED, @@ -98,7 +99,6 @@ export enum ErrorCodes { X_SCOPE_ID_NOT_SUPPORTED, // deprecations - DEPRECATION_VNODE_HOOKS, DEPRECATION_V_IS, // Special value for higher-order compilers to pick up the last code @@ -176,6 +176,7 @@ export const errorMessages: Record = { [ErrorCodes.X_V_MODEL_ON_PROPS]: `v-model cannot be used on a prop, because local prop bindings are not writable.\nUse a v-bind binding combined with a v-on listener that emits update:x event instead.`, [ErrorCodes.X_INVALID_EXPRESSION]: `Error parsing JavaScript expression: `, [ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN]: ` expects exactly one child component.`, + [ErrorCodes.X_VNODE_HOOKS]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`, // generic errors [ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED]: `"prefixIdentifiers" option is not supported in this build of compiler.`, @@ -184,7 +185,6 @@ export const errorMessages: Record = { [ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED]: `"scopeId" option is only supported in module mode.`, // deprecations - [ErrorCodes.DEPRECATION_VNODE_HOOKS]: `@vnode-* hooks in templates are deprecated. Use the vue: prefix instead. For example, @vnode-mounted should be changed to @vue:mounted. @vnode-* hooks support will be removed in 3.4.`, [ErrorCodes.DEPRECATION_V_IS]: `v-is="component-name" has been deprecated. Use is="vue:component-name" instead. v-is support will be removed in 3.4.`, // just to fulfill types diff --git a/packages/compiler-core/src/transforms/vOn.ts b/packages/compiler-core/src/transforms/vOn.ts index 3deee202418..1c15675ce36 100644 --- a/packages/compiler-core/src/transforms/vOn.ts +++ b/packages/compiler-core/src/transforms/vOn.ts @@ -44,9 +44,7 @@ export const transformOn: DirectiveTransform = ( if (arg.isStatic) { let rawName = arg.content if (__DEV__ && rawName.startsWith('vnode')) { - context.onWarn( - createCompilerError(ErrorCodes.DEPRECATION_VNODE_HOOKS, arg.loc) - ) + context.onError(createCompilerError(ErrorCodes.X_VNODE_HOOKS, arg.loc)) } if (rawName.startsWith('vue:')) { rawName = `vnode-${rawName.slice(4)}`