{"version":3,"names":["path","require","ACTIONS","GET_VERSION","GET_TYPES_INFO","GET_VISITOR_KEYS","GET_TOKEN_LABELS","MAYBE_PARSE","MAYBE_PARSE_SYNC","Client","constructor","send","getVersion","undefined","getTypesInfo","getVisitorKeys","getTokLabels","maybeParse","code","options","exports","WorkerClient","action","payload","signal","Int32Array","SharedArrayBuffer","subChannel","MessageChannel","postMessage","port","port1","Atomics","wait","message","receiveMessageOnPort","port2","error","Object","assign","errorData","result","Worker","resolve","__dirname","env","SHARE_ENV","unref","LocalClient"],"sources":["../src/client.cjs"],"sourcesContent":["const path = require(\"path\");\n\nconst ACTIONS = {\n GET_VERSION: \"GET_VERSION\",\n GET_TYPES_INFO: \"GET_TYPES_INFO\",\n GET_VISITOR_KEYS: \"GET_VISITOR_KEYS\",\n GET_TOKEN_LABELS: \"GET_TOKEN_LABELS\",\n MAYBE_PARSE: \"MAYBE_PARSE\",\n MAYBE_PARSE_SYNC: \"MAYBE_PARSE_SYNC\",\n};\n\nclass Client {\n #send;\n\n constructor(send) {\n this.#send = send;\n }\n\n #vCache;\n getVersion() {\n return (this.#vCache ??= this.#send(ACTIONS.GET_VERSION, undefined));\n }\n\n #tiCache;\n getTypesInfo() {\n return (this.#tiCache ??= this.#send(ACTIONS.GET_TYPES_INFO, undefined));\n }\n\n #vkCache;\n getVisitorKeys() {\n return (this.#vkCache ??= this.#send(ACTIONS.GET_VISITOR_KEYS, undefined));\n }\n\n #tlCache;\n getTokLabels() {\n return (this.#tlCache ??= this.#send(ACTIONS.GET_TOKEN_LABELS, undefined));\n }\n\n maybeParse(code, options) {\n return this.#send(ACTIONS.MAYBE_PARSE, { code, options });\n }\n}\n\n// We need to run Babel in a worker for two reasons:\n// 1. ESLint workers must be CJS files, and this is a problem\n// since Babel 8+ uses native ESM\n// 2. ESLint parsers must run synchronously, but many steps\n// of Babel's config loading (which is done for each file)\n// can be asynchronous\n// If ESLint starts supporting async parsers, we can move\n// everything back to the main thread.\nexports.WorkerClient = class WorkerClient extends Client {\n static #worker_threads_cache;\n static get #worker_threads() {\n return (WorkerClient.#worker_threads_cache ??= require(\"worker_threads\"));\n }\n\n #worker = new WorkerClient.#worker_threads.Worker(\n path.resolve(__dirname, \"../lib/worker/index.cjs\"),\n { env: WorkerClient.#worker_threads.SHARE_ENV },\n );\n\n constructor() {\n super((action, payload) => {\n // We create a new SharedArrayBuffer every time rather than reusing\n // the same one, otherwise sometimes its contents get corrupted and\n // Atomics.wait wakes up too early.\n // https://github.com/babel/babel/pull/14541\n const signal = new Int32Array(new SharedArrayBuffer(8));\n\n const subChannel = new WorkerClient.#worker_threads.MessageChannel();\n\n this.#worker.postMessage(\n { signal, port: subChannel.port1, action, payload },\n [subChannel.port1],\n );\n\n Atomics.wait(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 (!USE_ESM) {\n exports.LocalClient = class LocalClient extends Client {\n static #handleMessage;\n\n constructor() {\n LocalClient.#handleMessage ??= require(\"./worker/handle-message.cjs\");\n\n super((action, payload) => {\n return LocalClient.#handleMessage(\n action === ACTIONS.MAYBE_PARSE ? ACTIONS.MAYBE_PARSE_SYNC : action,\n payload,\n );\n });\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAMA,IAAI,GAAGC,OAAO,CAAC,MAAD,CAApB;;AAEA,MAAMC,OAAO,GAAG;EACdC,WAAW,EAAE,aADC;EAEdC,cAAc,EAAE,gBAFF;EAGdC,gBAAgB,EAAE,kBAHJ;EAIdC,gBAAgB,EAAE,kBAJJ;EAKdC,WAAW,EAAE,aALC;EAMdC,gBAAgB,EAAE;AANJ,CAAhB;;;;;;;;;;;;AASA,MAAMC,MAAN,CAAa;EAGXC,WAAW,CAACC,IAAD,EAAO;IAAA;MAAA;MAAA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