Commit 9a64440d authored by Luke Sandberg's avatar Luke Sandberg

Fix: remove `declare function` statements that prevented free var rewriting

The `declare function __turbopack_*__` statements in the extracted modules
caused SWC to treat them as local bindings instead of free variables,
preventing Turbopack's free var rewriting from transforming them into
`__turbopack_context__.<shortcut>()` calls.

Also fixes prettier formatting for CI (which runs `prettier --check .`
without `--with-node-modules`).
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent 7b2d8614
......@@ -3,12 +3,8 @@
* Only included when a .wasm file is actually imported.
*/
'use turbopack no side effects'
declare function __turbopack_chunk_url__(chunkPath: string): string
export async function instantiateWebAssembly(
chunkPath: string,
_edgeModule: () => WebAssembly.Module,
......
......@@ -3,8 +3,6 @@
* Only included when a .wasm file is actually imported.
*/
'use turbopack no side effects'
async function loadEdgeWasm(
......
......@@ -3,12 +3,8 @@
* Only included when a .wasm file is actually imported.
*/
'use turbopack no side effects'
declare function __turbopack_resolve_chunk_path__(path: string): string
function readWebAssemblyAsResponse(path: string) {
const { createReadStream } = require('fs') as typeof import('fs')
const { Readable } = require('stream') as typeof import('stream')
......
......@@ -3,14 +3,8 @@
* Only included when a Web Worker or SharedWorker is actually used.
*/
'use turbopack no side effects'
declare function __turbopack_chunk_url__(chunkPath: string): string
declare function __turbopack_forwarded_globals__(): string[]
declare function __turbopack_asset_suffix__(): string
/**
* Creates a worker by instantiating the given WorkerConstructor with the
* appropriate URL and options.
......
......@@ -3,12 +3,8 @@
* Only included when a Node.js worker_threads Worker is actually used.
*/
'use turbopack no side effects'
declare function __turbopack_forwarded_globals__(): string[]
/**
* Creates a Node.js worker thread by instantiating the given WorkerConstructor
* with the appropriate path and options, including forwarded globals.
......
......@@ -16,18 +16,18 @@ __turbopack_context__.s([
/**
* Browser worker creation module.
* Only included when a Web Worker or SharedWorker is actually used.
*/ /* eslint-disable @typescript-eslint/no-unused-vars */ 'use turbopack no side effects';
*/ 'use turbopack no side effects';
function createWorker(WorkerConstructor, entrypoint, moduleChunks, workerOptions) {
const isSharedWorker = WorkerConstructor.name === 'SharedWorker';
const chunkUrls = moduleChunks.map((chunk)=>__turbopack_chunk_url__(chunk)).reverse();
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.w(chunk)).reverse();
const params = [
chunkUrls,
__turbopack_asset_suffix__()
/*TURBOPACK member replacement*/ __turbopack_context__.X()
];
for (const globalName of __turbopack_forwarded_globals__()){
for (const globalName of /*TURBOPACK member replacement*/ __turbopack_context__.b()){
params.push(globalThis[globalName]);
}
const url = new URL(__turbopack_chunk_url__(entrypoint), location.origin);
const url = new URL(/*TURBOPACK member replacement*/ __turbopack_context__.w(entrypoint), location.origin);
const paramsJson = JSON.stringify(params);
if (isSharedWorker) {
url.searchParams.set('params', paramsJson);
......
......@@ -3,6 +3,6 @@
"sources": [],
"sections": [
{"offset": {"line": 3, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/vercel.cjs"],"sourcesContent":["module.exports = 'turbopack'\n"],"names":["module","exports"],"mappings":"AAAAA,OAAOC,OAAO,GAAG"}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/shared/worker-browser.ts"],"sourcesContent":["/**\n * Browser worker creation module.\n * Only included when a Web Worker or SharedWorker is actually used.\n */\n\n/* eslint-disable @typescript-eslint/no-unused-vars */\n\n'use turbopack no side effects'\n\ndeclare function __turbopack_chunk_url__(chunkPath: string): string\ndeclare function __turbopack_forwarded_globals__(): string[]\ndeclare function __turbopack_asset_suffix__(): string\n\n/**\n * Creates a worker by instantiating the given WorkerConstructor with the\n * appropriate URL and options.\n *\n * The entrypoint is a pre-compiled worker runtime file. The params configure\n * which module chunks to load and which module to run as the entry point.\n *\n * The params are a JSON array of the following structure:\n * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...WORKER_FORWARDED_GLOBALS values]`\n *\n * @param WorkerConstructor The Worker or SharedWorker constructor\n * @param entrypoint URL path to the worker entrypoint chunk\n * @param moduleChunks list of module chunk paths to load\n * @param workerOptions options to pass to the Worker constructor (optional)\n */\nexport function createWorker(\n WorkerConstructor: { new (url: URL, options?: object): Worker },\n entrypoint: string,\n moduleChunks: string[],\n workerOptions?: object\n): Worker {\n const isSharedWorker = WorkerConstructor.name === 'SharedWorker'\n\n const chunkUrls = moduleChunks\n .map((chunk) => __turbopack_chunk_url__(chunk))\n .reverse()\n const params: unknown[] = [chunkUrls, __turbopack_asset_suffix__()]\n for (const globalName of __turbopack_forwarded_globals__()) {\n params.push((globalThis as Record<string, unknown>)[globalName])\n }\n\n const url = new URL(__turbopack_chunk_url__(entrypoint), location.origin)\n const paramsJson = JSON.stringify(params)\n if (isSharedWorker) {\n url.searchParams.set('params', paramsJson)\n } else {\n url.hash = '#params=' + encodeURIComponent(paramsJson)\n }\n\n // Remove type: \"module\" from options since our worker entrypoint is not a module\n const options = workerOptions\n ? { ...workerOptions, type: undefined }\n : undefined\n return new WorkerConstructor(url, options)\n}\n"],"names":["createWorker","WorkerConstructor","entrypoint","moduleChunks","workerOptions","isSharedWorker","name","chunkUrls","map","chunk","__turbopack_chunk_url__","reverse","params","__turbopack_asset_suffix__","globalName","__turbopack_forwarded_globals__","push","globalThis","url","URL","location","origin","paramsJson","JSON","stringify","searchParams","set","hash","encodeURIComponent","options","type","undefined"],"mappings":";;;;AAAA;;;CAGC,GAED,oDAAoD,GAEpD;AAqBO,SAASA,aACdC,iBAA+D,EAC/DC,UAAkB,EAClBC,YAAsB,EACtBC,aAAsB;IAEtB,MAAMC,iBAAiBJ,kBAAkBK,IAAI,KAAK;IAElD,MAAMC,YAAYJ,aACfK,GAAG,CAAC,CAACC,QAAUC,wBAAwBD,QACvCE,OAAO;IACV,MAAMC,SAAoB;QAACL;QAAWM;KAA6B;IACnE,KAAK,MAAMC,cAAcC,kCAAmC;QAC1DH,OAAOI,IAAI,CAAC,AAACC,UAAsC,CAACH,WAAW;IACjE;IAEA,MAAMI,MAAM,IAAIC,IAAIT,wBAAwBR,aAAakB,SAASC,MAAM;IACxE,MAAMC,aAAaC,KAAKC,SAAS,CAACZ;IAClC,IAAIP,gBAAgB;QAClBa,IAAIO,YAAY,CAACC,GAAG,CAAC,UAAUJ;IACjC,OAAO;QACLJ,IAAIS,IAAI,GAAG,aAAaC,mBAAmBN;IAC7C;IAEA,iFAAiF;IACjF,MAAMO,UAAUzB,gBACZ;QAAE,GAAGA,aAAa;QAAE0B,MAAMC;IAAU,IACpCA;IACJ,OAAO,IAAI9B,kBAAkBiB,KAAKW;AACpC","ignoreList":[0]}},
{"offset": {"line": 11, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/shared/worker-browser.ts"],"sourcesContent":["/**\n * Browser worker creation module.\n * Only included when a Web Worker or SharedWorker is actually used.\n */\n\n'use turbopack no side effects'\n\n/**\n * Creates a worker by instantiating the given WorkerConstructor with the\n * appropriate URL and options.\n *\n * The entrypoint is a pre-compiled worker runtime file. The params configure\n * which module chunks to load and which module to run as the entry point.\n *\n * The params are a JSON array of the following structure:\n * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...WORKER_FORWARDED_GLOBALS values]`\n *\n * @param WorkerConstructor The Worker or SharedWorker constructor\n * @param entrypoint URL path to the worker entrypoint chunk\n * @param moduleChunks list of module chunk paths to load\n * @param workerOptions options to pass to the Worker constructor (optional)\n */\nexport function createWorker(\n WorkerConstructor: { new (url: URL, options?: object): Worker },\n entrypoint: string,\n moduleChunks: string[],\n workerOptions?: object\n): Worker {\n const isSharedWorker = WorkerConstructor.name === 'SharedWorker'\n\n const chunkUrls = moduleChunks\n .map((chunk) => __turbopack_chunk_url__(chunk))\n .reverse()\n const params: unknown[] = [chunkUrls, __turbopack_asset_suffix__()]\n for (const globalName of __turbopack_forwarded_globals__()) {\n params.push((globalThis as Record<string, unknown>)[globalName])\n }\n\n const url = new URL(__turbopack_chunk_url__(entrypoint), location.origin)\n const paramsJson = JSON.stringify(params)\n if (isSharedWorker) {\n url.searchParams.set('params', paramsJson)\n } else {\n url.hash = '#params=' + encodeURIComponent(paramsJson)\n }\n\n // Remove type: \"module\" from options since our worker entrypoint is not a module\n const options = workerOptions\n ? { ...workerOptions, type: undefined }\n : undefined\n return new WorkerConstructor(url, options)\n}\n"],"names":["createWorker","WorkerConstructor","entrypoint","moduleChunks","workerOptions","isSharedWorker","name","chunkUrls","map","chunk","reverse","params","globalName","push","globalThis","url","URL","location","origin","paramsJson","JSON","stringify","searchParams","set","hash","encodeURIComponent","options","type","undefined"],"mappings":";;;;AAAA;;;CAGC,GAED;AAiBO,SAASA,aACdC,iBAA+D,EAC/DC,UAAkB,EAClBC,YAAsB,EACtBC,aAAsB;IAEtB,MAAMC,iBAAiBJ,kBAAkBK,IAAI,KAAK;IAElD,MAAMC,YAAYJ,aACfK,GAAG,CAAC,CAACC,QAAU,yDAAwBA,QACvCC,OAAO;IACV,MAAMC,SAAoB;QAACJ;QAAW;KAA6B;IACnE,KAAK,MAAMK,cAAc,2DAAmC;QAC1DD,OAAOE,IAAI,CAAC,AAACC,UAAsC,CAACF,WAAW;IACjE;IAEA,MAAMG,MAAM,IAAIC,IAAI,yDAAwBd,aAAae,SAASC,MAAM;IACxE,MAAMC,aAAaC,KAAKC,SAAS,CAACV;IAClC,IAAIN,gBAAgB;QAClBU,IAAIO,YAAY,CAACC,GAAG,CAAC,UAAUJ;IACjC,OAAO;QACLJ,IAAIS,IAAI,GAAG,aAAaC,mBAAmBN;IAC7C;IAEA,iFAAiF;IACjF,MAAMO,UAAUtB,gBACZ;QAAE,GAAGA,aAAa;QAAEuB,MAAMC;IAAU,IACpCA;IACJ,OAAO,IAAI3B,kBAAkBc,KAAKW;AACpC","ignoreList":[0]}},
{"offset": {"line": 57, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/imports/ignore-comments/input/index.js"],"sourcesContent":["import('./vercel.mjs').then(console.log)\nimport(/* webpackIgnore: false */ './vercel.mjs').then(console.log)\nconsole.log(require('./vercel.cjs'))\nnew Worker(\n /* turbopackIgnore: false */ new URL('./vercel.cjs', import.meta.url)\n)\n\n// turbopack shouldn't attempt to bundle these, and they should be preserved in the output\nimport(/* webpackIgnore: true */ './ignore.mjs')\nimport(/* turbopackIgnore: true */ './ignore.mjs')\n\n// this should work for cjs requires too\nrequire(/* webpackIgnore: true */ './ignore.cjs')\nrequire(/* turbopackIgnore: true */ './ignore.cjs')\n\nnew Worker(\n /* turbopackIgnore: true */ new URL('./ignore-worker.cjs', import.meta.url)\n)\nnew Worker(\n /* webpackIgnore: true */ new URL('./ignore-worker.cjs', import.meta.url)\n)\n\nexport function foo(plugin) {\n return require(/* turbopackIgnore: true */ plugin)\n}\n"],"names":["then","console","log","Worker","require","foo","plugin"],"mappings":";;;;;;;;;AAAA,gKAAuBA,IAAI,CAACC,QAAQC,GAAG;AACvC,gKAAkDF,IAAI,CAACC,QAAQC,GAAG;AAClED,QAAQC,GAAG;AACX,iKAAIC;AAIJ,0FAA0F;AAC1F,MAAM,CAAC,uBAAuB,GAAG;AACjC,MAAM,CAAC,yBAAyB,GAAG;AAEnC,wCAAwC;AACxCC,QAAQ,uBAAuB,GAAG;AAClCA,QAAQ,yBAAyB,GAAG;AAEpC,IAAID;AAGJ,IAAIA;AAIG,SAASE,IAAIC,MAAM;IACxB,OAAOF,QAAQ,yBAAyB,GAAGE;AAC7C"}}]
}
\ No newline at end of file
......@@ -12,18 +12,18 @@ __turbopack_context__.s([
/**
* Browser worker creation module.
* Only included when a Web Worker or SharedWorker is actually used.
*/ /* eslint-disable @typescript-eslint/no-unused-vars */ 'use turbopack no side effects';
*/ 'use turbopack no side effects';
function createWorker(WorkerConstructor, entrypoint, moduleChunks, workerOptions) {
const isSharedWorker = WorkerConstructor.name === 'SharedWorker';
const chunkUrls = moduleChunks.map((chunk)=>__turbopack_chunk_url__(chunk)).reverse();
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.w(chunk)).reverse();
const params = [
chunkUrls,
__turbopack_asset_suffix__()
/*TURBOPACK member replacement*/ __turbopack_context__.X()
];
for (const globalName of __turbopack_forwarded_globals__()){
for (const globalName of /*TURBOPACK member replacement*/ __turbopack_context__.b()){
params.push(globalThis[globalName]);
}
const url = new URL(__turbopack_chunk_url__(entrypoint), location.origin);
const url = new URL(/*TURBOPACK member replacement*/ __turbopack_context__.w(entrypoint), location.origin);
const paramsJson = JSON.stringify(params);
if (isSharedWorker) {
url.searchParams.set('params', paramsJson);
......
......@@ -2,6 +2,6 @@
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 7, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/shared/worker-browser.ts"],"sourcesContent":["/**\n * Browser worker creation module.\n * Only included when a Web Worker or SharedWorker is actually used.\n */\n\n/* eslint-disable @typescript-eslint/no-unused-vars */\n\n'use turbopack no side effects'\n\ndeclare function __turbopack_chunk_url__(chunkPath: string): string\ndeclare function __turbopack_forwarded_globals__(): string[]\ndeclare function __turbopack_asset_suffix__(): string\n\n/**\n * Creates a worker by instantiating the given WorkerConstructor with the\n * appropriate URL and options.\n *\n * The entrypoint is a pre-compiled worker runtime file. The params configure\n * which module chunks to load and which module to run as the entry point.\n *\n * The params are a JSON array of the following structure:\n * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...WORKER_FORWARDED_GLOBALS values]`\n *\n * @param WorkerConstructor The Worker or SharedWorker constructor\n * @param entrypoint URL path to the worker entrypoint chunk\n * @param moduleChunks list of module chunk paths to load\n * @param workerOptions options to pass to the Worker constructor (optional)\n */\nexport function createWorker(\n WorkerConstructor: { new (url: URL, options?: object): Worker },\n entrypoint: string,\n moduleChunks: string[],\n workerOptions?: object\n): Worker {\n const isSharedWorker = WorkerConstructor.name === 'SharedWorker'\n\n const chunkUrls = moduleChunks\n .map((chunk) => __turbopack_chunk_url__(chunk))\n .reverse()\n const params: unknown[] = [chunkUrls, __turbopack_asset_suffix__()]\n for (const globalName of __turbopack_forwarded_globals__()) {\n params.push((globalThis as Record<string, unknown>)[globalName])\n }\n\n const url = new URL(__turbopack_chunk_url__(entrypoint), location.origin)\n const paramsJson = JSON.stringify(params)\n if (isSharedWorker) {\n url.searchParams.set('params', paramsJson)\n } else {\n url.hash = '#params=' + encodeURIComponent(paramsJson)\n }\n\n // Remove type: \"module\" from options since our worker entrypoint is not a module\n const options = workerOptions\n ? { ...workerOptions, type: undefined }\n : undefined\n return new WorkerConstructor(url, options)\n}\n"],"names":["createWorker","WorkerConstructor","entrypoint","moduleChunks","workerOptions","isSharedWorker","name","chunkUrls","map","chunk","__turbopack_chunk_url__","reverse","params","__turbopack_asset_suffix__","globalName","__turbopack_forwarded_globals__","push","globalThis","url","URL","location","origin","paramsJson","JSON","stringify","searchParams","set","hash","encodeURIComponent","options","type","undefined"],"mappings":";;;;AAAA;;;CAGC,GAED,oDAAoD,GAEpD;AAqBO,SAASA,aACdC,iBAA+D,EAC/DC,UAAkB,EAClBC,YAAsB,EACtBC,aAAsB;IAEtB,MAAMC,iBAAiBJ,kBAAkBK,IAAI,KAAK;IAElD,MAAMC,YAAYJ,aACfK,GAAG,CAAC,CAACC,QAAUC,wBAAwBD,QACvCE,OAAO;IACV,MAAMC,SAAoB;QAACL;QAAWM;KAA6B;IACnE,KAAK,MAAMC,cAAcC,kCAAmC;QAC1DH,OAAOI,IAAI,CAAC,AAACC,UAAsC,CAACH,WAAW;IACjE;IAEA,MAAMI,MAAM,IAAIC,IAAIT,wBAAwBR,aAAakB,SAASC,MAAM;IACxE,MAAMC,aAAaC,KAAKC,SAAS,CAACZ;IAClC,IAAIP,gBAAgB;QAClBa,IAAIO,YAAY,CAACC,GAAG,CAAC,UAAUJ;IACjC,OAAO;QACLJ,IAAIS,IAAI,GAAG,aAAaC,mBAAmBN;IAC7C;IAEA,iFAAiF;IACjF,MAAMO,UAAUzB,gBACZ;QAAE,GAAGA,aAAa;QAAE0B,MAAMC;IAAU,IACpCA;IACJ,OAAO,IAAI9B,kBAAkBiB,KAAKW;AACpC","ignoreList":[0]}},
{"offset": {"line": 7, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/shared/worker-browser.ts"],"sourcesContent":["/**\n * Browser worker creation module.\n * Only included when a Web Worker or SharedWorker is actually used.\n */\n\n'use turbopack no side effects'\n\n/**\n * Creates a worker by instantiating the given WorkerConstructor with the\n * appropriate URL and options.\n *\n * The entrypoint is a pre-compiled worker runtime file. The params configure\n * which module chunks to load and which module to run as the entry point.\n *\n * The params are a JSON array of the following structure:\n * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...WORKER_FORWARDED_GLOBALS values]`\n *\n * @param WorkerConstructor The Worker or SharedWorker constructor\n * @param entrypoint URL path to the worker entrypoint chunk\n * @param moduleChunks list of module chunk paths to load\n * @param workerOptions options to pass to the Worker constructor (optional)\n */\nexport function createWorker(\n WorkerConstructor: { new (url: URL, options?: object): Worker },\n entrypoint: string,\n moduleChunks: string[],\n workerOptions?: object\n): Worker {\n const isSharedWorker = WorkerConstructor.name === 'SharedWorker'\n\n const chunkUrls = moduleChunks\n .map((chunk) => __turbopack_chunk_url__(chunk))\n .reverse()\n const params: unknown[] = [chunkUrls, __turbopack_asset_suffix__()]\n for (const globalName of __turbopack_forwarded_globals__()) {\n params.push((globalThis as Record<string, unknown>)[globalName])\n }\n\n const url = new URL(__turbopack_chunk_url__(entrypoint), location.origin)\n const paramsJson = JSON.stringify(params)\n if (isSharedWorker) {\n url.searchParams.set('params', paramsJson)\n } else {\n url.hash = '#params=' + encodeURIComponent(paramsJson)\n }\n\n // Remove type: \"module\" from options since our worker entrypoint is not a module\n const options = workerOptions\n ? { ...workerOptions, type: undefined }\n : undefined\n return new WorkerConstructor(url, options)\n}\n"],"names":["createWorker","WorkerConstructor","entrypoint","moduleChunks","workerOptions","isSharedWorker","name","chunkUrls","map","chunk","reverse","params","globalName","push","globalThis","url","URL","location","origin","paramsJson","JSON","stringify","searchParams","set","hash","encodeURIComponent","options","type","undefined"],"mappings":";;;;AAAA;;;CAGC,GAED;AAiBO,SAASA,aACdC,iBAA+D,EAC/DC,UAAkB,EAClBC,YAAsB,EACtBC,aAAsB;IAEtB,MAAMC,iBAAiBJ,kBAAkBK,IAAI,KAAK;IAElD,MAAMC,YAAYJ,aACfK,GAAG,CAAC,CAACC,QAAU,yDAAwBA,QACvCC,OAAO;IACV,MAAMC,SAAoB;QAACJ;QAAW;KAA6B;IACnE,KAAK,MAAMK,cAAc,2DAAmC;QAC1DD,OAAOE,IAAI,CAAC,AAACC,UAAsC,CAACF,WAAW;IACjE;IAEA,MAAMG,MAAM,IAAIC,IAAI,yDAAwBd,aAAae,SAASC,MAAM;IACxE,MAAMC,aAAaC,KAAKC,SAAS,CAACV;IAClC,IAAIN,gBAAgB;QAClBU,IAAIO,YAAY,CAACC,GAAG,CAAC,UAAUJ;IACjC,OAAO;QACLJ,IAAIS,IAAI,GAAG,aAAaC,mBAAmBN;IAC7C;IAEA,iFAAiF;IACjF,MAAMO,UAAUtB,gBACZ;QAAE,GAAGA,aAAa;QAAEuB,MAAMC;IAAU,IACpCA;IACJ,OAAO,IAAI3B,kBAAkBc,KAAKW;AACpC","ignoreList":[0]}},
{"offset": {"line": 49, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/basic/input/index.js"],"sourcesContent":["console.log('index.js')\nconst url = new URL('./worker.js', import.meta.url)\nnew Worker(url)\n"],"names":["console","log","url","Worker"],"mappings":";;;;;AAAAA,QAAQC,GAAG,CAAC;AACZ,MAAMC;AACN,sJAAIC"}}]
}
\ No newline at end of file
......@@ -12,18 +12,18 @@ __turbopack_context__.s([
/**
* Browser worker creation module.
* Only included when a Web Worker or SharedWorker is actually used.
*/ /* eslint-disable @typescript-eslint/no-unused-vars */ 'use turbopack no side effects';
*/ 'use turbopack no side effects';
function createWorker(WorkerConstructor, entrypoint, moduleChunks, workerOptions) {
const isSharedWorker = WorkerConstructor.name === 'SharedWorker';
const chunkUrls = moduleChunks.map((chunk)=>__turbopack_chunk_url__(chunk)).reverse();
const chunkUrls = moduleChunks.map((chunk)=>/*TURBOPACK member replacement*/ __turbopack_context__.w(chunk)).reverse();
const params = [
chunkUrls,
__turbopack_asset_suffix__()
/*TURBOPACK member replacement*/ __turbopack_context__.X()
];
for (const globalName of __turbopack_forwarded_globals__()){
for (const globalName of /*TURBOPACK member replacement*/ __turbopack_context__.b()){
params.push(globalThis[globalName]);
}
const url = new URL(__turbopack_chunk_url__(entrypoint), location.origin);
const url = new URL(/*TURBOPACK member replacement*/ __turbopack_context__.w(entrypoint), location.origin);
const paramsJson = JSON.stringify(params);
if (isSharedWorker) {
url.searchParams.set('params', paramsJson);
......
......@@ -2,6 +2,6 @@
"version": 3,
"sources": [],
"sections": [
{"offset": {"line": 7, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/shared/worker-browser.ts"],"sourcesContent":["/**\n * Browser worker creation module.\n * Only included when a Web Worker or SharedWorker is actually used.\n */\n\n/* eslint-disable @typescript-eslint/no-unused-vars */\n\n'use turbopack no side effects'\n\ndeclare function __turbopack_chunk_url__(chunkPath: string): string\ndeclare function __turbopack_forwarded_globals__(): string[]\ndeclare function __turbopack_asset_suffix__(): string\n\n/**\n * Creates a worker by instantiating the given WorkerConstructor with the\n * appropriate URL and options.\n *\n * The entrypoint is a pre-compiled worker runtime file. The params configure\n * which module chunks to load and which module to run as the entry point.\n *\n * The params are a JSON array of the following structure:\n * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...WORKER_FORWARDED_GLOBALS values]`\n *\n * @param WorkerConstructor The Worker or SharedWorker constructor\n * @param entrypoint URL path to the worker entrypoint chunk\n * @param moduleChunks list of module chunk paths to load\n * @param workerOptions options to pass to the Worker constructor (optional)\n */\nexport function createWorker(\n WorkerConstructor: { new (url: URL, options?: object): Worker },\n entrypoint: string,\n moduleChunks: string[],\n workerOptions?: object\n): Worker {\n const isSharedWorker = WorkerConstructor.name === 'SharedWorker'\n\n const chunkUrls = moduleChunks\n .map((chunk) => __turbopack_chunk_url__(chunk))\n .reverse()\n const params: unknown[] = [chunkUrls, __turbopack_asset_suffix__()]\n for (const globalName of __turbopack_forwarded_globals__()) {\n params.push((globalThis as Record<string, unknown>)[globalName])\n }\n\n const url = new URL(__turbopack_chunk_url__(entrypoint), location.origin)\n const paramsJson = JSON.stringify(params)\n if (isSharedWorker) {\n url.searchParams.set('params', paramsJson)\n } else {\n url.hash = '#params=' + encodeURIComponent(paramsJson)\n }\n\n // Remove type: \"module\" from options since our worker entrypoint is not a module\n const options = workerOptions\n ? { ...workerOptions, type: undefined }\n : undefined\n return new WorkerConstructor(url, options)\n}\n"],"names":["createWorker","WorkerConstructor","entrypoint","moduleChunks","workerOptions","isSharedWorker","name","chunkUrls","map","chunk","__turbopack_chunk_url__","reverse","params","__turbopack_asset_suffix__","globalName","__turbopack_forwarded_globals__","push","globalThis","url","URL","location","origin","paramsJson","JSON","stringify","searchParams","set","hash","encodeURIComponent","options","type","undefined"],"mappings":";;;;AAAA;;;CAGC,GAED,oDAAoD,GAEpD;AAqBO,SAASA,aACdC,iBAA+D,EAC/DC,UAAkB,EAClBC,YAAsB,EACtBC,aAAsB;IAEtB,MAAMC,iBAAiBJ,kBAAkBK,IAAI,KAAK;IAElD,MAAMC,YAAYJ,aACfK,GAAG,CAAC,CAACC,QAAUC,wBAAwBD,QACvCE,OAAO;IACV,MAAMC,SAAoB;QAACL;QAAWM;KAA6B;IACnE,KAAK,MAAMC,cAAcC,kCAAmC;QAC1DH,OAAOI,IAAI,CAAC,AAACC,UAAsC,CAACH,WAAW;IACjE;IAEA,MAAMI,MAAM,IAAIC,IAAIT,wBAAwBR,aAAakB,SAASC,MAAM;IACxE,MAAMC,aAAaC,KAAKC,SAAS,CAACZ;IAClC,IAAIP,gBAAgB;QAClBa,IAAIO,YAAY,CAACC,GAAG,CAAC,UAAUJ;IACjC,OAAO;QACLJ,IAAIS,IAAI,GAAG,aAAaC,mBAAmBN;IAC7C;IAEA,iFAAiF;IACjF,MAAMO,UAAUzB,gBACZ;QAAE,GAAGA,aAAa;QAAE0B,MAAMC;IAAU,IACpCA;IACJ,OAAO,IAAI9B,kBAAkBiB,KAAKW;AACpC","ignoreList":[0]}},
{"offset": {"line": 7, "column": 0}, "map": {"version":3,"sources":["turbopack:///[turbopack]/shared/worker-browser.ts"],"sourcesContent":["/**\n * Browser worker creation module.\n * Only included when a Web Worker or SharedWorker is actually used.\n */\n\n'use turbopack no side effects'\n\n/**\n * Creates a worker by instantiating the given WorkerConstructor with the\n * appropriate URL and options.\n *\n * The entrypoint is a pre-compiled worker runtime file. The params configure\n * which module chunks to load and which module to run as the entry point.\n *\n * The params are a JSON array of the following structure:\n * `[TURBOPACK_NEXT_CHUNK_URLS, ASSET_SUFFIX, ...WORKER_FORWARDED_GLOBALS values]`\n *\n * @param WorkerConstructor The Worker or SharedWorker constructor\n * @param entrypoint URL path to the worker entrypoint chunk\n * @param moduleChunks list of module chunk paths to load\n * @param workerOptions options to pass to the Worker constructor (optional)\n */\nexport function createWorker(\n WorkerConstructor: { new (url: URL, options?: object): Worker },\n entrypoint: string,\n moduleChunks: string[],\n workerOptions?: object\n): Worker {\n const isSharedWorker = WorkerConstructor.name === 'SharedWorker'\n\n const chunkUrls = moduleChunks\n .map((chunk) => __turbopack_chunk_url__(chunk))\n .reverse()\n const params: unknown[] = [chunkUrls, __turbopack_asset_suffix__()]\n for (const globalName of __turbopack_forwarded_globals__()) {\n params.push((globalThis as Record<string, unknown>)[globalName])\n }\n\n const url = new URL(__turbopack_chunk_url__(entrypoint), location.origin)\n const paramsJson = JSON.stringify(params)\n if (isSharedWorker) {\n url.searchParams.set('params', paramsJson)\n } else {\n url.hash = '#params=' + encodeURIComponent(paramsJson)\n }\n\n // Remove type: \"module\" from options since our worker entrypoint is not a module\n const options = workerOptions\n ? { ...workerOptions, type: undefined }\n : undefined\n return new WorkerConstructor(url, options)\n}\n"],"names":["createWorker","WorkerConstructor","entrypoint","moduleChunks","workerOptions","isSharedWorker","name","chunkUrls","map","chunk","reverse","params","globalName","push","globalThis","url","URL","location","origin","paramsJson","JSON","stringify","searchParams","set","hash","encodeURIComponent","options","type","undefined"],"mappings":";;;;AAAA;;;CAGC,GAED;AAiBO,SAASA,aACdC,iBAA+D,EAC/DC,UAAkB,EAClBC,YAAsB,EACtBC,aAAsB;IAEtB,MAAMC,iBAAiBJ,kBAAkBK,IAAI,KAAK;IAElD,MAAMC,YAAYJ,aACfK,GAAG,CAAC,CAACC,QAAU,yDAAwBA,QACvCC,OAAO;IACV,MAAMC,SAAoB;QAACJ;QAAW;KAA6B;IACnE,KAAK,MAAMK,cAAc,2DAAmC;QAC1DD,OAAOE,IAAI,CAAC,AAACC,UAAsC,CAACF,WAAW;IACjE;IAEA,MAAMG,MAAM,IAAIC,IAAI,yDAAwBd,aAAae,SAASC,MAAM;IACxE,MAAMC,aAAaC,KAAKC,SAAS,CAACV;IAClC,IAAIN,gBAAgB;QAClBU,IAAIO,YAAY,CAACC,GAAG,CAAC,UAAUJ;IACjC,OAAO;QACLJ,IAAIS,IAAI,GAAG,aAAaC,mBAAmBN;IAC7C;IAEA,iFAAiF;IACjF,MAAMO,UAAUtB,gBACZ;QAAE,GAAGA,aAAa;QAAEuB,MAAMC;IAAU,IACpCA;IACJ,OAAO,IAAI3B,kBAAkBc,KAAKW;AACpC","ignoreList":[0]}},
{"offset": {"line": 49, "column": 0}, "map": {"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/workers/shared/input/index.js"],"sourcesContent":["const url = new URL('./worker.js', import.meta.url)\nnew SharedWorker(url)\n"],"names":["url","SharedWorker"],"mappings":";;;;;AAAA,MAAMA;AACN,uJAAIC"}}]
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment