Skip to content

Commit 66c0ed0

Browse files
committedNov 25, 2023
perf: optimize away isBuiltInType
1 parent bc170c4 commit 66c0ed0

File tree

6 files changed

+15
-24
lines changed

6 files changed

+15
-24
lines changed
 

‎packages/compiler-core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ export {
7171
CompilerDeprecationTypes
7272
} from './compat/compatConfig'
7373

74-
export { baseParse as newParse } from './parser/index'
74+
// export { baseParse as newParse } from './parser/index'

‎packages/compiler-core/src/transforms/vIf.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,7 @@ import { createCompilerError, ErrorCodes } from '../errors'
3030
import { processExpression } from './transformExpression'
3131
import { validateBrowserExpression } from '../validateExpression'
3232
import { FRAGMENT, CREATE_COMMENT } from '../runtimeHelpers'
33-
import {
34-
injectProp,
35-
findDir,
36-
findProp,
37-
isBuiltInType,
38-
getMemoedVNodeCall
39-
} from '../utils'
33+
import { injectProp, findDir, findProp, getMemoedVNodeCall } from '../utils'
4034
import { PatchFlags, PatchFlagNames } from '@vue/shared'
4135

4236
export const transformIf = createStructuralDirectiveTransform(
@@ -165,7 +159,8 @@ export function processIf(
165159
!(
166160
context.parent &&
167161
context.parent.type === NodeTypes.ELEMENT &&
168-
isBuiltInType(context.parent.tag, 'transition')
162+
(context.parent.tag === 'transition' ||
163+
context.parent.tag === 'Transition')
169164
)
170165
) {
171166
branch.children = [...comments, ...branch.children]

‎packages/compiler-core/src/utils.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,14 @@ import {
3737
GUARD_REACTIVE_PROPS,
3838
WITH_MEMO
3939
} from './runtimeHelpers'
40-
import { isString, isObject, hyphenate, extend, NOOP } from '@vue/shared'
40+
import { isString, isObject, extend, NOOP } from '@vue/shared'
4141
import { PropsExpression } from './transforms/transformElement'
4242
import { parseExpression } from '@babel/parser'
4343
import { Expression } from '@babel/types'
4444

4545
export const isStaticExp = (p: JSChildNode): p is SimpleExpressionNode =>
4646
p.type === NodeTypes.SIMPLE_EXPRESSION && p.isStatic
4747

48-
export const isBuiltInType = (tag: string, expected: string): boolean =>
49-
tag === expected || tag === hyphenate(expected)
50-
5148
export function isCoreComponent(tag: string): symbol | void {
5249
switch (tag) {
5350
case 'Teleport':

‎packages/compiler-dom/src/parserOptions.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import {
22
TextModes,
33
ParserOptions,
44
ElementNode,
5-
NodeTypes,
6-
isBuiltInType
5+
NodeTypes
76
} from '@vue/compiler-core'
87
import { isVoidTag, isHTMLTag, isSVGTag } from '@vue/shared'
98
import { TRANSITION, TRANSITION_GROUP } from './runtimeHelpers'
@@ -23,9 +22,9 @@ export const parserOptions: ParserOptions = {
2322
decodeEntities: __BROWSER__ ? decodeHtmlBrowser : decodeHtml,
2423

2524
isBuiltInComponent: (tag: string): symbol | undefined => {
26-
if (isBuiltInType(tag, `Transition`)) {
25+
if (tag === 'Transition' || tag === 'transition') {
2726
return TRANSITION
28-
} else if (isBuiltInType(tag, `TransitionGroup`)) {
27+
} else if (tag === 'TransitionGroup' || tag === 'transition-group') {
2928
return TRANSITION_GROUP
3029
}
3130
},

‎packages/compiler-ssr/src/transforms/ssrInjectCssVars.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import {
66
createSimpleExpression,
77
RootNode,
88
TemplateChildNode,
9-
findDir,
10-
isBuiltInType
9+
findDir
1110
} from '@vue/compiler-dom'
1211

1312
export const ssrInjectCssVars: NodeTransform = (node, context) => {
@@ -43,7 +42,7 @@ function injectCssVars(node: RootNode | TemplateChildNode) {
4342
node.tagType === ElementTypes.COMPONENT) &&
4443
!findDir(node, 'for')
4544
) {
46-
if (isBuiltInType(node.tag, 'Suspense')) {
45+
if (node.tag === 'suspense' || node.tag === 'Suspense') {
4746
for (const child of node.children) {
4847
if (
4948
child.type === NodeTypes.ELEMENT &&

‎packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import {
77
RootNode,
88
TemplateChildNode,
99
ParentNode,
10-
findDir,
11-
isBuiltInType
10+
findDir
1211
} from '@vue/compiler-dom'
1312

1413
const filterChild = (node: ParentNode) =>
@@ -28,8 +27,10 @@ export const ssrInjectFallthroughAttrs: NodeTransform = (node, context) => {
2827
if (
2928
node.type === NodeTypes.ELEMENT &&
3029
node.tagType === ElementTypes.COMPONENT &&
31-
(isBuiltInType(node.tag, 'Transition') ||
32-
isBuiltInType(node.tag, 'KeepAlive'))
30+
(node.tag === 'transition' ||
31+
node.tag === 'Transition' ||
32+
node.tag === 'KeepAlive' ||
33+
node.tag === 'keep-alive')
3334
) {
3435
const rootChildren = filterChild(context.root)
3536
if (rootChildren.length === 1 && rootChildren[0] === node) {

0 commit comments

Comments
 (0)
Please sign in to comment.