wip: plain template tag compat

This commit is contained in:
Evan You 2021-04-17 22:16:48 -04:00
parent 048ac299f3
commit 505269405e
3 changed files with 22 additions and 4 deletions
packages/compiler-core/src

@ -78,7 +78,7 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
[CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE]: { [CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE]: {
message: 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.` `element instead of its inner content in Vue 3.`
} }
} }

@ -41,7 +41,8 @@ import {
TELEPORT, TELEPORT,
KEEP_ALIVE, KEEP_ALIVE,
SUSPENSE, SUSPENSE,
UNREF UNREF,
FRAGMENT
} from '../runtimeHelpers' } from '../runtimeHelpers'
import { import {
getInnerRange, getInnerRange,
@ -87,9 +88,22 @@ export const transformElement: NodeTransform = (node, context) => {
// The goal of the transform is to create a codegenNode implementing the // The goal of the transform is to create a codegenNode implementing the
// VNodeCall interface. // VNodeCall interface.
const vnodeTag = isComponent let vnodeTag = isComponent
? resolveComponentType(node as ComponentNode, context) ? resolveComponentType(node as ComponentNode, context)
: `"${tag}"` : `"${tag}"`
if (
__COMPAT__ &&
tag === 'template' &&
checkCompatEnabled(
CompilerDeprecationTypes.COMPILER_NATIVE_TEMPLATE,
context,
node.loc
)
) {
vnodeTag = context.helper(FRAGMENT)
}
const isDynamicComponent = const isDynamicComponent =
isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT

@ -63,7 +63,11 @@ export const transformText: NodeTransform = (node, context) => {
(children.length === 1 && (children.length === 1 &&
(node.type === NodeTypes.ROOT || (node.type === NodeTypes.ROOT ||
(node.type === NodeTypes.ELEMENT && (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 return
} }