index.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 !== "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") {
  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 === "2022-03") {
  56. parserOpts.plugins.push(["decorators", {
  57. decoratorsBeforeExport: false,
  58. allowCallParenthesized: false
  59. }], "decoratorAutoAccessors");
  60. } else if (version === "2021-12") {
  61. parserOpts.plugins.push(["decorators", {
  62. decoratorsBeforeExport
  63. }], "decoratorAutoAccessors");
  64. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  65. } else if (version === "2018-09") {
  66. parserOpts.plugins.push(["decorators", {
  67. decoratorsBeforeExport
  68. }]);
  69. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  70. }
  71. }
  72. }
  73. };
  74. });
  75. exports.default = _default;
  76. //# sourceMappingURL=index.js.map