@@ -71,6 +71,16 @@ describe('workerImportMetaUrlPlugin', async () => {
71
71
)
72
72
} )
73
73
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
+
74
84
test ( 'with dynamic name field and static type in worker options' , async ( ) => {
75
85
expect (
76
86
await transform (
@@ -81,6 +91,16 @@ describe('workerImportMetaUrlPlugin', async () => {
81
91
)
82
92
} )
83
93
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
+
84
104
test ( 'with parenthesis inside of worker options' , async ( ) => {
85
105
expect (
86
106
await transform (
@@ -113,6 +133,26 @@ worker.addEventListener('message', (ev) => text('.simple-worker-url', JSON.strin
113
133
"` )
114
134
} )
115
135
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
+
116
156
test ( 'throws an error when non-static worker options are provided' , async ( ) => {
117
157
await expect (
118
158
transform (
0 commit comments