2023-12-18 13:12:25 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
2024-01-16 21:26:16 +08:00
|
|
|
exports.default = optimiseCallExpression;
|
|
|
|
var _t = require("@babel/types");
|
|
|
|
const {
|
|
|
|
callExpression,
|
|
|
|
identifier,
|
|
|
|
isIdentifier,
|
|
|
|
isSpreadElement,
|
|
|
|
memberExpression,
|
|
|
|
optionalCallExpression,
|
|
|
|
optionalMemberExpression
|
|
|
|
} = _t;
|
|
|
|
function optimiseCallExpression(callee, thisNode, args, optional) {
|
|
|
|
if (args.length === 1 && isSpreadElement(args[0]) && isIdentifier(args[0].argument, {
|
2023-12-18 13:12:25 +08:00
|
|
|
name: "arguments"
|
|
|
|
})) {
|
2024-01-16 21:26:16 +08:00
|
|
|
if (optional) {
|
|
|
|
return optionalCallExpression(optionalMemberExpression(callee, identifier("apply"), false, true), [thisNode, args[0].argument], false);
|
|
|
|
}
|
|
|
|
return callExpression(memberExpression(callee, identifier("apply")), [thisNode, args[0].argument]);
|
2023-12-18 13:12:25 +08:00
|
|
|
} else {
|
2024-01-16 21:26:16 +08:00
|
|
|
if (optional) {
|
|
|
|
return optionalCallExpression(optionalMemberExpression(callee, identifier("call"), false, true), [thisNode, ...args], false);
|
|
|
|
}
|
|
|
|
return callExpression(memberExpression(callee, identifier("call")), [thisNode, ...args]);
|
2023-12-18 13:12:25 +08:00
|
|
|
}
|
2024-01-16 21:26:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//# sourceMappingURL=index.js.map
|