index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. targets: () => () => {
  12. return {};
  13. },
  14. assumption: () => () => {
  15. return undefined;
  16. }
  17. };
  18. function declare(builder) {
  19. return (api, options, dirname) => {
  20. var _clonedApi2;
  21. let clonedApi;
  22. for (const name of Object.keys(apiPolyfills)) {
  23. var _clonedApi;
  24. if (api[name]) continue;
  25. clonedApi = (_clonedApi = clonedApi) != null ? _clonedApi : copyApiObject(api);
  26. clonedApi[name] = apiPolyfills[name](clonedApi);
  27. }
  28. return builder((_clonedApi2 = clonedApi) != null ? _clonedApi2 : api, options || {}, dirname);
  29. };
  30. }
  31. const declarePreset = declare;
  32. exports.declarePreset = declarePreset;
  33. function copyApiObject(api) {
  34. let proto = null;
  35. if (typeof api.version === "string" && /^7\./.test(api.version)) {
  36. proto = Object.getPrototypeOf(api);
  37. if (proto && (!has(proto, "version") || !has(proto, "transform") || !has(proto, "template") || !has(proto, "types"))) {
  38. proto = null;
  39. }
  40. }
  41. return Object.assign({}, proto, api);
  42. }
  43. function has(obj, key) {
  44. return Object.prototype.hasOwnProperty.call(obj, key);
  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