Skip to content

Commit 1030049

Browse files
authored
perf: remove regex in ImportMetaURL plugins (#12502)
1 parent da43936 commit 1030049

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/vite/src/node/plugins/assetImportMetaUrl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
5252
if (!s) s = new MagicString(code)
5353

5454
// potential dynamic template string
55-
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
55+
if (rawUrl[0] === '`' && rawUrl.includes('${')) {
5656
const ast = this.parse(rawUrl)
5757
const templateLiteral = (ast as any).body[0].expression
5858
if (templateLiteral.expressions.length) {

packages/vite/src/node/plugins/workerImportMetaUrl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
126126
const rawUrl = code.slice(urlStart, urlEnd)
127127

128128
// potential dynamic template string
129-
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
129+
if (rawUrl[0] === '`' && rawUrl.includes('${')) {
130130
this.error(
131131
`\`new URL(url, import.meta.url)\` is not supported in dynamic template string.`,
132132
urlIndex,

0 commit comments

Comments
 (0)