index.js 1.1 KB

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