Skip to content

Commit 66c9058

Browse files
authoredSep 24, 2022
fix(worker): support comment in worker constructor option (#10226)
1 parent 0f7353b commit 66c9058

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed
 

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,9 @@ function getWorkerType(raw: string, clean: string, i: number): WorkerType {
3939
}
4040

4141
// need to find in comment code
42-
let workerOptString = raw.substring(commaIndex + 1, endIndex).trim()
43-
// strip trailing comma for parsing
44-
if (workerOptString.endsWith(',')) {
45-
workerOptString = workerOptString.slice(0, -1)
46-
}
42+
const workerOptString = raw
43+
.substring(commaIndex + 1, endIndex)
44+
.replace(/}[^]*,/g, '}') // strip trailing comma for parsing
4745

4846
const hasViteIgnore = ignoreFlagRE.test(workerOptString)
4947
if (hasViteIgnore) {

‎playground/worker/worker/main-classic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const classicSharedWorker = new SharedWorker(
2222
new URL('../classic-shared-worker.js', import.meta.url),
2323
{
2424
type: 'classic'
25-
},
25+
}, // test comment
2626
)
2727
classicSharedWorker.port.addEventListener('message', (ev) => {
2828
text('.classic-shared-worker', JSON.stringify(ev.data))

0 commit comments

Comments
 (0)
Please sign in to comment.