[CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE]: {
message:
- `<template> with no special directives will render as a native template` +
+ `<template> with no special directives will render as a native template ` +
`element instead of its inner content in Vue 3.`
}
}
TELEPORT,
KEEP_ALIVE,
SUSPENSE,
- UNREF
+ UNREF,
+ FRAGMENT
} from '../runtimeHelpers'
import {
getInnerRange,
// The goal of the transform is to create a codegenNode implementing the
// VNodeCall interface.
- const vnodeTag = isComponent
+ let vnodeTag = isComponent
? resolveComponentType(node as ComponentNode, context)
: `"${tag}"`
+
+ if (
+ __COMPAT__ &&
+ tag === 'template' &&
+ checkCompatEnabled(
+ CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE,
+ context,
+ node.loc
+ )
+ ) {
+ vnodeTag = context.helper(FRAGMENT)
+ }
+
const isDynamicComponent =
isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT
(children.length === 1 &&
(node.type === NodeTypes.ROOT ||
(node.type === NodeTypes.ELEMENT &&
- node.tagType === ElementTypes.ELEMENT)))
+ node.tagType === ElementTypes.ELEMENT &&
+ // in compat mode, <template> tags with no special directives
+ // will be rendered as a fragment so its children must be
+ // converted into vnodes.
+ !(__COMPAT__ && node.tag === 'template'))))
) {
return
}