"use strict"; /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ Object.defineProperty(exports, "__esModule", { value: true }); const sass_1 = require("sass"); const worker_threads_1 = require("worker_threads"); if (!worker_threads_1.parentPort) { throw new Error('Sass worker must be executed as a Worker.'); } // The importer variables are used to proxy import requests to the main thread let { workerImporterPort, importerSignal } = (worker_threads_1.workerData || {}); worker_threads_1.parentPort.on('message', (message) => { // The init message is only needed to support Node.js < 12.17 and can be removed once support is dropped if (message.init) { workerImporterPort = message.workerImporterPort; importerSignal = message.importerSignal; return; } const { id, hasImporter, options } = message; try { if (hasImporter) { // When a custom importer function is present, the importer request must be proxied // back to the main thread where it can be executed. // This process must be synchronous from the perspective of dart-sass. The `Atomics` // functions combined with the shared memory `importSignal` and the Node.js // `receiveMessageOnPort` function are used to ensure synchronous behavior. options.importer = function (url, prev) { var _a; Atomics.store(importerSignal, 0, 0); // `this.fromImport` was added in dart-sass in 1.33.0, `@types/sass` doesn't include it yet. const { fromImport } = this; workerImporterPort.postMessage({ id, url, prev, fromImport }); Atomics.wait(importerSignal, 0, 0); return (_a = worker_threads_1.receiveMessageOnPort(workerImporterPort)) === null || _a === void 0 ? void 0 : _a.message; }; } // The synchronous Sass render function can be up to two times faster than the async variant const result = sass_1.renderSync(options); worker_threads_1.parentPort === null || worker_threads_1.parentPort === void 0 ? void 0 : worker_threads_1.parentPort.postMessage({ id, result }); } catch (error) { // Needed because V8 will only serialize the message and stack properties of an Error instance. const { formatted, file, line, column, message, stack } = error; worker_threads_1.parentPort === null || worker_threads_1.parentPort === void 0 ? void 0 : worker_threads_1.parentPort.postMessage({ id, error: { formatted, file, line, column, message, stack } }); } });