@@ -71,6 +71,16 @@ describe('workerImportMetaUrlPlugin', async () => {
7171 )
7272 } )
7373
74+ test ( 'with interpolated dynamic name field in worker options' , async ( ) => {
75+ expect (
76+ await transform (
77+ 'const id = 1; new Worker(new URL("./worker.js", import.meta.url), { name: `worker-${id}` })' ,
78+ ) ,
79+ ) . toMatchInlineSnapshot (
80+ `"const id = 1; new Worker(new URL(/* @vite-ignore */ "/worker.js?worker_file&type=classic", import.meta.url), { name: \`worker-\${id}\` })"` ,
81+ )
82+ } )
83+
7484 test ( 'with dynamic name field and static type in worker options' , async ( ) => {
7585 expect (
7686 await transform (
@@ -81,6 +91,16 @@ describe('workerImportMetaUrlPlugin', async () => {
8191 )
8292 } )
8393
94+ test ( 'with interpolated dynamic name field and static type in worker options' , async ( ) => {
95+ expect (
96+ await transform (
97+ 'const id = 1; new Worker(new URL("./worker.js", import.meta.url), { name: `worker-${id}`, type: "module" })' ,
98+ ) ,
99+ ) . toMatchInlineSnapshot (
100+ `"const id = 1; new Worker(new URL(/* @vite-ignore */ "/worker.js?worker_file&type=module", import.meta.url), { name: \`worker-\${id}\`, type: "module" })"` ,
101+ )
102+ } )
103+
84104 test ( 'with parenthesis inside of worker options' , async ( ) => {
85105 expect (
86106 await transform (
@@ -113,6 +133,26 @@ worker.addEventListener('message', (ev) => text('.simple-worker-url', JSON.strin
113133"` )
114134 } )
115135
136+ test ( 'trailing comma' , async ( ) => {
137+ expect (
138+ await transform ( `
139+ new Worker(
140+ new URL('./worker.js', import.meta.url),
141+ {
142+ type: 'module'
143+ }, // },
144+ )
145+ ` ) ,
146+ ) . toMatchInlineSnapshot ( `"
147+ new Worker(
148+ new URL(/* @vite-ignore */ "/worker.js?worker_file&type=module", import.meta.url),
149+ {
150+ type: 'module'
151+ }, // },
152+ )
153+ "` )
154+ } )
155+
116156 test ( 'throws an error when non-static worker options are provided' , async ( ) => {
117157 await expect (
118158 transform (
0 commit comments