cjs-proxy.cjs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. const functionNames = [
  10. "createConfigItem",
  11. "loadPartialConfig",
  12. "loadOptions",
  13. "transform",
  14. "transformFile",
  15. "transformFromAst",
  16. "parse",
  17. ];
  18. const propertyNames = ["types", "tokTypes", "traverse", "template", "version"];
  19. for (const name of functionNames) {
  20. exports[name] = function (...args) {
  21. babelP.then(babel => {
  22. babel[name](...args);
  23. });
  24. };
  25. exports[`${name}Async`] = function (...args) {
  26. return babelP.then(babel => babel[`${name}Async`](...args));
  27. };
  28. exports[`${name}Sync`] = function (...args) {
  29. if (!babel) throw notLoadedError(`${name}Sync`, "callable");
  30. return babel[`${name}Sync`](...args);
  31. };
  32. }
  33. for (const name of propertyNames) {
  34. Object.defineProperty(exports, name, {
  35. get() {
  36. if (!babel) throw notLoadedError(name, "accessible");
  37. return babel[name];
  38. },
  39. });
  40. }
  41. function notLoadedError(name, keyword) {
  42. return new Error(
  43. `The \`${name}\` export of @babel/core is only ${keyword}` +
  44. ` from the CommonJS version after that the ESM version is loaded.`
  45. );
  46. }