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

View File

@ -78,7 +78,7 @@ const deprecationData: Record<CompilerDeprecationTypes, DeprecationData> = {
[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.`
}
}

View File

@ -41,7 +41,8 @@ import {
TELEPORT,
KEEP_ALIVE,
SUSPENSE,
UNREF
UNREF,
FRAGMENT
} from '../runtimeHelpers'
import {
getInnerRange,
@ -87,9 +88,22 @@ export const transformElement: NodeTransform = (node, context) => {
// 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

View File

@ -63,7 +63,11 @@ export const transformText: NodeTransform = (node, context) => {
(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
}