12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- "use strict";
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
- exports.__esModule = true;
- exports["default"] = replaceShorthandObjectMethod;
- var util = _interopRequireWildcard(require("./util"));
- function replaceShorthandObjectMethod(path) {
- var t = util.getTypes();
- if (!path.node || !t.isFunction(path.node)) {
- throw new Error("replaceShorthandObjectMethod can only be called on Function AST node paths.");
- }
-
- if (!t.isObjectMethod(path.node)) {
- return path;
- }
- if (!path.node.generator) {
- return path;
- }
- var parameters = path.node.params.map(function (param) {
- return t.cloneDeep(param);
- });
- var functionExpression = t.functionExpression(null,
- parameters,
- t.cloneDeep(path.node.body),
- path.node.generator, path.node.async);
- util.replaceWithOrRemove(path, t.objectProperty(t.cloneDeep(path.node.key),
- functionExpression,
- path.node.computed,
- false
- ));
-
-
-
- return path.get("value");
- }
|