Skip to content

Commit

Permalink
feat(deprecation): deprecate v-is directive
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 21, 2023
1 parent 5f0394a commit bbd8301
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion packages/compiler-core/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -183,7 +184,8 @@ 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.`,
[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__]: ``
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
7 changes: 6 additions & 1 deletion packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
])
Expand Down
6 changes: 4 additions & 2 deletions packages/compiler-dom/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.`
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions packages/compiler-ssr/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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.`
)
}
}
Expand Down

0 comments on commit bbd8301

Please sign in to comment.