index.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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-0 || >8.0.0-alpha <8.0.0-beta");
  9. let {
  10. version
  11. } = options;
  12. const {
  13. legacy
  14. } = options;
  15. if (legacy !== undefined) {
  16. if (typeof legacy !== "boolean") {
  17. throw new Error(".legacy must be a boolean.");
  18. }
  19. if (version !== undefined) {
  20. throw new Error("You can either use the .legacy or the .version option, not both.");
  21. }
  22. }
  23. if (version === undefined) {
  24. version = legacy ? "legacy" : "2018-09";
  25. } else if (version !== "2023-11" && version !== "2023-05" && version !== "2023-01" && version !== "2022-03" && version !== "2021-12" && version !== "2018-09" && version !== "legacy") {
  26. throw new Error("Unsupported decorators version: " + version);
  27. }
  28. var {
  29. decoratorsBeforeExport
  30. } = options;
  31. if (decoratorsBeforeExport === undefined) {
  32. if (version === "2021-12" || version === "2022-03") {
  33. decoratorsBeforeExport = false;
  34. } else if (version === "2018-09") {
  35. throw new Error("The decorators plugin, when .version is '2018-09' or not specified," + " requires a 'decoratorsBeforeExport' option, whose value must be a boolean.");
  36. }
  37. } else {
  38. if (version === "legacy" || version === "2022-03" || version === "2023-01") {
  39. throw new Error(`'decoratorsBeforeExport' can't be used with ${version} decorators.`);
  40. }
  41. if (typeof decoratorsBeforeExport !== "boolean") {
  42. throw new Error("'decoratorsBeforeExport' must be a boolean.");
  43. }
  44. }
  45. return {
  46. name: "syntax-decorators",
  47. manipulateOptions({
  48. generatorOpts
  49. }, parserOpts) {
  50. if (version === "legacy") {
  51. parserOpts.plugins.push("decorators-legacy");
  52. } else {
  53. if (version === "2023-01" || version === "2023-05" || version === "2023-11") {
  54. parserOpts.plugins.push(["decorators", {
  55. allowCallParenthesized: false
  56. }], "decoratorAutoAccessors");
  57. } else if (version === "2022-03") {
  58. parserOpts.plugins.push(["decorators", {
  59. decoratorsBeforeExport: false,
  60. allowCallParenthesized: false
  61. }], "decoratorAutoAccessors");
  62. } else if (version === "2021-12") {
  63. parserOpts.plugins.push(["decorators", {
  64. decoratorsBeforeExport
  65. }], "decoratorAutoAccessors");
  66. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  67. } else if (version === "2018-09") {
  68. parserOpts.plugins.push(["decorators", {
  69. decoratorsBeforeExport
  70. }]);
  71. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  72. }
  73. }
  74. }
  75. };
  76. });
  77. //# sourceMappingURL=index.js.map