Skip to content

Commit

Permalink
perf: remove regex in ImportMetaURL plugins (#12502)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Mar 22, 2023
1 parent da43936 commit 1030049
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/assetImportMetaUrl.ts
Expand Up @@ -52,7 +52,7 @@ export function assetImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
if (!s) s = new MagicString(code)

// potential dynamic template string
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
if (rawUrl[0] === '`' && rawUrl.includes('${')) {
const ast = this.parse(rawUrl)
const templateLiteral = (ast as any).body[0].expression
if (templateLiteral.expressions.length) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/workerImportMetaUrl.ts
Expand Up @@ -126,7 +126,7 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin {
const rawUrl = code.slice(urlStart, urlEnd)

// potential dynamic template string
if (rawUrl[0] === '`' && /\$\{/.test(rawUrl)) {
if (rawUrl[0] === '`' && rawUrl.includes('${')) {
this.error(
`\`new URL(url, import.meta.url)\` is not supported in dynamic template string.`,
urlIndex,
Expand Down

0 comments on commit 1030049

Please sign in to comment.