1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.pushAccessor = pushAccessor;
|
7 | exports.toDefineObject = toDefineObject;
|
8 | var _core = require("@babel/core");
|
9 | function pushAccessor(mutatorMap, node) {
|
10 | var _mutatorMap$alias;
|
11 | const alias = _core.types.toKeyAlias(node);
|
12 | const map = (_mutatorMap$alias = mutatorMap[alias]) != null ? _mutatorMap$alias : mutatorMap[alias] = {
|
13 | _inherits: [],
|
14 | _key: node.key
|
15 | };
|
16 | map._inherits.push(node);
|
17 | const value = _core.types.functionExpression(null, node.params, node.body, node.generator, node.async);
|
18 | value.returnType = node.returnType;
|
19 | _core.types.inheritsComments(value, node);
|
20 | map[node.kind] = value;
|
21 | return map;
|
22 | }
|
23 | function toDefineObject(mutatorMap) {
|
24 | const objExpr = _core.types.objectExpression([]);
|
25 | Object.keys(mutatorMap).forEach(function (mutatorMapKey) {
|
26 | const map = mutatorMap[mutatorMapKey];
|
27 | map.configurable = _core.types.booleanLiteral(true);
|
28 | map.enumerable = _core.types.booleanLiteral(true);
|
29 | const mapNode = _core.types.objectExpression([]);
|
30 | const propNode = _core.types.objectProperty(map._key, mapNode, map._computed);
|
31 | Object.keys(map).forEach(function (key) {
|
32 | const node = map[key];
|
33 | if (key[0] === "_") return;
|
34 | const prop = _core.types.objectProperty(_core.types.identifier(key), node);
|
35 | _core.types.inheritsComments(prop, node);
|
36 | _core.types.removeComments(node);
|
37 | mapNode.properties.push(prop);
|
38 | });
|
39 | objExpr.properties.push(propNode);
|
40 | });
|
41 | return objExpr;
|
42 | }
|
43 |
|
44 |
|