index.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function _helperPluginUtils() {
  7. const data = require("@babel/helper-plugin-utils");
  8. _helperPluginUtils = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _pluginSyntaxDecorators() {
  14. const data = _interopRequireDefault(require("@babel/plugin-syntax-decorators"));
  15. _pluginSyntaxDecorators = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. function _helperCreateClassFeaturesPlugin() {
  21. const data = require("@babel/helper-create-class-features-plugin");
  22. _helperCreateClassFeaturesPlugin = function () {
  23. return data;
  24. };
  25. return data;
  26. }
  27. var _transformerLegacy = _interopRequireDefault(require("./transformer-legacy"));
  28. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  29. var _default = (0, _helperPluginUtils().declare)((api, options) => {
  30. api.assertVersion(7);
  31. const {
  32. legacy = false
  33. } = options;
  34. if (typeof legacy !== "boolean") {
  35. throw new Error("'legacy' must be a boolean.");
  36. }
  37. const {
  38. decoratorsBeforeExport
  39. } = options;
  40. if (decoratorsBeforeExport === undefined) {
  41. if (!legacy) {
  42. throw new Error("The decorators plugin requires a 'decoratorsBeforeExport' option," + " whose value must be a boolean. If you want to use the legacy" + " decorators semantics, you can set the 'legacy: true' option.");
  43. }
  44. } else {
  45. if (legacy) {
  46. throw new Error("'decoratorsBeforeExport' can't be used with legacy decorators.");
  47. }
  48. if (typeof decoratorsBeforeExport !== "boolean") {
  49. throw new Error("'decoratorsBeforeExport' must be a boolean.");
  50. }
  51. }
  52. if (legacy) {
  53. return {
  54. name: "proposal-decorators",
  55. inherits: _pluginSyntaxDecorators().default,
  56. manipulateOptions({
  57. generatorOpts
  58. }) {
  59. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  60. },
  61. visitor: _transformerLegacy.default
  62. };
  63. }
  64. return (0, _helperCreateClassFeaturesPlugin().createClassFeaturePlugin)({
  65. name: "proposal-decorators",
  66. feature: _helperCreateClassFeaturesPlugin().FEATURES.decorators,
  67. manipulateOptions({
  68. generatorOpts,
  69. parserOpts
  70. }) {
  71. parserOpts.plugins.push(["decorators", {
  72. decoratorsBeforeExport
  73. }]);
  74. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  75. }
  76. });
  77. });
  78. exports.default = _default;