Skip to content

Commit 5052694

Browse files
committed
wip: plain template tag compat
1 parent 048ac29 commit 5052694

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
7878

7979
[CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE]: {
8080
message:
81-
`<template> with no special directives will render as a native template` +
81+
`<template> with no special directives will render as a native template ` +
8282
`element instead of its inner content in Vue 3.`
8383
}
8484
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import {
4141
TELEPORT,
4242
KEEP_ALIVE,
4343
SUSPENSE,
44-
UNREF
44+
UNREF,
45+
FRAGMENT
4546
} from '../runtimeHelpers'
4647
import {
4748
getInnerRange,
@@ -87,9 +88,22 @@ export const transformElement: NodeTransform = (node, context) => {
8788

8889
// The goal of the transform is to create a codegenNode implementing the
8990
// VNodeCall interface.
90-
const vnodeTag = isComponent
91+
let vnodeTag = isComponent
9192
? resolveComponentType(node as ComponentNode, context)
9293
: `"${tag}"`
94+
95+
if (
96+
__COMPAT__ &&
97+
tag === 'template' &&
98+
checkCompatEnabled(
99+
CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE,
100+
context,
101+
node.loc
102+
)
103+
) {
104+
vnodeTag = context.helper(FRAGMENT)
105+
}
106+
93107
const isDynamicComponent =
94108
isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT
95109

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ export const transformText: NodeTransform = (node, context) => {
6363
(children.length === 1 &&
6464
(node.type === NodeTypes.ROOT ||
6565
(node.type === NodeTypes.ELEMENT &&
66-
node.tagType === ElementTypes.ELEMENT)))
66+
node.tagType === ElementTypes.ELEMENT &&
67+
// in compat mode, <template> tags with no special directives
68+
// will be rendered as a fragment so its children must be
69+
// converted into vnodes.
70+
!(__COMPAT__ && node.tag === 'template'))))
6771
) {
6872
return
6973
}

0 commit comments

Comments
 (0)