my-idlers/node_modules/@babel/helper-optimise-call-expression/lib/index.js
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

36 lines
1.0 KiB
JavaScript
Vendored

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
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, {
name: "arguments"
})) {
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]);
} else {
if (optional) {
return optionalCallExpression(optionalMemberExpression(callee, identifier("call"), false, true), [thisNode, ...args], false);
}
return callExpression(memberExpression(callee, identifier("call")), [thisNode, ...args]);
}
}