Last change
on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = optimiseCallExpression;
|
---|
7 |
|
---|
8 | var _t = require("@babel/types");
|
---|
9 |
|
---|
10 | const {
|
---|
11 | callExpression,
|
---|
12 | identifier,
|
---|
13 | isIdentifier,
|
---|
14 | isSpreadElement,
|
---|
15 | memberExpression,
|
---|
16 | optionalCallExpression,
|
---|
17 | optionalMemberExpression
|
---|
18 | } = _t;
|
---|
19 |
|
---|
20 | function optimiseCallExpression(callee, thisNode, args, optional) {
|
---|
21 | if (args.length === 1 && isSpreadElement(args[0]) && isIdentifier(args[0].argument, {
|
---|
22 | name: "arguments"
|
---|
23 | })) {
|
---|
24 | if (optional) {
|
---|
25 | return optionalCallExpression(optionalMemberExpression(callee, identifier("apply"), false, true), [thisNode, args[0].argument], false);
|
---|
26 | }
|
---|
27 |
|
---|
28 | return callExpression(memberExpression(callee, identifier("apply")), [thisNode, args[0].argument]);
|
---|
29 | } else {
|
---|
30 | if (optional) {
|
---|
31 | return optionalCallExpression(optionalMemberExpression(callee, identifier("call"), false, true), [thisNode, ...args], false);
|
---|
32 | }
|
---|
33 |
|
---|
34 | return callExpression(memberExpression(callee, identifier("call")), [thisNode, ...args]);
|
---|
35 | }
|
---|
36 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.