const { createTransformer } = require("babel-jest");

const { prevalReplace } = require("../utils/prevalReplace");

const babelTransformer = createTransformer();

module.exports = {
  ...babelTransformer,
  getCacheKey(sourceText, sourcePath, options) {
    const replaced = prevalReplace(sourceText);
    const code = replaced ?? sourceText;

    return babelTransformer.getCacheKey(code, sourcePath, options);
  },
  process(sourceText, sourcePath, options) {
    const replaced = prevalReplace(sourceText);
    const code = replaced ?? sourceText;

    return babelTransformer.process(code, sourcePath, options);
  },
  processAsync(sourceText, sourcePath, options) {
    const replaced = prevalReplace(sourceText);
    const code = replaced ?? sourceText;

    return babelTransformer.processAsync(code, sourcePath, options);
  },
  getCacheKeyAsync(sourceText, sourcePath, options) {
    const replaced = prevalReplace(sourceText);
    const code = replaced ?? sourceText;

    return babelTransformer.getCacheKeyAsync(code, sourcePath, options);
  },
};
