"use strict";
var _vm = _interopRequireDefault(require("vm"));
var _index = require("./index");
var _options = require("./options");
function _interopRequireDefault(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
// Jest use the `vm` [Module API](https://nodejs.org/api/vm.html#vm_class_vm_module) for ESM.
// see https://github.com/facebook/jest/issues/9430
const isSupportEsm = "Module" in _vm.default;
function getJestConfig(jestConfig) {
    return "config" in jestConfig ? jestConfig.config : jestConfig;
}
function isEsm(isEsmProject, filename, jestConfig) {
    var ref;
    return /\.jsx?$/.test(filename) && isEsmProject || ((ref = jestConfig.extensionsToTreatAsEsm) == null ? void 0 : ref.some((ext)=>filename.endsWith(ext)));
}
const createTransformer = (inputOptions)=>{
    return {
        process (src, filename, jestOptions) {
            const jestConfig = getJestConfig(jestOptions);
            let swcTransformOpts = (0, _options).getJestSWCOptions({
                // When target is node it's similar to the server option set in SWC.
                isServer: jestConfig.testEnvironment ? jestConfig.testEnvironment === "node" : false,
                filename,
                jsConfig: inputOptions == null ? void 0 : inputOptions.jsConfig,
                resolvedBaseUrl: inputOptions == null ? void 0 : inputOptions.resolvedBaseUrl,
                pagesDir: inputOptions == null ? void 0 : inputOptions.pagesDir,
                hasServerComponents: inputOptions == null ? void 0 : inputOptions.hasServerComponents,
                modularizeImports: inputOptions == null ? void 0 : inputOptions.modularizeImports,
                swcPlugins: inputOptions == null ? void 0 : inputOptions.swcPlugins,
                compilerOptions: inputOptions == null ? void 0 : inputOptions.compilerOptions,
                esm: isSupportEsm && isEsm(Boolean(inputOptions == null ? void 0 : inputOptions.isEsmProject), filename, jestConfig)
            });
            return (0, _index).transformSync(src, {
                ...swcTransformOpts,
                filename
            });
        }
    };
};
module.exports = {
    createTransformer
};

//# sourceMappingURL=jest-transformer.js.map