You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.9 KiB

4 years ago
  1. "use strict";
  2. function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
  3. function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
  4. const babel = require("@babel/core");
  5. const promisify = require("pify");
  6. const LoaderError = require("./Error");
  7. const transform = promisify(babel.transform);
  8. module.exports =
  9. /*#__PURE__*/
  10. function () {
  11. var _ref = _asyncToGenerator(function* (source, options) {
  12. let result;
  13. try {
  14. result = yield transform(source, options);
  15. } catch (err) {
  16. throw err.message && err.codeFrame ? new LoaderError(err) : err;
  17. }
  18. if (!result) return null; // We don't return the full result here because some entries are not
  19. // really serializable. For a full list of properties see here:
  20. // https://github.com/babel/babel/blob/master/packages/babel-core/src/transformation/index.js
  21. // For discussion on this topic see here:
  22. // https://github.com/babel/babel-loader/pull/629
  23. const {
  24. ast,
  25. code,
  26. map,
  27. metadata,
  28. sourceType
  29. } = result;
  30. if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
  31. map.sourcesContent = [source];
  32. }
  33. return {
  34. ast,
  35. code,
  36. map,
  37. metadata,
  38. sourceType
  39. };
  40. });
  41. return function (_x, _x2) {
  42. return _ref.apply(this, arguments);
  43. };
  44. }();
  45. module.exports.version = babel.version;