feat(compiler-core): options.isBuiltInComponent
This commit is contained in:
parent
52134a88d0
commit
4e8d57bdfb
@ -31,7 +31,7 @@ import { extend } from '@vue/shared'
|
|||||||
|
|
||||||
// Portal and Fragment are native types, not components
|
// Portal and Fragment are native types, not components
|
||||||
const isBuiltInComponent = /*#__PURE__*/ makeMap(
|
const isBuiltInComponent = /*#__PURE__*/ makeMap(
|
||||||
`suspense,keep-alive,keepalive,base-transition`,
|
`suspense,keep-alive,base-transition`,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -40,6 +40,11 @@ export interface ParserOptions {
|
|||||||
isNativeTag?: (tag: string) => boolean // e.g. loading-indicator in weex
|
isNativeTag?: (tag: string) => boolean // e.g. loading-indicator in weex
|
||||||
isPreTag?: (tag: string) => boolean // e.g. <pre> where whitespace is intact
|
isPreTag?: (tag: string) => boolean // e.g. <pre> where whitespace is intact
|
||||||
isCustomElement?: (tag: string) => boolean
|
isCustomElement?: (tag: string) => boolean
|
||||||
|
// for importing platform-specific components from the runtime.
|
||||||
|
// e.g. <transition> for runtime-dom
|
||||||
|
// However this is only needed if isNativeTag is not specified, since when
|
||||||
|
// isNativeTag is specified anything that is not native is a component.
|
||||||
|
isBuiltInComponent?: (tag: string) => boolean
|
||||||
getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace
|
getNamespace?: (tag: string, parent: ElementNode | undefined) => Namespace
|
||||||
getTextMode?: (tag: string, ns: Namespace) => TextModes
|
getTextMode?: (tag: string, ns: Namespace) => TextModes
|
||||||
delimiters?: [string, string] // ['{{', '}}']
|
delimiters?: [string, string] // ['{{', '}}']
|
||||||
@ -55,8 +60,9 @@ export interface ParserOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// `isNativeTag` is optional, others are required
|
// `isNativeTag` is optional, others are required
|
||||||
type MergedParserOptions = Omit<Required<ParserOptions>, 'isNativeTag'> &
|
type OptionalOptions = 'isNativeTag' | 'isBuiltInComponent'
|
||||||
Pick<ParserOptions, 'isNativeTag'>
|
type MergedParserOptions = Omit<Required<ParserOptions>, OptionalOptions> &
|
||||||
|
Pick<ParserOptions, OptionalOptions>
|
||||||
|
|
||||||
export const defaultParserOptions: MergedParserOptions = {
|
export const defaultParserOptions: MergedParserOptions = {
|
||||||
delimiters: [`{{`, `}}`],
|
delimiters: [`{{`, `}}`],
|
||||||
@ -472,10 +478,15 @@ function parseTag(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let tagType = ElementTypes.ELEMENT
|
let tagType = ElementTypes.ELEMENT
|
||||||
if (!context.inPre && !context.options.isCustomElement(tag)) {
|
const options = context.options
|
||||||
if (context.options.isNativeTag) {
|
if (!context.inPre && !options.isCustomElement(tag)) {
|
||||||
if (!context.options.isNativeTag(tag)) tagType = ElementTypes.COMPONENT
|
if (options.isNativeTag) {
|
||||||
} else if (isBuiltInComponent(tag) || /^[A-Z]/.test(tag)) {
|
if (!options.isNativeTag(tag)) tagType = ElementTypes.COMPONENT
|
||||||
|
} else if (
|
||||||
|
isBuiltInComponent(tag) ||
|
||||||
|
(options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
|
||||||
|
/^[A-Z]/.test(tag)
|
||||||
|
) {
|
||||||
tagType = ElementTypes.COMPONENT
|
tagType = ElementTypes.COMPONENT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user