Skip to content

Commit 92cc578

Browse files
committed
perf: improve regexp performance with non-capturing groups
1 parent eca0e1c commit 92cc578

File tree

14 files changed

+17
-17
lines changed

14 files changed

+17
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { findDir, findProp, getMemoedVNodeCall, injectProp } from '../utils'
3636
import { PatchFlags } from '@vue/shared'
3737

3838
export const transformIf: NodeTransform = createStructuralDirectiveTransform(
39-
/^(if|else|else-if)$/,
39+
/^(?:if|else|else-if)$/,
4040
(node, dir, context) => {
4141
return processIf(node, dir, context, (ifNode, branch, isRoot) => {
4242
// #1587: We need to dynamically increment the key based on the current

packages/compiler-core/src/transforms/vSlot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export function buildSlots(
215215
),
216216
)
217217
} else if (
218-
(vElse = findDir(slotElement, /^else(-if)?$/, true /* allowEmpty */))
218+
(vElse = findDir(slotElement, /^else(?:-if)?$/, true /* allowEmpty */))
219219
) {
220220
// find adjacent v-if
221221
let j = i
@@ -226,7 +226,7 @@ export function buildSlots(
226226
break
227227
}
228228
}
229-
if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
229+
if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
230230
__TEST__ && assert(dynamicSlots.length > 0)
231231
// attach this slot to previous conditional
232232
let conditional = dynamicSlots[

packages/compiler-core/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const isMemberExpression: (
189189
) => boolean = __BROWSER__ ? isMemberExpressionBrowser : isMemberExpressionNode
190190

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

194194
export const isFnExpressionBrowser: (exp: ExpressionNode) => boolean = exp =>
195195
fnExpRE.test(getExpSource(exp))

packages/compiler-dom/src/transforms/stringifyStatic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ const getCachedNode = (
184184
}
185185
}
186186

187-
const dataAriaRE = /^(data|aria)-/
187+
const dataAriaRE = /^(?:data|aria)-/
188188
const isStringifiableAttr = (name: string, ns: Namespaces) => {
189189
return (
190190
(ns === Namespaces.HTML

packages/compiler-sfc/src/style/pluginScoped.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
import selectorParser from 'postcss-selector-parser'
99
import { warn } from '../warn'
1010

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

1414
const scopedPlugin: PluginCreator<string> = (id = '') => {
1515
const keyframes = Object.create(null)

packages/compiler-sfc/src/template/templateUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function isRelativeUrl(url: string): boolean {
66
return firstChar === '.' || firstChar === '~' || firstChar === '@'
77
}
88

9-
const externalRE = /^(https?:)?\/\//
9+
const externalRE = /^(?:https?:)?\/\//
1010
export function isExternalUrl(url: string): boolean {
1111
return externalRE.test(url)
1212
}

packages/compiler-ssr/src/transforms/ssrVIf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717

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

packages/runtime-core/src/compat/global.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ function installCompatMount(
536536
if (__DEV__) {
537537
for (let i = 0; i < container.attributes.length; i++) {
538538
const attr = container.attributes[i]
539-
if (attr.name !== 'v-cloak' && /^(v-|:|@)/.test(attr.name)) {
539+
if (attr.name !== 'v-cloak' && /^(?:v-|:|@)/.test(attr.name)) {
540540
warnDeprecation(DeprecationTypes.GLOBAL_MOUNT_CONTAINER, null)
541541
break
542542
}

packages/runtime-core/src/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ export function getComponentPublicInstance(
12031203
}
12041204
}
12051205

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

packages/runtime-dom/src/components/Transition.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ export function getTransitionInfo(
447447
}
448448
const hasTransform =
449449
type === TRANSITION &&
450-
/\b(transform|all)(,|$)/.test(
450+
/\b(?:transform|all)(?:,|$)/.test(
451451
getStyleProperties(`${TRANSITION}Property`).toString(),
452452
)
453453
return {

packages/runtime-dom/src/components/TransitionGroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const TransitionGroupImpl: ComponentOptions = /*@__PURE__*/ decorate({
103103
if (e && e.target !== el) {
104104
return
105105
}
106-
if (!e || /transform$/.test(e.propertyName)) {
106+
if (!e || e.propertyName.endsWith('transform')) {
107107
el.removeEventListener('transitionend', cb)
108108
;(el as any)[moveCbKey] = null
109109
removeTransitionClass(el, moveClass)

packages/runtime-dom/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export const createApp = ((...args) => {
119119
if (__COMPAT__ && __DEV__ && container.nodeType === 1) {
120120
for (let i = 0; i < (container as Element).attributes.length; i++) {
121121
const attr = (container as Element).attributes[i]
122-
if (attr.name !== 'v-cloak' && /^(v-|:|@)/.test(attr.name)) {
122+
if (attr.name !== 'v-cloak' && /^(?:v-|:|@)/.test(attr.name)) {
123123
compatUtils.warnDeprecation(
124124
DeprecationTypes.GLOBAL_MOUNT_CONTAINER,
125125
null,

packages/runtime-dom/src/modules/style.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { CSS_VAR_TEXT } from '../helpers/useCssVars'
99

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

12-
const displayRE = /(^|;)\s*display\s*:/
12+
const displayRE = /(?:^|;)\s*display\s*:/
1313

1414
export function patchStyle(el: Element, prev: Style, next: Style): void {
1515
const style = (el as HTMLElement).style

packages/shared/src/general.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ const cacheStringFunction = <T extends (str: string) => string>(fn: T): T => {
101101
}) as T
102102
}
103103

104-
const camelizeRE = /-(\w)/g
104+
const camelizeRE = /-\w/g
105105
/**
106106
* @private
107107
*/
108108
export const camelize: (str: string) => string = cacheStringFunction(
109109
(str: string): string => {
110-
return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
110+
return str.replace(camelizeRE, c => c.slice(1).toUpperCase())
111111
},
112112
)
113113

0 commit comments

Comments
 (0)