import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import * as Babel from '@babel/core';
export var compileModule = function compileModule(code) {
  var globals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  var exports = {};
  var module = {
    exports: exports
  };
  var globalNames = Object.keys(globals);
  var keys = ['module', 'exports'].concat(_toConsumableArray(globalNames));
  var values = [module, exports].concat(_toConsumableArray(globalNames.map(function (key) {
    return globals[key];
  }))); // eslint-disable-next-line no-new-func

  new Function(keys.join(), code).apply(exports, values);
  return module.exports;
};
export var transpilePlugin = function transpilePlugin(pluginString) {
  return Babel.transform(pluginString, {
    babelrc: false,
    configFile: false,
    ast: false,
    highlightCode: false,
    presets: [require('@babel/preset-env')]
  }).code;
}; // export default () => {
//   // 直接使用babel生成Module
//   const FUNCTION2 = `function sumFunction(babel) {
//     const a = 1;
//     const b= 2;
//     return a+b;
//   }
//   const data = {
//     name:'1',
//     age:12
//   }
//   function sumFunction2(x, y) {
//     return x+y+data.age;
//   }
//   export {sumFunction, data, sumFunction2};
//   `;
//   const selfModule = compileModule(transpilePlugin(FUNCTION2));
//   const { sumFunction, sumFunction2, data } = selfModule;
//   return (
//     <div>
//       <br />
//       {sumFunction()}
//       <br />
//       {sumFunction2(2, 4)}
//     </div>
//   );
// };
//# sourceMappingURL=transformJS.js.map