Skip to content

Commit

Permalink
feat(compiler): lift vnode hooks deprecation warning to error
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 1, 2023
1 parent 7f00ec2 commit 8abc754
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
28 changes: 14 additions & 14 deletions packages/compiler-core/__tests__/transforms/vOn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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.`,
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions packages/compiler-core/src/transforms/vOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`
Expand Down

0 comments on commit 8abc754

Please sign in to comment.