index.js 1.3 KB

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