index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _helperPluginUtils = require("@babel/helper-plugin-utils");
  7. var _default = (0, _helperPluginUtils.declare)((api, options) => {
  8. api.assertVersion(7);
  9. let {
  10. version
  11. } = options;
  12. {
  13. const {
  14. legacy
  15. } = options;
  16. if (legacy !== undefined) {
  17. if (typeof legacy !== "boolean") {
  18. throw new Error(".legacy must be a boolean.");
  19. }
  20. if (version !== undefined) {
  21. throw new Error("You can either use the .legacy or the .version option, not both.");
  22. }
  23. }
  24. if (version === undefined) {
  25. version = legacy ? "legacy" : "2018-09";
  26. } else if (version !== "2021-12" && version !== "2018-09" && version !== "legacy") {
  27. throw new Error("Unsupported decorators version: " + version);
  28. }
  29. var {
  30. decoratorsBeforeExport
  31. } = options;
  32. if (decoratorsBeforeExport === undefined) {
  33. if (version === "2021-12") {
  34. decoratorsBeforeExport = false;
  35. } else if (version === "2018-09") {
  36. throw new Error("The decorators plugin, when .version is '2018-09' or not specified," + " requires a 'decoratorsBeforeExport' option, whose value must be a boolean.");
  37. }
  38. } else {
  39. if (version === "legacy") {
  40. throw new Error("'decoratorsBeforeExport' can't be used with legacy decorators.");
  41. }
  42. if (typeof decoratorsBeforeExport !== "boolean") {
  43. throw new Error("'decoratorsBeforeExport' must be a boolean.");
  44. }
  45. }
  46. }
  47. return {
  48. name: "syntax-decorators",
  49. manipulateOptions({
  50. generatorOpts
  51. }, parserOpts) {
  52. if (version === "legacy") {
  53. parserOpts.plugins.push("decorators-legacy");
  54. } else {
  55. if (version === "2021-12") {
  56. parserOpts.plugins.push(["decorators", {
  57. decoratorsBeforeExport
  58. }], "decoratorAutoAccessors");
  59. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  60. } else if (version === "2018-09") {
  61. parserOpts.plugins.push(["decorators", {
  62. decoratorsBeforeExport
  63. }]);
  64. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  65. }
  66. }
  67. }
  68. };
  69. });
  70. exports.default = _default;