]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf: optimize away isBuiltInType
authorEvan You <yyx990803@gmail.com>
Thu, 16 Nov 2023 09:30:00 +0000 (17:30 +0800)
committerEvan You <yyx990803@gmail.com>
Sat, 25 Nov 2023 08:18:29 +0000 (16:18 +0800)
packages/compiler-core/src/index.ts
packages/compiler-core/src/transforms/vIf.ts
packages/compiler-core/src/utils.ts
packages/compiler-dom/src/parserOptions.ts
packages/compiler-ssr/src/transforms/ssrInjectCssVars.ts
packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts

index c88844a5c06216577ae6711525b5eeedb204ee2f..5ce3134fc13d870159146f06bbab7e86940e0d3c 100644 (file)
@@ -71,4 +71,4 @@ export {
   CompilerDeprecationTypes
 } from './compat/compatConfig'
 
-export { baseParse as newParse } from './parser/index'
+// export { baseParse as newParse } from './parser/index'
index 4e1673561c522fe809af5a33ac535bcbdf1d5072..c3b9f91a842e510450c4a13b7dde1a613b8bc9eb 100644 (file)
@@ -30,13 +30,7 @@ import { createCompilerError, ErrorCodes } from '../errors'
 import { processExpression } from './transformExpression'
 import { validateBrowserExpression } from '../validateExpression'
 import { FRAGMENT, CREATE_COMMENT } from '../runtimeHelpers'
-import {
-  injectProp,
-  findDir,
-  findProp,
-  isBuiltInType,
-  getMemoedVNodeCall
-} from '../utils'
+import { injectProp, findDir, findProp, getMemoedVNodeCall } from '../utils'
 import { PatchFlags, PatchFlagNames } from '@vue/shared'
 
 export const transformIf = createStructuralDirectiveTransform(
@@ -165,7 +159,8 @@ export function processIf(
           !(
             context.parent &&
             context.parent.type === NodeTypes.ELEMENT &&
-            isBuiltInType(context.parent.tag, 'transition')
+            (context.parent.tag === 'transition' ||
+              context.parent.tag === 'Transition')
           )
         ) {
           branch.children = [...comments, ...branch.children]
index ee6beadbbfa6f556295eb0c98b59d0ccbfc25193..ddb4b7f8d51247f25a6722ac568fde3bfdb18724 100644 (file)
@@ -37,7 +37,7 @@ import {
   GUARD_REACTIVE_PROPS,
   WITH_MEMO
 } from './runtimeHelpers'
-import { isString, isObject, hyphenate, extend, NOOP } from '@vue/shared'
+import { isString, isObject, extend, NOOP } from '@vue/shared'
 import { PropsExpression } from './transforms/transformElement'
 import { parseExpression } from '@babel/parser'
 import { Expression } from '@babel/types'
@@ -45,9 +45,6 @@ import { Expression } from '@babel/types'
 export const isStaticExp = (p: JSChildNode): p is SimpleExpressionNode =>
   p.type === NodeTypes.SIMPLE_EXPRESSION && p.isStatic
 
-export const isBuiltInType = (tag: string, expected: string): boolean =>
-  tag === expected || tag === hyphenate(expected)
-
 export function isCoreComponent(tag: string): symbol | void {
   switch (tag) {
     case 'Teleport':
index 38e5e8b9d517382e806a3c719c2554b4f7a927bd..67b8f10b02e2050b153fe26a6be6f8238f7b09fd 100644 (file)
@@ -2,8 +2,7 @@ import {
   TextModes,
   ParserOptions,
   ElementNode,
-  NodeTypes,
-  isBuiltInType
+  NodeTypes
 } from '@vue/compiler-core'
 import { isVoidTag, isHTMLTag, isSVGTag } from '@vue/shared'
 import { TRANSITION, TRANSITION_GROUP } from './runtimeHelpers'
@@ -23,9 +22,9 @@ export const parserOptions: ParserOptions = {
   decodeEntities: __BROWSER__ ? decodeHtmlBrowser : decodeHtml,
 
   isBuiltInComponent: (tag: string): symbol | undefined => {
-    if (isBuiltInType(tag, `Transition`)) {
+    if (tag === 'Transition' || tag === 'transition') {
       return TRANSITION
-    } else if (isBuiltInType(tag, `TransitionGroup`)) {
+    } else if (tag === 'TransitionGroup' || tag === 'transition-group') {
       return TRANSITION_GROUP
     }
   },
index d5c0daee7cf3f64343cf6b923d41dd21946f3415..f11e62f6f43b5507940dd3539270851ce413f2ae 100644 (file)
@@ -6,8 +6,7 @@ import {
   createSimpleExpression,
   RootNode,
   TemplateChildNode,
-  findDir,
-  isBuiltInType
+  findDir
 } from '@vue/compiler-dom'
 
 export const ssrInjectCssVars: NodeTransform = (node, context) => {
@@ -43,7 +42,7 @@ function injectCssVars(node: RootNode | TemplateChildNode) {
       node.tagType === ElementTypes.COMPONENT) &&
     !findDir(node, 'for')
   ) {
-    if (isBuiltInType(node.tag, 'Suspense')) {
+    if (node.tag === 'suspense' || node.tag === 'Suspense') {
       for (const child of node.children) {
         if (
           child.type === NodeTypes.ELEMENT &&
index 2b5c350a557565c3820d587a9d635a2a0fc6c20f..a54a7366f012f49964832bdd3607caadb2c164e6 100644 (file)
@@ -7,8 +7,7 @@ import {
   RootNode,
   TemplateChildNode,
   ParentNode,
-  findDir,
-  isBuiltInType
+  findDir
 } from '@vue/compiler-dom'
 
 const filterChild = (node: ParentNode) =>
@@ -28,8 +27,10 @@ export const ssrInjectFallthroughAttrs: NodeTransform = (node, context) => {
   if (
     node.type === NodeTypes.ELEMENT &&
     node.tagType === ElementTypes.COMPONENT &&
-    (isBuiltInType(node.tag, 'Transition') ||
-      isBuiltInType(node.tag, 'KeepAlive'))
+    (node.tag === 'transition' ||
+      node.tag === 'Transition' ||
+      node.tag === 'KeepAlive' ||
+      node.tag === 'keep-alive')
   ) {
     const rootChildren = filterChild(context.root)
     if (rootChildren.length === 1 && rootChildren[0] === node) {