mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 09:55:15 +00:00
26 lines
913 B
JavaScript
26 lines
913 B
JavaScript
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.default = optimiseCallExpression;
|
|
|
|
var t = require("@babel/types");
|
|
|
|
function optimiseCallExpression(callee, thisNode, args, optional) {
|
|
if (args.length === 1 && t.isSpreadElement(args[0]) && t.isIdentifier(args[0].argument, {
|
|
name: "arguments"
|
|
})) {
|
|
if (optional) {
|
|
return t.optionalCallExpression(t.optionalMemberExpression(callee, t.identifier("apply"), false, true), [thisNode, args[0].argument], false);
|
|
}
|
|
|
|
return t.callExpression(t.memberExpression(callee, t.identifier("apply")), [thisNode, args[0].argument]);
|
|
} else {
|
|
if (optional) {
|
|
return t.optionalCallExpression(t.optionalMemberExpression(callee, t.identifier("call"), false, true), [thisNode, ...args], false);
|
|
}
|
|
|
|
return t.callExpression(t.memberExpression(callee, t.identifier("call")), [thisNode, ...args]);
|
|
}
|
|
} |