| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = void 0;
|
|---|
| 7 | var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
|---|
| 8 | var _core = require("@babel/core");
|
|---|
| 9 | var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
|
|---|
| 10 | api.assertVersion(7);
|
|---|
| 11 | return {
|
|---|
| 12 | name: "transform-shorthand-properties",
|
|---|
| 13 | visitor: {
|
|---|
| 14 | ObjectMethod(path) {
|
|---|
| 15 | const {
|
|---|
| 16 | node
|
|---|
| 17 | } = path;
|
|---|
| 18 | if (node.kind === "method") {
|
|---|
| 19 | const func = _core.types.functionExpression(null, node.params, node.body, node.generator, node.async);
|
|---|
| 20 | func.returnType = node.returnType;
|
|---|
| 21 | const computedKey = _core.types.toComputedKey(node);
|
|---|
| 22 | if (_core.types.isStringLiteral(computedKey, {
|
|---|
| 23 | value: "__proto__"
|
|---|
| 24 | })) {
|
|---|
| 25 | path.replaceWith(_core.types.objectProperty(computedKey, func, true));
|
|---|
| 26 | } else {
|
|---|
| 27 | path.replaceWith(_core.types.objectProperty(node.key, func, node.computed));
|
|---|
| 28 | }
|
|---|
| 29 | }
|
|---|
| 30 | },
|
|---|
| 31 | ObjectProperty(path) {
|
|---|
| 32 | const {
|
|---|
| 33 | node
|
|---|
| 34 | } = path;
|
|---|
| 35 | if (node.shorthand) {
|
|---|
| 36 | const computedKey = _core.types.toComputedKey(node);
|
|---|
| 37 | if (_core.types.isStringLiteral(computedKey, {
|
|---|
| 38 | value: "__proto__"
|
|---|
| 39 | })) {
|
|---|
| 40 | path.replaceWith(_core.types.objectProperty(computedKey, node.value, true));
|
|---|
| 41 | } else {
|
|---|
| 42 | node.shorthand = false;
|
|---|
| 43 | }
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | };
|
|---|
| 48 | });
|
|---|
| 49 |
|
|---|
| 50 | //# sourceMappingURL=index.js.map
|
|---|