index.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.declare = declare;
  6. exports.declarePreset = void 0;
  7. const apiPolyfills = {
  8. assertVersion: api => range => {
  9. throwVersionError(range, api.version);
  10. }
  11. };
  12. {
  13. Object.assign(apiPolyfills, {
  14. targets: () => () => {
  15. return {};
  16. },
  17. assumption: () => () => {
  18. return undefined;
  19. }
  20. });
  21. }
  22. function declare(builder) {
  23. return (api, options, dirname) => {
  24. var _clonedApi2;
  25. let clonedApi;
  26. for (const name of Object.keys(apiPolyfills)) {
  27. var _clonedApi;
  28. if (api[name]) continue;
  29. (_clonedApi = clonedApi) != null ? _clonedApi : clonedApi = copyApiObject(api);
  30. clonedApi[name] = apiPolyfills[name](clonedApi);
  31. }
  32. return builder((_clonedApi2 = clonedApi) != null ? _clonedApi2 : api, options || {}, dirname);
  33. };
  34. }
  35. const declarePreset = exports.declarePreset = declare;
  36. function copyApiObject(api) {
  37. let proto = null;
  38. if (typeof api.version === "string" && /^7\./.test(api.version)) {
  39. proto = Object.getPrototypeOf(api);
  40. if (proto && (!hasOwnProperty.call(proto, "version") || !hasOwnProperty.call(proto, "transform") || !hasOwnProperty.call(proto, "template") || !hasOwnProperty.call(proto, "types"))) {
  41. proto = null;
  42. }
  43. }
  44. return Object.assign({}, proto, api);
  45. }
  46. function throwVersionError(range, version) {
  47. if (typeof range === "number") {
  48. if (!Number.isInteger(range)) {
  49. throw new Error("Expected string or integer value.");
  50. }
  51. range = `^${range}.0.0-0`;
  52. }
  53. if (typeof range !== "string") {
  54. throw new Error("Expected string or integer value.");
  55. }
  56. const limit = Error.stackTraceLimit;
  57. if (typeof limit === "number" && limit < 25) {
  58. Error.stackTraceLimit = 25;
  59. }
  60. let err;
  61. if (version.slice(0, 2) === "7.") {
  62. err = new Error(`Requires Babel "^7.0.0-beta.41", but was loaded with "${version}". ` + `You'll need to update your @babel/core version.`);
  63. } else {
  64. err = new Error(`Requires Babel "${range}", but was loaded with "${version}". ` + `If you are sure you have a compatible version of @babel/core, ` + `it is likely that something in your build process is loading the ` + `wrong version. Inspect the stack trace of this error to look for ` + `the first entry that doesn't mention "@babel/core" or "babel-core" ` + `to see what is calling Babel.`);
  65. }
  66. if (typeof limit === "number") {
  67. Error.stackTraceLimit = limit;
  68. }
  69. throw Object.assign(err, {
  70. code: "BABEL_VERSION_UNSUPPORTED",
  71. version,
  72. range
  73. });
  74. }
  75. //# sourceMappingURL=index.js.map