"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "packages/babel-helper-optimise-call-expression/src/index.js" between
babel-7.12.6.tar.gz and babel-7.12.7.tar.gz

About: Babel is a JavaScript compiler that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript. Hint: There exists a high-performance language interoperability tool also named "Babel".

index.js  (babel-7.12.6):index.js  (babel-7.12.7)
import * as t from "@babel/types"; import * as t from "@babel/types";
export default function (callee, thisNode, args, optional) { /**
* A helper function that generates a new call expression with given thisNode.
It will also optimize `(...arguments)` to `.apply(arguments)`
*
* @export
* @param {Node} callee The callee of call expression
* @param {Node} thisNode The desired this of call expression
* @param {Node[]} args The arguments of call expression
* @param {boolean} optional Whether the call expression is optional
* @returns {CallExpression | OptionalCallExpression} The generated new call exp
ression
*/
export default function (
callee: Node,
thisNode: Node,
args: Node[],
optional: boolean,
): CallExpression | OptionalCallExpression {
if ( if (
args.length === 1 && args.length === 1 &&
t.isSpreadElement(args[0]) && t.isSpreadElement(args[0]) &&
t.isIdentifier(args[0].argument, { name: "arguments" }) t.isIdentifier(args[0].argument, { name: "arguments" })
) { ) {
// eg. super(...arguments); // a.b?.(...arguments);
if (optional) {
return t.optionalCallExpression(
t.optionalMemberExpression(callee, t.identifier("apply"), false, true),
[thisNode, args[0].argument],
false,
);
}
// a.b(...arguments);
return t.callExpression(t.memberExpression(callee, t.identifier("apply")), [ return t.callExpression(t.memberExpression(callee, t.identifier("apply")), [
thisNode, thisNode,
args[0].argument, args[0].argument,
]); ]);
} else { } else {
// a.b?.(arg1, arg2)
if (optional) { if (optional) {
return t.optionalCallExpression( return t.optionalCallExpression(
t.optionalMemberExpression(callee, t.identifier("call"), false, true), t.optionalMemberExpression(callee, t.identifier("call"), false, true),
[thisNode, ...args], [thisNode, ...args],
false, false,
); );
} }
// a.b(arg1, arg2)
return t.callExpression(t.memberExpression(callee, t.identifier("call")), [ return t.callExpression(t.memberExpression(callee, t.identifier("call")), [
thisNode, thisNode,
...args, ...args,
]); ]);
} }
} }
 End of changes. 4 change blocks. 
2 lines changed or deleted 29 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)