fba171dfc2afe6a39a21f85bff66ab09672a6cb1e87ffb59341d5336b6e9a1bd3f5e377d0e6c307ff2d66a45564eb79814dc0fd7371a240c5b279265c919ce 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = generateCode;
  6. function _convertSourceMap() {
  7. const data = require("convert-source-map");
  8. _convertSourceMap = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _generator() {
  14. const data = require("@babel/generator");
  15. _generator = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. var _mergeMap = require("./merge-map.js");
  21. function generateCode(pluginPasses, file) {
  22. const {
  23. opts,
  24. ast,
  25. code,
  26. inputMap
  27. } = file;
  28. const {
  29. generatorOpts
  30. } = opts;
  31. generatorOpts.inputSourceMap = inputMap == null ? void 0 : inputMap.toObject();
  32. const results = [];
  33. for (const plugins of pluginPasses) {
  34. for (const plugin of plugins) {
  35. const {
  36. generatorOverride
  37. } = plugin;
  38. if (generatorOverride) {
  39. const result = generatorOverride(ast, generatorOpts, code, _generator().default);
  40. if (result !== undefined) results.push(result);
  41. }
  42. }
  43. }
  44. let result;
  45. if (results.length === 0) {
  46. result = (0, _generator().default)(ast, generatorOpts, code);
  47. } else if (results.length === 1) {
  48. result = results[0];
  49. if (typeof result.then === "function") {
  50. throw new Error(`You appear to be using an async codegen plugin, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, ` + `you may need to upgrade your @babel/core version.`);
  51. }
  52. } else {
  53. throw new Error("More than one plugin attempted to override codegen.");
  54. }
  55. let {
  56. code: outputCode,
  57. decodedMap: outputMap = result.map
  58. } = result;
  59. if (result.__mergedMap) {
  60. outputMap = Object.assign({}, result.map);
  61. } else {
  62. if (outputMap) {
  63. if (inputMap) {
  64. outputMap = (0, _mergeMap.default)(inputMap.toObject(), outputMap, generatorOpts.sourceFileName);
  65. } else {
  66. outputMap = result.map;
  67. }
  68. }
  69. }
  70. if (opts.sourceMaps === "inline" || opts.sourceMaps === "both") {
  71. outputCode += "\n" + _convertSourceMap().fromObject(outputMap).toComment();
  72. }
  73. if (opts.sourceMaps === "inline") {
  74. outputMap = null;
  75. }
  76. return {
  77. outputCode,
  78. outputMap
  79. };
  80. }
  81. 0 && 0;
  82. //# sourceMappingURL=generate.js.map