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