cjs-proxy.cjs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. "use strict";
  2. const babelP = import("./lib/index.js");
  3. let babel = null;
  4. Object.defineProperty(exports, "__ initialize @babel/core cjs proxy __", {
  5. set(val) {
  6. babel = val;
  7. },
  8. });
  9. exports.version = require("./package.json").version;
  10. const functionNames = [
  11. "createConfigItem",
  12. "loadPartialConfig",
  13. "loadOptions",
  14. "transform",
  15. "transformFile",
  16. "transformFromAst",
  17. "parse",
  18. ];
  19. const propertyNames = [
  20. "buildExternalHelpers",
  21. "types",
  22. "tokTypes",
  23. "traverse",
  24. "template",
  25. ];
  26. for (const name of functionNames) {
  27. exports[name] = function (...args) {
  28. if (
  29. process.env.BABEL_8_BREAKING &&
  30. typeof args[args.length - 1] !== "function"
  31. ) {
  32. throw new Error(
  33. `Starting from Babel 8.0.0, the '${name}' function expects a callback. If you need to call it synchronously, please use '${name}Sync'.`
  34. );
  35. }
  36. babelP.then(babel => {
  37. babel[name](...args);
  38. });
  39. };
  40. exports[`${name}Async`] = function (...args) {
  41. return babelP.then(babel => babel[`${name}Async`](...args));
  42. };
  43. exports[`${name}Sync`] = function (...args) {
  44. if (!babel) throw notLoadedError(`${name}Sync`, "callable");
  45. return babel[`${name}Sync`](...args);
  46. };
  47. }
  48. for (const name of propertyNames) {
  49. Object.defineProperty(exports, name, {
  50. get() {
  51. if (!babel) throw notLoadedError(name, "accessible");
  52. return babel[name];
  53. },
  54. });
  55. }
  56. function notLoadedError(name, keyword) {
  57. return new Error(
  58. `The \`${name}\` export of @babel/core is only ${keyword}` +
  59. ` from the CommonJS version after that the ESM version is loaded.`
  60. );
  61. }