index.js 913 B

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