Skip to content

Commit d974adb

Browse files
committed
wip: is usage compat
1 parent e130c7d commit d974adb

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

packages/compiler-core/src/compat/compatConfig.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ type DeprecationData = {
3131

3232
const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
3333
[CompilerDeprecationTypes.IS_ON_ELEMENT]: {
34-
message: ``,
34+
message:
35+
`Platform-native elements with "is" prop will no longer be ` +
36+
`treated as components in Vue 3 unless the "is" value is explicitly ` +
37+
`prefixed with "vue:".`,
3538
link: `https://v3.vuejs.org/guide/migration/custom-elements-interop.html`
3639
},
3740

packages/compiler-core/src/parse.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ import {
3030
createRoot,
3131
ConstantTypes
3232
} from './ast'
33-
import { CompilerCompatOptions } from './compat/compatConfig'
33+
import {
34+
checkCompatEnabled,
35+
CompilerCompatOptions,
36+
CompilerDeprecationTypes
37+
} from './compat/compatConfig'
3438

3539
type OptionalOptions =
3640
| 'isNativeTag'
@@ -499,14 +503,28 @@ function parseTag(
499503
let tagType = ElementTypes.ELEMENT
500504
const options = context.options
501505
if (!context.inVPre && !options.isCustomElement(tag)) {
502-
const hasVIs = props.some(
503-
p =>
504-
p.name === 'is' &&
505-
// v-is="xxx" (TODO: deprecate)
506-
(p.type === NodeTypes.DIRECTIVE ||
507-
// is="vue:xxx"
508-
(p.value && p.value.content.startsWith('vue:')))
509-
)
506+
const hasVIs = props.some(p => {
507+
if (p.name !== 'is') return
508+
// v-is="xxx" (TODO: deprecate)
509+
if (p.type === NodeTypes.DIRECTIVE) {
510+
return true
511+
}
512+
// is="vue:xxx"
513+
if (p.value && p.value.content.startsWith('vue:')) {
514+
return true
515+
}
516+
// in compat mode, any is usage is considered a component
517+
if (
518+
__COMPAT__ &&
519+
checkCompatEnabled(
520+
CompilerDeprecationTypes.IS_ON_ELEMENT,
521+
context,
522+
p.loc
523+
)
524+
) {
525+
return true
526+
}
527+
})
510528
if (options.isNativeTag && !hasVIs) {
511529
if (!options.isNativeTag(tag)) tagType = ElementTypes.COMPONENT
512530
} else if (

packages/compiler-core/src/transforms/transformElement.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,11 @@ export function resolveComponentType(
240240
if (!isExplicitDynamic && isProp.type === NodeTypes.ATTRIBUTE) {
241241
// <button is="vue:xxx">
242242
// if not <component>, only is value that starts with "vue:" will be
243-
// treated as component by the parse phase and reach here.
244-
tag = isProp.value!.content.slice(4)
243+
// treated as component by the parse phase and reach here, unless it's
244+
// compat mode where all is values are considered components
245+
tag = __COMPAT__
246+
? isProp.value!.content.replace(/^vue:/, '')
247+
: isProp.value!.content.slice(4)
245248
} else {
246249
const exp =
247250
isProp.type === NodeTypes.ATTRIBUTE

0 commit comments

Comments
 (0)