Skip to content

Commit

Permalink
fix(worker): support comment in worker constructor option (#10226)
Browse files Browse the repository at this point in the history
  • Loading branch information
ydcjeff authored Sep 24, 2022
1 parent 0f7353b commit 66c9058
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions packages/vite/src/node/plugins/workerImportMetaUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ function getWorkerType(raw: string, clean: string, i: number): WorkerType {
}

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

const hasViteIgnore = ignoreFlagRE.test(workerOptString)
if (hasViteIgnore) {
Expand Down
2 changes: 1 addition & 1 deletion playground/worker/worker/main-classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const classicSharedWorker = new SharedWorker(
new URL('../classic-shared-worker.js', import.meta.url),
{
type: 'classic'
},
}, // test comment
)
classicSharedWorker.port.addEventListener('message', (ev) => {
text('.classic-shared-worker', JSON.stringify(ev.data))
Expand Down

0 comments on commit 66c9058

Please sign in to comment.