1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports["default"] = replaceShorthandObjectMethod;
|
5 | var util = _interopRequireWildcard(require("./util"));
|
6 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
7 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | function replaceShorthandObjectMethod(path) {
|
44 | var t = util.getTypes();
|
45 | if (!path.node || !t.isFunction(path.node)) {
|
46 | throw new Error("replaceShorthandObjectMethod can only be called on Function AST node paths.");
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 | if (!t.isObjectMethod(path.node)) {
|
52 | return path;
|
53 | }
|
54 |
|
55 |
|
56 | if (!path.node.generator) {
|
57 | return path;
|
58 | }
|
59 | var parameters = path.node.params.map(function (param) {
|
60 | return t.cloneDeep(param);
|
61 | });
|
62 | var functionExpression = t.functionExpression(null,
|
63 |
|
64 | parameters,
|
65 |
|
66 | t.cloneDeep(path.node.body),
|
67 |
|
68 | path.node.generator, path.node.async);
|
69 | util.replaceWithOrRemove(path, t.objectProperty(t.cloneDeep(path.node.key),
|
70 |
|
71 | functionExpression,
|
72 |
|
73 | path.node.computed,
|
74 |
|
75 | false
|
76 | ));
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | return path.get("value");
|
83 | } |
\ | No newline at end of file |