feat(compiler): support keep-alive in templates

This commit is contained in:
Evan You
2019-11-05 10:26:36 -05:00
parent a5f1387d78
commit 98e9b769e6
5 changed files with 136 additions and 82 deletions

View File

@@ -1,4 +1,4 @@
import { NO } from '@vue/shared'
import { NO, makeMap } from '@vue/shared'
import {
ErrorCodes,
createCompilerError,
@@ -29,6 +29,12 @@ import {
} from './ast'
import { extend } from '@vue/shared'
// Portal and Fragment are native types, not components
const isBuiltInComponent = /*#__PURE__*/ makeMap(
`suspense,keep-alive,keepalive,transition`,
true
)
export interface ParserOptions {
isVoidTag?: (tag: string) => boolean // e.g. img, br, hr
isNativeTag?: (tag: string) => boolean // e.g. loading-indicator in weex
@@ -467,15 +473,15 @@ function parseTag(
if (!context.inPre && !context.options.isCustomElement(tag)) {
if (context.options.isNativeTag) {
if (!context.options.isNativeTag(tag)) tagType = ElementTypes.COMPONENT
} else {
if (/^[A-Z]/.test(tag)) tagType = ElementTypes.COMPONENT
} else if (isBuiltInComponent(tag) || /^[A-Z]/.test(tag)) {
tagType = ElementTypes.COMPONENT
}
if (tag === 'slot') tagType = ElementTypes.SLOT
else if (tag === 'template') tagType = ElementTypes.TEMPLATE
else if (tag === 'portal' || tag === 'Portal') tagType = ElementTypes.PORTAL
else if (tag === 'suspense' || tag === 'Suspense')
tagType = ElementTypes.SUSPENSE
if (tag === 'slot') {
tagType = ElementTypes.SLOT
} else if (tag === 'template') {
tagType = ElementTypes.TEMPLATE
}
}
return {