index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 _pluginSyntaxDecorators = _interopRequireDefault(require("@babel/plugin-syntax-decorators"));
  8. var _helperCreateClassFeaturesPlugin = require("@babel/helper-create-class-features-plugin");
  9. var _transformerLegacy = _interopRequireDefault(require("./transformer-legacy"));
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. var _default = (0, _helperPluginUtils.declare)((api, options) => {
  12. api.assertVersion(7);
  13. const {
  14. legacy = false
  15. } = options;
  16. if (typeof legacy !== "boolean") {
  17. throw new Error("'legacy' must be a boolean.");
  18. }
  19. const {
  20. decoratorsBeforeExport
  21. } = options;
  22. if (decoratorsBeforeExport === undefined) {
  23. if (!legacy) {
  24. 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.");
  25. }
  26. } else {
  27. if (legacy) {
  28. throw new Error("'decoratorsBeforeExport' can't be used with legacy decorators.");
  29. }
  30. if (typeof decoratorsBeforeExport !== "boolean") {
  31. throw new Error("'decoratorsBeforeExport' must be a boolean.");
  32. }
  33. }
  34. if (legacy) {
  35. return {
  36. name: "proposal-decorators",
  37. inherits: _pluginSyntaxDecorators.default,
  38. manipulateOptions({
  39. generatorOpts
  40. }) {
  41. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  42. },
  43. visitor: _transformerLegacy.default
  44. };
  45. }
  46. return (0, _helperCreateClassFeaturesPlugin.createClassFeaturePlugin)({
  47. name: "proposal-decorators",
  48. feature: _helperCreateClassFeaturesPlugin.FEATURES.decorators,
  49. manipulateOptions({
  50. generatorOpts,
  51. parserOpts
  52. }) {
  53. parserOpts.plugins.push(["decorators", {
  54. decoratorsBeforeExport
  55. }]);
  56. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  57. }
  58. });
  59. });
  60. exports.default = _default;