From 48042266f02df12b7a97a2abdd310553aff80f64 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 09:07:44 +0000 Subject: [PATCH 1/3] Initial plan From 2966f54e015977c8c83f487cc8aa47fcc1ce19ae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 09:15:34 +0000 Subject: [PATCH 2/3] Fix multi-line new URL parsing with trailing comma Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --- .../plugins/workerImportMetaUrl.spec.ts | 32 +++++++++++++++++++ .../src/node/plugins/workerImportMetaUrl.ts | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/__tests__/plugins/workerImportMetaUrl.spec.ts b/packages/vite/src/node/__tests__/plugins/workerImportMetaUrl.spec.ts index a6d60a84b345f3..3fbf2f9886c17c 100644 --- a/packages/vite/src/node/__tests__/plugins/workerImportMetaUrl.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/workerImportMetaUrl.spec.ts @@ -221,4 +221,36 @@ new Worker( `"repro(new Worker(new URL(/* @vite-ignore */ "/worker?worker_file&type=classic", '' + import.meta.url)), { type: "module" })"`, ) }) + + test('with multi-line new URL and trailing comma', async () => { + expect( + await transform(`new Worker( + new URL( + "./worker.js", + import.meta.url, + ) +)`), + ).toMatchInlineSnapshot(` + "new Worker( + new URL(/* @vite-ignore */ "/worker.js?worker_file&type=classic", '' + import.meta.url) + )" + `) + }) + + test('with multi-line new URL, trailing comma, and worker options', async () => { + expect( + await transform(`const worker = new Worker( + new URL( + "../some-loooooooooooooooooong-file-path-of-module-name.js", + import.meta.url, + ), + { type: "module" }, +)`), + ).toMatchInlineSnapshot(` + "const worker = new Worker( + new URL(/* @vite-ignore */ "/@fs/home/runner/work/vite/some-loooooooooooooooooong-file-path-of-module-name.js?worker_file&type=module", '' + import.meta.url), + { type: "module" }, + )" + `) + }) }) diff --git a/packages/vite/src/node/plugins/workerImportMetaUrl.ts b/packages/vite/src/node/plugins/workerImportMetaUrl.ts index a8b25a262ff0f4..991783b64e075b 100644 --- a/packages/vite/src/node/plugins/workerImportMetaUrl.ts +++ b/packages/vite/src/node/plugins/workerImportMetaUrl.ts @@ -209,7 +209,7 @@ export function workerImportMetaUrlPlugin(config: ResolvedConfig): Plugin { let s: MagicString | undefined const cleanString = stripLiteral(code) const workerImportMetaUrlRE = - /\bnew\s+(?:Worker|SharedWorker)\s*\(\s*(new\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/dg + /\bnew\s+(?:Worker|SharedWorker)\s*\(\s*(new\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\))/dg let match: RegExpExecArray | null while ((match = workerImportMetaUrlRE.exec(cleanString))) { From 80808a95b915a14df04fb70f630538ba10c61d77 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Dec 2025 10:35:36 +0000 Subject: [PATCH 3/3] Simplify test case to use ./worker.js for consistency Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --- .../src/node/__tests__/plugins/workerImportMetaUrl.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/__tests__/plugins/workerImportMetaUrl.spec.ts b/packages/vite/src/node/__tests__/plugins/workerImportMetaUrl.spec.ts index 3fbf2f9886c17c..348e3e39be0147 100644 --- a/packages/vite/src/node/__tests__/plugins/workerImportMetaUrl.spec.ts +++ b/packages/vite/src/node/__tests__/plugins/workerImportMetaUrl.spec.ts @@ -241,14 +241,14 @@ new Worker( expect( await transform(`const worker = new Worker( new URL( - "../some-loooooooooooooooooong-file-path-of-module-name.js", + "./worker.js", import.meta.url, ), { type: "module" }, )`), ).toMatchInlineSnapshot(` "const worker = new Worker( - new URL(/* @vite-ignore */ "/@fs/home/runner/work/vite/some-loooooooooooooooooong-file-path-of-module-name.js?worker_file&type=module", '' + import.meta.url), + new URL(/* @vite-ignore */ "/worker.js?worker_file&type=module", '' + import.meta.url), { type: "module" }, )" `)