index.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 = require("@babel/plugin-syntax-decorators");
  8. var _helperCreateClassFeaturesPlugin = require("@babel/helper-create-class-features-plugin");
  9. var _transformerLegacy = require("./transformer-legacy");
  10. var _default = (0, _helperPluginUtils.declare)((api, options) => {
  11. api.assertVersion(7);
  12. const {
  13. legacy = false
  14. } = options;
  15. if (typeof legacy !== "boolean") {
  16. throw new Error("'legacy' must be a boolean.");
  17. }
  18. const {
  19. decoratorsBeforeExport
  20. } = options;
  21. if (decoratorsBeforeExport === undefined) {
  22. if (!legacy) {
  23. 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.");
  24. }
  25. } else {
  26. if (legacy) {
  27. throw new Error("'decoratorsBeforeExport' can't be used with legacy decorators.");
  28. }
  29. if (typeof decoratorsBeforeExport !== "boolean") {
  30. throw new Error("'decoratorsBeforeExport' must be a boolean.");
  31. }
  32. }
  33. if (legacy) {
  34. return {
  35. name: "proposal-decorators",
  36. inherits: _pluginSyntaxDecorators.default,
  37. manipulateOptions({
  38. generatorOpts
  39. }) {
  40. generatorOpts.decoratorsBeforeExport = decoratorsBeforeExport;
  41. },
  42. visitor: _transformerLegacy.default
  43. };
  44. }
  45. return (0, _helperCreateClassFeaturesPlugin.createClassFeaturePlugin)({
  46. name: "proposal-decorators",
  47. api,
  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;