All files / src/swc loadSwc.ts

61.11% Statements 11/18
75% Branches 3/4
50% Functions 2/4
60% Lines 9/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 263x     3x 3x   3x 78x 3x                     3x   3x   78x    
import { isBrowserOrWorkerEnvironment } from "../utils/browser";
import type * as swcTypes from "@swc/wasm-web";
 
let initialized = false;
let swcInstance: any = null;
 
export const getSwc = async (): Promise<typeof swcTypes> => {
  if (!initialized) {
    Iif (isBrowserOrWorkerEnvironment()) {
      // Use WASM version for browser/worker environments
      const swc = await import("@swc/wasm-web");
      const { default: initSwc } = swc;
      //@ts-ignore
      const wasmModule = (await import("@swc/wasm-web/wasm_bg.wasm")).default;
      const wasm = await wasmModule();
      await initSwc({ module_or_path: wasm });
      swcInstance = swc;
    } else {
      // Use native version for Node.js environments
      swcInstance = await import("@swc/core");
    }
    initialized = true;
  }
  return swcInstance;
};