]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(compiler): lift vnode hooks deprecation warning to error
authorEvan You <yyx990803@gmail.com>
Fri, 1 Dec 2023 03:56:29 +0000 (11:56 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 1 Dec 2023 03:56:29 +0000 (11:56 +0800)
packages/compiler-core/__tests__/transforms/vOn.spec.ts
packages/compiler-core/src/errors.ts
packages/compiler-core/src/transforms/vOn.ts

index 218281ba762fe582f0babc12dbfd765bafad7fe1..746cfc2a01de288406d1e4d144dbe7ea311e9a79 100644 (file)
@@ -437,22 +437,22 @@ describe('compiler: transform v-on', () => {
     })
   })
 
-  // TODO remove in 3.4
-  test('case conversion for vnode hooks', () => {
-    const { node } = parseWithVOn(`<div v-on:vnode-mounted="onMount"/>`)
-    expect((node.codegenNode as VNodeCall).props).toMatchObject({
-      properties: [
-        {
-          key: {
-            content: `onVnodeMounted`
-          },
-          value: {
-            content: `onMount`
-          }
+  test('error for vnode hooks', () => {
+    const onError = vi.fn()
+    parseWithVOn(`<div v-on:vnode-mounted="onMount"/>`, { 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', () => {
index ac11b7e3d55377efbe6c0a2858c8803a6606ed2c..7090a5a26d59d9c8cab8baffe0a577762a56c179 100644 (file)
@@ -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, string> = {
   [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]: `<KeepAlive> 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, string> = {
   [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
index 3deee2024182063f1c3837ba40d4a74b01717475..1c15675ce36733c9ab2d119a165bbe2220877a1e 100644 (file)
@@ -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)}`