{"version":3,"names":["path","require","ACTIONS","GET_DEFAULT_EXTENSIONS","SET_OPTIONS","TRANSFORM","TRANSFORM_SYNC","_send","WeakMap","_eCache","Client","constructor","send","_classPrivateFieldInitSpec","writable","value","_classPrivateFieldSet","getDefaultExtensions","_classPrivateFieldGet2","_classPrivateFieldGet","call","undefined","setOptions","options","transform","code","filename","exports","WorkerClient","_worker","_signal","_class2","action","payload","subChannel","_classStaticPrivateFieldSpecGet","_worker_threads","MessageChannel","postMessage","signal","port","port1","Atomics","wait","message","receiveMessageOnPort","port2","error","Object","assign","errorData","result","Worker","resolve","__dirname","env","_markInRegisterWorker","process","Int32Array","SharedArrayBuffer","unref","get","_get_markInRegisterWorker","set","_get_worker_threads","markInRegisterWorker","_class3","_handleMessage","LocalClient","_classStaticPrivateFi","_classStaticPrivateFieldSpecSet","isLocalClient"],"sources":["../src/worker-client.js"],"sourcesContent":["const path = require(\"path\");\n\nconst ACTIONS = {\n GET_DEFAULT_EXTENSIONS: \"GET_DEFAULT_EXTENSIONS\",\n SET_OPTIONS: \"SET_OPTIONS\",\n TRANSFORM: \"TRANSFORM\",\n TRANSFORM_SYNC: \"TRANSFORM_SYNC\",\n};\n\nclass Client {\n #send;\n\n constructor(send) {\n this.#send = send;\n }\n\n #eCache;\n /** @return {string[]} */\n getDefaultExtensions() {\n return (this.#eCache ??= this.#send(\n ACTIONS.GET_DEFAULT_EXTENSIONS,\n undefined,\n ));\n }\n\n /**\n * @param {object} options\n * @return {void}\n */\n setOptions(options) {\n return this.#send(ACTIONS.SET_OPTIONS, options);\n }\n\n /**\n * @param {string} code\n * @param {string} filename\n * @return {{ code: string, map: object } | null}\n */\n transform(code, filename) {\n return this.#send(ACTIONS.TRANSFORM, { code, filename });\n }\n}\n\n// We need to run Babel in a worker because require hooks must\n// run synchronously, but many steps of Babel's config loading\n// (which is done for each file) can be asynchronous\nexports.WorkerClient = class WorkerClient extends Client {\n // These two require() calls are in deferred so that they are not imported in\n // older Node.js versions (which don't support workers).\n // TODO: Hoist them in Babel 8.\n\n /** @type {typeof import(\"worker_threads\")} */\n static get #worker_threads() {\n return require(\"worker_threads\");\n }\n\n static get #markInRegisterWorker() {\n return require(\"./is-in-register-worker.js\").markInRegisterWorker;\n }\n\n #worker = new WorkerClient.#worker_threads.Worker(\n path.resolve(__dirname, \"./worker/index.js\"),\n { env: WorkerClient.#markInRegisterWorker(process.env) },\n );\n\n #signal = new Int32Array(new SharedArrayBuffer(4));\n\n constructor() {\n super((action, payload) => {\n this.#signal[0] = 0;\n const subChannel = new WorkerClient.#worker_threads.MessageChannel();\n\n this.#worker.postMessage(\n { signal: this.#signal, port: subChannel.port1, action, payload },\n [subChannel.port1],\n );\n\n Atomics.wait(this.#signal, 0, 0);\n const { message } = WorkerClient.#worker_threads.receiveMessageOnPort(\n subChannel.port2,\n );\n\n if (message.error) throw Object.assign(message.error, message.errorData);\n else return message.result;\n });\n\n // The worker will never exit by itself. Prevent it from keeping\n // the main process alive.\n this.#worker.unref();\n }\n};\n\nif (!process.env.BABEL_8_BREAKING) {\n exports.LocalClient = class LocalClient extends Client {\n isLocalClient = true;\n\n static #handleMessage;\n\n constructor() {\n LocalClient.#handleMessage ??= require(\"./worker/handle-message.js\");\n\n super((action, payload) => {\n return LocalClient.#handleMessage(\n action === ACTIONS.TRANSFORM ? ACTIONS.TRANSFORM_SYNC : action,\n payload,\n );\n });\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;AAAA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAM,CAAC;AAE5B,MAAMC,OAAO,GAAG;EACdC,sBAAsB,EAAE,wBAAwB;EAChDC,WAAW,EAAE,aAAa;EAC1BC,SAAS,EAAE,WAAW;EACtBC,cAAc,EAAE;AAClB,CAAC;AAAC,IAAAC,KAAA,OAAAC,OAAA;AAAA,IAAAC,OAAA,OAAAD,OAAA;AAEF,MAAME,MAAM,CAAC;EAGXC,WAAWA,CAACC,IAAI,EAAE;IAAAC,0BAAA,OAAAN,KAAA;MAAAO,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