[6a3a178] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | 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); } }
|
---|
| 4 |
|
---|
| 5 | 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); }); }; }
|
---|
| 6 |
|
---|
| 7 | const babel = require("@babel/core");
|
---|
| 8 |
|
---|
| 9 | const {
|
---|
| 10 | promisify
|
---|
| 11 | } = require("util");
|
---|
| 12 |
|
---|
| 13 | const LoaderError = require("./Error");
|
---|
| 14 |
|
---|
| 15 | const transform = promisify(babel.transform);
|
---|
| 16 |
|
---|
| 17 | module.exports = /*#__PURE__*/function () {
|
---|
| 18 | var _ref = _asyncToGenerator(function* (source, options) {
|
---|
| 19 | let result;
|
---|
| 20 |
|
---|
| 21 | try {
|
---|
| 22 | result = yield transform(source, options);
|
---|
| 23 | } catch (err) {
|
---|
| 24 | throw err.message && err.codeFrame ? new LoaderError(err) : err;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | if (!result) return null; // We don't return the full result here because some entries are not
|
---|
| 28 | // really serializable. For a full list of properties see here:
|
---|
| 29 | // https://github.com/babel/babel/blob/main/packages/babel-core/src/transformation/index.js
|
---|
| 30 | // For discussion on this topic see here:
|
---|
| 31 | // https://github.com/babel/babel-loader/pull/629
|
---|
| 32 |
|
---|
| 33 | const {
|
---|
| 34 | ast,
|
---|
| 35 | code,
|
---|
| 36 | map,
|
---|
| 37 | metadata,
|
---|
| 38 | sourceType
|
---|
| 39 | } = result;
|
---|
| 40 |
|
---|
| 41 | if (map && (!map.sourcesContent || !map.sourcesContent.length)) {
|
---|
| 42 | map.sourcesContent = [source];
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | return {
|
---|
| 46 | ast,
|
---|
| 47 | code,
|
---|
| 48 | map,
|
---|
| 49 | metadata,
|
---|
| 50 | sourceType
|
---|
| 51 | };
|
---|
| 52 | });
|
---|
| 53 |
|
---|
| 54 | return function (_x, _x2) {
|
---|
| 55 | return _ref.apply(this, arguments);
|
---|
| 56 | };
|
---|
| 57 | }();
|
---|
| 58 |
|
---|
| 59 | module.exports.version = babel.version; |
---|