From: Evan You Date: Fri, 29 Nov 2019 17:13:49 +0000 (-0500) Subject: feat(compiler-core): options.isBuiltInComponent X-Git-Tag: v3.0.0-alpha.0~127 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4e8d57bdfb270341c23fcb9f6bc9043509649b32;p=thirdparty%2Fvuejs%2Fcore.git feat(compiler-core): options.isBuiltInComponent --- diff --git a/packages/compiler-core/src/parse.ts b/packages/compiler-core/src/parse.ts index e2ca06380a..69c4750a47 100644 --- a/packages/compiler-core/src/parse.ts +++ b/packages/compiler-core/src/parse.ts @@ -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.
 where whitespace is intact
   isCustomElement?: (tag: string) => boolean
+  // for importing platform-specific components from the runtime.
+  // e.g.  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, 'isNativeTag'> &
-  Pick
+type OptionalOptions = 'isNativeTag' | 'isBuiltInComponent'
+type MergedParserOptions = Omit, OptionalOptions> &
+  Pick
 
 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
     }