perf(compiler-vapor): use array instead of regex

This commit is contained in:
三咲智子 Kevin Deng 2024-01-28 03:35:04 +08:00
parent d3baff92b1
commit 86ed0eddae
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
2 changed files with 4 additions and 5 deletions

View File

@ -388,12 +388,11 @@ function processDynamicChildren(ctx: TransformContext<RootNode | ElementNode>) {
}
export function createStructuralDirectiveTransform(
name: string | RegExp,
name: string | string[],
fn: StructuralDirectiveTransform,
): NodeTransform {
const matches = isString(name)
? (n: string) => n === name
: (n: string) => name.test(n)
const matches = (n: string) =>
isString(name) ? n === name : name.includes(n)
return (node, context) => {
if (node.type === NodeTypes.ELEMENT) {

View File

@ -20,7 +20,7 @@ import {
import { extend } from '@vue/shared'
export const transformVIf = createStructuralDirectiveTransform(
/^(if|else|else-if)$/,
['if', 'else', 'else-if'],
processIf,
)