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