Skip to content

Commit ef79a49

Browse files
Scan0815oliver
andauthored
fix(compiler): silence INVALID_ANNOTATION and SOURCEMAP_BROKEN warnings from workerPlugin (#6718)
* fix(compiler): drop invalid @__PURE__ before import.meta in workerPlugin The /*@__PURE__*/ annotation is only meaningful in front of call or new expressions. In getWorkerMain and getInlineWorker it was placed before an import.meta.ROLLUP_FILE_URL_* property access, which Rollup cannot interpret and silently strips with an INVALID_ANNOTATION warning on every build of a project that uses *.worker.ts entries. Drop the unused annotation on the workerPath assignment. The remaining PURE markers on the createWorker(...) / createWorkerProxy(...) calls are unchanged. * fix(compiler): emit noop sourcemap from workerPlugin transform The workerPlugin transform hook returned synthetic wrapper code without a sourcemap, triggering a SOURCEMAP_BROKEN warning from Rollup for every project that builds a *.worker.ts entry. The Rollup plugin convention for transforms that produce code with no useful source-position mapping is to return an empty mappings string; do that for all five transform return paths (the mocked hydrate/worker-platform branch and the four real-bundle branches). --------- Co-authored-by: oliver <oliver@bitcaster.de>
1 parent 2d5ab9f commit ef79a49

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/compiler/bundle/worker-plugin.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ export const workerPlugin = (
1919
name: 'workerPlugin',
2020
transform(_, id) {
2121
if (id.endsWith('?worker') || id.endsWith('?worker-inline')) {
22-
return getMockedWorkerMain();
22+
return {
23+
code: getMockedWorkerMain(),
24+
map: { mappings: '' },
25+
};
2326
}
2427
return null;
2528
},
@@ -77,6 +80,7 @@ export const workerPlugin = (
7780
dependencies.forEach((id) => this.addWatchFile(id));
7881
return {
7982
code: getWorkerMain(referenceId, workerName, workerMsgId),
83+
map: { mappings: '' },
8084
moduleSideEffects: false,
8185
};
8286
} else if (id.endsWith('?worker-inline')) {
@@ -98,6 +102,7 @@ export const workerPlugin = (
98102
dependencies.forEach((id) => this.addWatchFile(id));
99103
return {
100104
code: getInlineWorker(referenceId, workerName, workerMsgId),
105+
map: { mappings: '' },
101106
moduleSideEffects: false,
102107
};
103108
}
@@ -110,11 +115,13 @@ export const workerPlugin = (
110115
if (inlineWorkers) {
111116
return {
112117
code: getInlineWorkerProxy(workerEntryPath, worker.workerMsgId, worker.exports),
118+
map: { mappings: '' },
113119
moduleSideEffects: false,
114120
};
115121
} else {
116122
return {
117123
code: getWorkerProxy(workerEntryPath, worker.exports),
124+
map: { mappings: '' },
118125
moduleSideEffects: false,
119126
};
120127
}
@@ -405,7 +412,7 @@ const getWorkerMain = (referenceId: string, workerName: string, workerMsgId: str
405412
import { createWorker } from '${WORKER_HELPER_ID}';
406413
export const workerName = '${workerName}';
407414
export const workerMsgId = '${workerMsgId}';
408-
export const workerPath = /*@__PURE__*/import.meta.ROLLUP_FILE_URL_${referenceId};
415+
export const workerPath = import.meta.ROLLUP_FILE_URL_${referenceId};
409416
export const worker = /*@__PURE__*/createWorker(workerPath, workerName, workerMsgId);
410417
`;
411418
};
@@ -415,7 +422,7 @@ const getInlineWorker = (referenceId: string, workerName: string, workerMsgId: s
415422
import { createWorker } from '${WORKER_HELPER_ID}';
416423
export const workerName = '${workerName}';
417424
export const workerMsgId = '${workerMsgId}';
418-
export const workerPath = /*@__PURE__*/import.meta.ROLLUP_FILE_URL_${referenceId};
425+
export const workerPath = import.meta.ROLLUP_FILE_URL_${referenceId};
419426
export let worker;
420427
try {
421428
// first try directly starting the worker with the URL

0 commit comments

Comments
 (0)