cjs-proxy.cjs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. babelP.then(babel => {
  29. babel[name](...args);
  30. });
  31. };
  32. exports[`${name}Async`] = function (...args) {
  33. return babelP.then(babel => babel[`${name}Async`](...args));
  34. };
  35. exports[`${name}Sync`] = function (...args) {
  36. if (!babel) throw notLoadedError(`${name}Sync`, "callable");
  37. return babel[`${name}Sync`](...args);
  38. };
  39. }
  40. for (const name of propertyNames) {
  41. Object.defineProperty(exports, name, {
  42. get() {
  43. if (!babel) throw notLoadedError(name, "accessible");
  44. return babel[name];
  45. },
  46. });
  47. }
  48. function notLoadedError(name, keyword) {
  49. return new Error(
  50. `The \`${name}\` export of @babel/core is only ${keyword}` +
  51. ` from the CommonJS version after that the ESM version is loaded.`
  52. );
  53. }