Skip to content

Commit d9a88fe

Browse files
committed
perf(compiler): remove regx for removeStaticBinding
1 parent cdffaf6 commit d9a88fe

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
isBooleanAttr,
4040
isBuiltInDirective,
4141
isSSRSafeAttrName,
42+
isString,
4243
propsToAttrMap,
4344
} from '@vue/shared'
4445
import { SSRErrorCodes, createSSRCompilerError } from '../errors'
@@ -423,9 +424,16 @@ function removeStaticBinding(
423424
tag: TemplateLiteral['elements'],
424425
binding: string,
425426
) {
426-
const regExp = new RegExp(`^ ${binding}=".+"$`)
427-
428-
const i = tag.findIndex(e => typeof e === 'string' && regExp.test(e))
427+
const bindingStart = ` ${binding}="`
428+
// tag must end with at least one character and "
429+
const minLen = bindingStart.length + 2
430+
const i = tag.findIndex(
431+
e =>
432+
isString(e) &&
433+
e.length >= minLen &&
434+
e.startsWith(bindingStart) &&
435+
e[e.length - 1] === '"',
436+
)
429437

430438
if (i > -1) {
431439
tag.splice(i, 1)

0 commit comments

Comments
 (0)