Skip to content

perf: improve regexp performance with non-capturing groups #13567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/compiler-core/src/transforms/vIf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { findDir, findProp, getMemoedVNodeCall, injectProp } from '../utils'
import { PatchFlags } from '@vue/shared'

export const transformIf: NodeTransform = createStructuralDirectiveTransform(
/^(if|else|else-if)$/,
/^(?:if|else|else-if)$/,
(node, dir, context) => {
return processIf(node, dir, context, (ifNode, branch, isRoot) => {
// #1587: We need to dynamically increment the key based on the current
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-core/src/transforms/vSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export function buildSlots(
),
)
} else if (
(vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))
(vElse = findDir(slotElement, /^else(?:-if)?$/, true /* allowEmpty */))
) {
// find adjacent v-if
let j = i
Expand All @@ -226,7 +226,7 @@ export function buildSlots(
break
}
}
if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
__TEST__ && assert(dynamicSlots.length > 0)
// attach this slot to previous conditional
let conditional = dynamicSlots[
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const isMemberExpression: (
) => boolean = __BROWSER__ ? isMemberExpressionBrowser : isMemberExpressionNode

const fnExpRE =
/^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/
/^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/

export const isFnExpressionBrowser: (exp: ExpressionNode) => boolean = exp =>
fnExpRE.test(getExpSource(exp))
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-dom/src/transforms/stringifyStatic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ const getCachedNode = (
}
}

const dataAriaRE = /^(data|aria)-/
const dataAriaRE = /^(?:data|aria)-/
const isStringifiableAttr = (name: string, ns: Namespaces) => {
return (
(ns === Namespaces.HTML
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-sfc/src/style/pluginScoped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
import selectorParser from 'postcss-selector-parser'
import { warn } from '../warn'

const animationNameRE = /^(-\w+-)?animation-name$/
const animationRE = /^(-\w+-)?animation$/
const animationNameRE = /^(?:-\w+-)?animation-name$/
const animationRE = /^(?:-\w+-)?animation$/

const scopedPlugin: PluginCreator<string> = (id = '') => {
const keyframes = Object.create(null)
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/template/templateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function isRelativeUrl(url: string): boolean {
return firstChar === '.' || firstChar === '~' || firstChar === '@'
}

const externalRE = /^(https?:)?\/\//
const externalRE = /^(?:https?:)?\/\//
export function isExternalUrl(url: string): boolean {
return externalRE.test(url)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-ssr/src/transforms/ssrVIf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

// Plugin for the first transform pass, which simply constructs the AST node
export const ssrTransformIf: NodeTransform = createStructuralDirectiveTransform(
/^(if|else|else-if)$/,
/^(?:if|else|else-if)$/,
processIf,
)

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/compat/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ function installCompatMount(
if (__DEV__) {
for (let i = 0; i < container.attributes.length; i++) {
const attr = container.attributes[i]
if (attr.name !== 'v-cloak' && /^(v-|:|@)/.test(attr.name)) {
if (attr.name !== 'v-cloak' && /^(?:v-|:|@)/.test(attr.name)) {
warnDeprecation(DeprecationTypes.GLOBAL_MOUNT_CONTAINER, null)
break
}
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ export function getComponentPublicInstance(
}
}

const classifyRE = /(?:^|[-_])(\w)/g
const classifyRE = /(?:^|[-_])\w/g
const classify = (str: string): string =>
str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/components/Transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export function getTransitionInfo(
}
const hasTransform =
type === TRANSITION &&
/\b(transform|all)(,|$)/.test(
/\b(?:transform|all)(?:,|$)/.test(
getStyleProperties(`${TRANSITION}Property`).toString(),
)
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/components/TransitionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const TransitionGroupImpl: ComponentOptions = /*@__PURE__*/ decorate({
if (e && e.target !== el) {
return
}
if (!e || /transform$/.test(e.propertyName)) {
if (!e || e.propertyName.endsWith('transform')) {
el.removeEventListener('transitionend', cb)
;(el as any)[moveCbKey] = null
removeTransitionClass(el, moveClass)
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const createApp = ((...args) => {
if (__COMPAT__ && __DEV__ && container.nodeType === 1) {
for (let i = 0; i < (container as Element).attributes.length; i++) {
const attr = (container as Element).attributes[i]
if (attr.name !== 'v-cloak' && /^(v-|:|@)/.test(attr.name)) {
if (attr.name !== 'v-cloak' && /^(?:v-|:|@)/.test(attr.name)) {
compatUtils.warnDeprecation(
DeprecationTypes.GLOBAL_MOUNT_CONTAINER,
null,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-dom/src/modules/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { CSS_VAR_TEXT } from '../helpers/useCssVars'

type Style = string | Record<string, string | string[]> | null

const displayRE = /(^|;)\s*display\s*:/
const displayRE = /(?:^|;)\s*display\s*:/

export function patchStyle(el: Element, prev: Style, next: Style): void {
const style = (el as HTMLElement).style
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/src/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ const cacheStringFunction = <T extends (str: string) => string>(fn: T): T => {
}) as T
}

const camelizeRE = /-(\w)/g
const camelizeRE = /-\w/g
/**
* @private
*/
export const camelize: (str: string) => string = cacheStringFunction(
(str: string): string => {
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
return str.replace(camelizeRE, c => c.slice(1).toUpperCase())
},
)

Expand Down