index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 = declare;
  36. exports.declarePreset = declarePreset;
  37. function copyApiObject(api) {
  38. let proto = null;
  39. if (typeof api.version === "string" && /^7\./.test(api.version)) {
  40. proto = Object.getPrototypeOf(api);
  41. if (proto && (!has(proto, "version") || !has(proto, "transform") || !has(proto, "template") || !has(proto, "types"))) {
  42. proto = null;
  43. }
  44. }
  45. return Object.assign({}, proto, api);
  46. }
  47. function has(obj, key) {
  48. return Object.prototype.hasOwnProperty.call(obj, key);
  49. }
  50. function throwVersionError(range, version) {
  51. if (typeof range === "number") {
  52. if (!Number.isInteger(range)) {
  53. throw new Error("Expected string or integer value.");
  54. }
  55. range = `^${range}.0.0-0`;
  56. }
  57. if (typeof range !== "string") {
  58. throw new Error("Expected string or integer value.");
  59. }
  60. const limit = Error.stackTraceLimit;
  61. if (typeof limit === "number" && limit < 25) {
  62. Error.stackTraceLimit = 25;
  63. }
  64. let err;
  65. if (version.slice(0, 2) === "7.") {
  66. err = new Error(`Requires Babel "^7.0.0-beta.41", but was loaded with "${version}". ` + `You'll need to update your @babel/core version.`);
  67. } else {
  68. 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.`);
  69. }
  70. if (typeof limit === "number") {
  71. Error.stackTraceLimit = limit;
  72. }
  73. throw Object.assign(err, {
  74. code: "BABEL_VERSION_UNSUPPORTED",
  75. version,
  76. range
  77. });
  78. }
  79. //# sourceMappingURL=index.js.map