You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.1 KiB

4 years ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _helperPluginUtils = require("@babel/helper-plugin-utils");
  7. var _helperFunctionName = _interopRequireDefault(require("@babel/helper-function-name"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. var _default = (0, _helperPluginUtils.declare)(api => {
  10. api.assertVersion(7);
  11. return {
  12. name: "transform-function-name",
  13. visitor: {
  14. FunctionExpression: {
  15. exit(path) {
  16. if (path.key !== "value" && !path.parentPath.isObjectProperty()) {
  17. const replacement = (0, _helperFunctionName.default)(path);
  18. if (replacement) path.replaceWith(replacement);
  19. }
  20. }
  21. },
  22. ObjectProperty(path) {
  23. const value = path.get("value");
  24. if (value.isFunction()) {
  25. const newNode = (0, _helperFunctionName.default)(value);
  26. if (newNode) value.replaceWith(newNode);
  27. }
  28. }
  29. }
  30. };
  31. });
  32. exports.default = _default;