Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ playground/html/invalid.html
playground/html/valid.html
playground/external/public/[email protected]
playground/ssr-html/public/[email protected]
playground/worker/classic-iife.js
Copy link
Contributor Author

@hi-ogawa hi-ogawa Aug 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prettier-ignore comment doesn't seem to avoid prepending ; to (() => {})(), so I needed to prettierignore an entire file.

Technically we could test the same thing by just adding (() => {})() to existing playground/worker/classic-worker.js, but that would require prettierignore-ing that file, so I added a new file playground/worker/classic-iife.js just for this.

EDIT: On second thought, doing that seems unnecessary involved, so I went back to prettierignore-ing existing classic-worker.js.

2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ export function webWorkerPlugin(config: ResolvedConfig): Plugin {
}
if (injectEnv) {
const s = new MagicString(raw)
s.prepend(injectEnv)
s.prepend(injectEnv + ';\n')
return {
code: s.toString(),
map: s.generateMap({ hires: 'boundary' }),
Expand Down
5 changes: 5 additions & 0 deletions playground/worker/__tests__/es/worker-es.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ test('classic worker', async () => {
'A classic',
true,
)
await untilUpdated(
() => page.textContent('.classic-iife'),
'classic-iife',
true,
)
})

test('emit chunk', async () => {
Expand Down
5 changes: 5 additions & 0 deletions playground/worker/classic-iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(() => {
self.addEventListener('message', () => {
self.postMessage('classic-iife');
})
})()
1 change: 1 addition & 0 deletions playground/worker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ <h2 class="format-iife">format iife:</h2>
</p>
<code class="classic-worker"></code>
<code class="classic-worker-import"></code>
<code class="classic-iife"></code>

<p>
new SharedWorker(new URL('./classic-shared-worker.js', import.meta.url), {
Expand Down
6 changes: 6 additions & 0 deletions playground/worker/worker/main-classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ classicSharedWorker.port.addEventListener('message', (ev) => {
text('.classic-shared-worker', JSON.stringify(ev.data))
})
classicSharedWorker.port.start()

const classicIife = new Worker(new URL('../classic-iife.js', import.meta.url))
classicIife.addEventListener('message', (e) => {
text('.classic-iife', e.data)
})
classicIife.postMessage('ping')