UNPKG

@tapcart/app-studio-utils

Version:

A utility library for Tapcart's App Studio

28 lines 1.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.transpileCode = void 0; const sucrase_1 = require("sucrase"); const trimCode = (code) => code.trim().replace(/;$/, ""); const firstPassTransforms = ["jsx", "typescript", "imports"]; const defaultTransforms = []; const compose = (...functions) => { return functions.reduce((acc, currentFn) => (...args) => acc(currentFn(...args))); }; const _transform = (opts = {}) => { const transforms = Array.isArray(opts.transforms) ? opts.transforms.filter(Boolean) : defaultTransforms; return (code) => { return (0, sucrase_1.transform)(code, { transforms }).code; }; }; const transpileCode = (code) => { const transformedCode = compose(trimCode, _transform({ transforms: firstPassTransforms, jsxRuntime: "automatic", production: true, }), trimCode)(code); return transformedCode; }; exports.transpileCode = transpileCode; //# sourceMappingURL=transpile.js.map