index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. Object.defineProperty(exports, "convertFunctionParams", {
  6. enumerable: true,
  7. get: function () {
  8. return _params.default;
  9. }
  10. });
  11. exports.default = void 0;
  12. var _helperPluginUtils = require("@babel/helper-plugin-utils");
  13. var _params = require("./params");
  14. var _rest = require("./rest");
  15. var _default = (0, _helperPluginUtils.declare)((api, options) => {
  16. var _api$assumption, _api$assumption2;
  17. api.assertVersion(7);
  18. const ignoreFunctionLength = (_api$assumption = api.assumption("ignoreFunctionLength")) != null ? _api$assumption : options.loose;
  19. const noNewArrows = (_api$assumption2 = api.assumption("noNewArrows")) != null ? _api$assumption2 : true;
  20. return {
  21. name: "transform-parameters",
  22. visitor: {
  23. Function(path) {
  24. if (path.isArrowFunctionExpression() && path.get("params").some(param => param.isRestElement() || param.isAssignmentPattern())) {
  25. path.arrowFunctionToExpression({
  26. noNewArrows
  27. });
  28. if (!path.isFunctionExpression()) return;
  29. }
  30. const convertedRest = (0, _rest.default)(path);
  31. const convertedParams = (0, _params.default)(path, ignoreFunctionLength);
  32. if (convertedRest || convertedParams) {
  33. path.scope.crawl();
  34. }
  35. }
  36. }
  37. };
  38. });
  39. exports.default = _default;
  40. //# sourceMappingURL=index.js.map