feat(compiler): lift vnode hooks deprecation warning to error

This commit is contained in:
Evan You 2023-12-01 11:56:29 +08:00
parent 7f00ec2d97
commit 8abc754d5d
3 changed files with 17 additions and 19 deletions

View File

@ -437,22 +437,22 @@ describe('compiler: transform v-on', () => {
}) })
}) })
// TODO remove in 3.4 test('error for vnode hooks', () => {
test('case conversion for vnode hooks', () => { const onError = vi.fn()
const { node } = parseWithVOn(`<div v-on:vnode-mounted="onMount"/>`) parseWithVOn(`<div v-on:vnode-mounted="onMount"/>`, { onError })
expect((node.codegenNode as VNodeCall).props).toMatchObject({ expect(onError.mock.calls[0][0]).toMatchObject({
properties: [ code: ErrorCodes.X_VNODE_HOOKS,
{ loc: {
key: { start: {
content: `onVnodeMounted` line: 1,
}, column: 11
value: { },
content: `onMount` end: {
} line: 1,
column: 24
} }
] }
}) })
expect('@vnode-* hooks in templates are deprecated').toHaveBeenWarned()
}) })
test('vue: prefixed events', () => { test('vue: prefixed events', () => {

View File

@ -90,6 +90,7 @@ export enum ErrorCodes {
X_V_MODEL_ON_PROPS, X_V_MODEL_ON_PROPS,
X_INVALID_EXPRESSION, X_INVALID_EXPRESSION,
X_KEEP_ALIVE_INVALID_CHILDREN, X_KEEP_ALIVE_INVALID_CHILDREN,
X_VNODE_HOOKS,
// generic errors // generic errors
X_PREFIX_ID_NOT_SUPPORTED, X_PREFIX_ID_NOT_SUPPORTED,
@ -98,7 +99,6 @@ export enum ErrorCodes {
X_SCOPE_ID_NOT_SUPPORTED, X_SCOPE_ID_NOT_SUPPORTED,
// deprecations // deprecations
DEPRECATION_VNODE_HOOKS,
DEPRECATION_V_IS, DEPRECATION_V_IS,
// Special value for higher-order compilers to pick up the last code // 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_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_INVALID_EXPRESSION]: `Error parsing JavaScript expression: `,
[ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN]: `<KeepAlive> expects exactly one child component.`, [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 // generic errors
[ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED]: `"prefixIdentifiers" option is not supported in this build of compiler.`, [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.`, [ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED]: `"scopeId" option is only supported in module mode.`,
// deprecations // 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.`, [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 // just to fulfill types

View File

@ -44,9 +44,7 @@ export const transformOn: DirectiveTransform = (
if (arg.isStatic) { if (arg.isStatic) {
let rawName = arg.content let rawName = arg.content
if (__DEV__ && rawName.startsWith('vnode')) { if (__DEV__ && rawName.startsWith('vnode')) {
context.onWarn( context.onError(createCompilerError(ErrorCodes.X_VNODE_HOOKS, arg.loc))
createCompilerError(ErrorCodes.DEPRECATION_VNODE_HOOKS, arg.loc)
)
} }
if (rawName.startsWith('vue:')) { if (rawName.startsWith('vue:')) {
rawName = `vnode-${rawName.slice(4)}` rawName = `vnode-${rawName.slice(4)}`