cjs-proxy.cjs 1.3 KB

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