]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(compiler-core): options.isBuiltInComponent
authorEvan You <yyx990803@gmail.com>
Fri, 29 Nov 2019 17:13:49 +0000 (12:13 -0500)
committerEvan You <yyx990803@gmail.com>
Fri, 29 Nov 2019 17:13:49 +0000 (12:13 -0500)
packages/compiler-core/src/parse.ts

index e2ca06380a9dbc9eef933b881e5da452a9f4f7f5..69c4750a47e64455f58792e1db70e2c78553d572 100644 (file)
@@ -31,7 +31,7 @@ import { extend } from '@vue/shared'
 
 // Portal and Fragment are native types, not components
 const isBuiltInComponent = /*#__PURE__*/ makeMap(
-  `suspense,keep-alive,keepalive,base-transition`,
+  `suspense,keep-alive,base-transition`,
   true
 )
 
@@ -40,6 +40,11 @@ export interface ParserOptions {
   isNativeTag?: (tag: string) => boolean // e.g. loading-indicator in weex
   isPreTag?: (tag: string) => boolean // e.g. <pre> where whitespace is intact
   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
   getTextMode?: (tag: string, ns: Namespace) => TextModes
   delimiters?: [string, string] // ['{{', '}}']
@@ -55,8 +60,9 @@ export interface ParserOptions {
 }
 
 // `isNativeTag` is optional, others are required
-type MergedParserOptions = Omit<Required<ParserOptions>, 'isNativeTag'> &
-  Pick<ParserOptions, 'isNativeTag'>
+type OptionalOptions = 'isNativeTag' | 'isBuiltInComponent'
+type MergedParserOptions = Omit<Required<ParserOptions>, OptionalOptions> &
+  Pick<ParserOptions, OptionalOptions>
 
 export const defaultParserOptions: MergedParserOptions = {
   delimiters: [`{{`, `}}`],
@@ -472,10 +478,15 @@ function parseTag(
   }
 
   let tagType = ElementTypes.ELEMENT
-  if (!context.inPre && !context.options.isCustomElement(tag)) {
-    if (context.options.isNativeTag) {
-      if (!context.options.isNativeTag(tag)) tagType = ElementTypes.COMPONENT
-    } else if (isBuiltInComponent(tag) || /^[A-Z]/.test(tag)) {
+  const options = context.options
+  if (!context.inPre && !options.isCustomElement(tag)) {
+    if (options.isNativeTag) {
+      if (!options.isNativeTag(tag)) tagType = ElementTypes.COMPONENT
+    } else if (
+      isBuiltInComponent(tag) ||
+      (options.isBuiltInComponent && options.isBuiltInComponent(tag)) ||
+      /^[A-Z]/.test(tag)
+    ) {
       tagType = ElementTypes.COMPONENT
     }