版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

36 строки
1.0 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = optimiseCallExpression;
  6. var _t = require("@babel/types");
  7. const {
  8. callExpression,
  9. identifier,
  10. isIdentifier,
  11. isSpreadElement,
  12. memberExpression,
  13. optionalCallExpression,
  14. optionalMemberExpression
  15. } = _t;
  16. function optimiseCallExpression(callee, thisNode, args, optional) {
  17. if (args.length === 1 && isSpreadElement(args[0]) && isIdentifier(args[0].argument, {
  18. name: "arguments"
  19. })) {
  20. if (optional) {
  21. return optionalCallExpression(optionalMemberExpression(callee, identifier("apply"), false, true), [thisNode, args[0].argument], false);
  22. }
  23. return callExpression(memberExpression(callee, identifier("apply")), [thisNode, args[0].argument]);
  24. } else {
  25. if (optional) {
  26. return optionalCallExpression(optionalMemberExpression(callee, identifier("call"), false, true), [thisNode, ...args], false);
  27. }
  28. return callExpression(memberExpression(callee, identifier("call")), [thisNode, ...args]);
  29. }
  30. }