Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(worker): support trailing comma #10211

Merged
merged 1 commit into from Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/vite/src/node/plugins/workerImportMetaUrl.ts
Expand Up @@ -38,16 +38,20 @@ function getWorkerType(raw: string, clean: string, i: number): WorkerType {
}

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

const hasViteIgnore = ignoreFlagRE.test(workerOptString)
if (hasViteIgnore) {
return 'ignore'
}

// need to find in no comment code
const cleanWorkerOptString = clean.substring(commaIndex + 1, endIndex)
if (!cleanWorkerOptString.trim().length) {
const cleanWorkerOptString = clean.substring(commaIndex + 1, endIndex).trim()
if (!cleanWorkerOptString.length) {
return 'classic'
}

Expand Down
4 changes: 3 additions & 1 deletion playground/worker/worker/main-classic.js
Expand Up @@ -16,11 +16,13 @@ classicWorker.addEventListener('message', ({ data }) => {
})
classicWorker.postMessage('ping')

// prettier-ignore
// test trailing comma
const classicSharedWorker = new SharedWorker(
new URL('../classic-shared-worker.js', import.meta.url),
{
type: 'classic'
}
},
)
classicSharedWorker.port.addEventListener('message', (ev) => {
text('.classic-shared-worker', JSON.stringify(ev.data))
Expand Down