"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BabelTransform = void 0;
const core_1 = require("@babel/core");
function BabelTransform(code, options = {}) {
    var _a;
    const { IIFE = false } = options;
    try {
        const simpleWrapped = `(\n${code || 'undefined'}\n)`;
        const { code: expression } = (0, core_1.transformSync)(IIFE ? `(()=>${simpleWrapped})()` : simpleWrapped, {
            // plugins: ['transform-modules-commonjs', 'transform-react-jsx'],
            cwd: __dirname,
            sourceType: 'script',
            comments: false,
            // minified: true,
            presets: [
                [
                    '@babel/preset-env',
                    {
                        targets: {
                            // esmodules: true,
                            browsers: ['defaults', 'iOS >= 10', 'safari >= 10'],
                        },
                    },
                ],
            ],
        }) || {};
        return ((_a = expression === null || expression === void 0 ? void 0 : expression.replace) === null || _a === void 0 ? void 0 : _a.call(expression, /;$/, '')) || code;
    }
    catch (e) {
        console.error(`transform [${code}] fail:`, e === null || e === void 0 ? void 0 : e.message);
        return code;
    }
}
exports.BabelTransform = BabelTransform;
