index.js 958 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 = require("@babel/helper-function-name");
  8. var _default = (0, _helperPluginUtils.declare)(api => {
  9. api.assertVersion(7);
  10. return {
  11. name: "transform-function-name",
  12. visitor: {
  13. FunctionExpression: {
  14. exit(path) {
  15. if (path.key !== "value" && !path.parentPath.isObjectProperty()) {
  16. const replacement = (0, _helperFunctionName.default)(path);
  17. if (replacement) path.replaceWith(replacement);
  18. }
  19. }
  20. },
  21. ObjectProperty(path) {
  22. const value = path.get("value");
  23. if (value.isFunction()) {
  24. const newNode = (0, _helperFunctionName.default)(value);
  25. if (newNode) value.replaceWith(newNode);
  26. }
  27. }
  28. }
  29. };
  30. });
  31. exports.default = _default;