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 _core = require("@babel/core");
|
11 |
|
12 | var _default = (0, _helperPluginUtils.declare)(api => {
|
13 | api.assertVersion(7);
|
14 | return {
|
15 | name: "transform-shorthand-properties",
|
16 | visitor: {
|
17 | ObjectMethod(path) {
|
18 | const {
|
19 | node
|
20 | } = path;
|
21 |
|
22 | if (node.kind === "method") {
|
23 | const func = _core.types.functionExpression(null, node.params, node.body, node.generator, node.async);
|
24 |
|
25 | func.returnType = node.returnType;
|
26 |
|
27 | const computedKey = _core.types.toComputedKey(node);
|
28 |
|
29 | if (_core.types.isStringLiteral(computedKey, {
|
30 | value: "__proto__"
|
31 | })) {
|
32 | path.replaceWith(_core.types.objectProperty(computedKey, func, true));
|
33 | } else {
|
34 | path.replaceWith(_core.types.objectProperty(node.key, func, node.computed));
|
35 | }
|
36 | }
|
37 | },
|
38 |
|
39 | ObjectProperty(path) {
|
40 | const {
|
41 | node
|
42 | } = path;
|
43 |
|
44 | if (node.shorthand) {
|
45 | const computedKey = _core.types.toComputedKey(node);
|
46 |
|
47 | if (_core.types.isStringLiteral(computedKey, {
|
48 | value: "__proto__"
|
49 | })) {
|
50 | path.replaceWith(_core.types.objectProperty(computedKey, node.value, true));
|
51 | } else {
|
52 | node.shorthand = false;
|
53 | }
|
54 | }
|
55 | }
|
56 |
|
57 | }
|
58 | };
|
59 | });
|
60 |
|
61 | exports.default = _default; |
\ | No newline at end of file |