refactor(compiler-core): improve template type handling
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { ParserOptions } from './options'
|
||||
import { NO, isArray } from '@vue/shared'
|
||||
import { NO, isArray, makeMap } from '@vue/shared'
|
||||
import { ErrorCodes, createCompilerError, defaultOnError } from './errors'
|
||||
import {
|
||||
assert,
|
||||
@@ -397,6 +397,10 @@ const enum TagType {
|
||||
End
|
||||
}
|
||||
|
||||
const isSpecialTemplateDirective = /*#__PURE__*/ makeMap(
|
||||
`if,else,else-if,for,slot`
|
||||
)
|
||||
|
||||
/**
|
||||
* Parse a tag (E.g. `<div id=a>`) with that type (start tag or end tag).
|
||||
*/
|
||||
@@ -467,7 +471,14 @@ function parseTag(
|
||||
|
||||
if (tag === 'slot') {
|
||||
tagType = ElementTypes.SLOT
|
||||
} else if (tag === 'template') {
|
||||
} else if (
|
||||
tag === 'template' &&
|
||||
props.some(p => {
|
||||
return (
|
||||
p.type === NodeTypes.DIRECTIVE && isSpecialTemplateDirective(p.name)
|
||||
)
|
||||
})
|
||||
) {
|
||||
tagType = ElementTypes.TEMPLATE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import {
|
||||
} from '../runtimeHelpers'
|
||||
import {
|
||||
getInnerRange,
|
||||
isVSlot,
|
||||
toValidAssetId,
|
||||
findProp,
|
||||
isCoreComponent
|
||||
@@ -48,12 +47,11 @@ const directiveImportMap = new WeakMap<DirectiveNode, symbol>()
|
||||
// generate a JavaScript AST for this element's codegen
|
||||
export const transformElement: NodeTransform = (node, context) => {
|
||||
if (
|
||||
node.type !== NodeTypes.ELEMENT ||
|
||||
// handled by transformSlotOutlet
|
||||
node.tagType === ElementTypes.SLOT ||
|
||||
// <template v-if/v-for> should have already been replaced
|
||||
// <template v-slot> is handled by buildSlots
|
||||
(node.tagType === ElementTypes.TEMPLATE && node.props.some(isVSlot))
|
||||
!(
|
||||
node.type === NodeTypes.ELEMENT &&
|
||||
(node.tagType === ElementTypes.ELEMENT ||
|
||||
node.tagType === ElementTypes.COMPONENT)
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user