From bbd8301a1344b02de635ea16d4822db1c343bd12 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 21 Apr 2023 15:26:01 +0800 Subject: [PATCH] feat(deprecation): deprecate v-is directive --- packages/compiler-core/src/errors.ts | 4 +++- packages/compiler-core/src/parse.ts | 2 +- packages/compiler-core/src/transforms/transformElement.ts | 7 ++++++- packages/compiler-dom/src/errors.ts | 6 ++++-- packages/compiler-ssr/src/errors.ts | 6 ++++-- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/packages/compiler-core/src/errors.ts b/packages/compiler-core/src/errors.ts index 9a91b91a650..36ab783edbe 100644 --- a/packages/compiler-core/src/errors.ts +++ b/packages/compiler-core/src/errors.ts @@ -99,6 +99,7 @@ export const enum ErrorCodes { // deprecations DEPRECATION_VNODE_HOOKS, + DEPRECATION_V_IS, // Special value for higher-order compilers to pick up the last code // to avoid collision of error codes. This should always be kept as the last @@ -183,7 +184,8 @@ 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.`, + [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 [ErrorCodes.__EXTEND_POINT__]: `` diff --git a/packages/compiler-core/src/parse.ts b/packages/compiler-core/src/parse.ts index 93ecf7be399..73a1953348e 100644 --- a/packages/compiler-core/src/parse.ts +++ b/packages/compiler-core/src/parse.ts @@ -687,7 +687,7 @@ function isComponent( } } else { // directive - // v-is (TODO Deprecate) + // v-is (TODO: remove in 3.4) if (p.name === 'is') { return true } else if ( diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index 52612edd612..253b6be5efa 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -285,9 +285,14 @@ export function resolveComponentType( } } - // 1.5 v-is (TODO: Deprecate) + // 1.5 v-is (TODO: remove in 3.4) const isDir = !isExplicitDynamic && findDir(node, 'is') if (isDir && isDir.exp) { + if (__DEV__) { + context.onWarn( + createCompilerError(ErrorCodes.DEPRECATION_V_IS, isDir.loc) + ) + } return createCallExpression(context.helper(RESOLVE_DYNAMIC_COMPONENT), [ isDir.exp ]) diff --git a/packages/compiler-dom/src/errors.ts b/packages/compiler-dom/src/errors.ts index d129dc08d4e..b519dbdb762 100644 --- a/packages/compiler-dom/src/errors.ts +++ b/packages/compiler-dom/src/errors.ts @@ -21,7 +21,7 @@ export function createDOMCompilerError( } export const enum DOMErrorCodes { - X_V_HTML_NO_EXPRESSION = 52 /* ErrorCodes.__EXTEND_POINT__ */, + X_V_HTML_NO_EXPRESSION = 53 /* ErrorCodes.__EXTEND_POINT__ */, X_V_HTML_WITH_CHILDREN, X_V_TEXT_NO_EXPRESSION, X_V_TEXT_WITH_CHILDREN, @@ -41,7 +41,9 @@ if (__TEST__) { // errors out if there are collisions. if (DOMErrorCodes.X_V_HTML_NO_EXPRESSION < ErrorCodes.__EXTEND_POINT__) { throw new Error( - 'DOMErrorCodes need to be updated to match extension point from core ErrorCodes.' + `DOMErrorCodes need to be updated to ${ + ErrorCodes.__EXTEND_POINT__ + 1 + } to match extension point from core ErrorCodes.` ) } } diff --git a/packages/compiler-ssr/src/errors.ts b/packages/compiler-ssr/src/errors.ts index 67622c1beb9..e8e5a3a541d 100644 --- a/packages/compiler-ssr/src/errors.ts +++ b/packages/compiler-ssr/src/errors.ts @@ -17,7 +17,7 @@ export function createSSRCompilerError( } export const enum SSRErrorCodes { - X_SSR_UNSAFE_ATTR_NAME = 62 /* DOMErrorCodes.__EXTEND_POINT__ */, + X_SSR_UNSAFE_ATTR_NAME = 65 /* DOMErrorCodes.__EXTEND_POINT__ */, X_SSR_NO_TELEPORT_TARGET, X_SSR_INVALID_AST_NODE } @@ -28,7 +28,9 @@ if (__TEST__) { // errors out if there are collisions. if (SSRErrorCodes.X_SSR_UNSAFE_ATTR_NAME < DOMErrorCodes.__EXTEND_POINT__) { throw new Error( - 'SSRErrorCodes need to be updated to match extension point from core DOMErrorCodes.' + `SSRErrorCodes need to be updated to ${ + DOMErrorCodes.__EXTEND_POINT__ + 1 + } to match extension point from core DOMErrorCodes.` ) } }