39373e27628dfcfc79186be1030eb5e3731eba681e27db305d68544bee5ceb6d7ca22d7cde4e6022db2b2543f8d22c8e60cf1dac26b96f7e0dc12cad4d9c3f 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 = exports.default = (0, _helperPluginUtils.declare)((api, options) => {
  8. api.assertVersion("^7.0.0-0 || >8.0.0-alpha <8.0.0-beta");
  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 !== "2023-11" && version !== "2023-05" && version !== "2023-01" && version !== "2022-03" && 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" || version === "2022-03") {
  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" || version === "2022-03" || version === "2023-01") {
  40. throw new Error(`'decoratorsBeforeExport' can't be used with ${version} 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 === "2023-01" || version === "2023-05" || version === "2023-11") {
  56. parserOpts.plugins.push(["decorators", {
  57. allowCallParenthesized: false
  58. }], "decoratorAutoAccessors");
  59. } else if (version === "2022-03") {
  60. parserOpts.plugins.push(["decorators", {
  61. decoratorsBeforeExport: false,
  62. allowCallParenthesized: false
  63. }], "decoratorAutoAccessors");
  64. } else if (version === "2021-12") {
  65. parserOpts.plugins.push(["decorators", {
  66. decoratorsBeforeExport
  67. }], "decoratorAutoAccessors");
  68. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  69. } else if (version === "2018-09") {
  70. parserOpts.plugins.push(["decorators", {
  71. decoratorsBeforeExport
  72. }]);
  73. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  74. }
  75. }
  76. }
  77. };
  78. });
  79. //# sourceMappingURL=index.js.map