-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
index.js
40 lines (34 loc) 路 1.11 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { declare } from "@babel/helper-plugin-utils";
import convertFunctionParams from "./params";
import convertFunctionRest from "./rest";
export { convertFunctionParams };
export default declare((api, options) => {
api.assertVersion(7);
const ignoreFunctionLength =
api.assumption("ignoreFunctionLength") ?? options.loose;
return {
name: "transform-parameters",
visitor: {
Function(path) {
if (
path.isArrowFunctionExpression() &&
path
.get("params")
.some(param => param.isRestElement() || param.isAssignmentPattern())
) {
// default/rest visitors require access to `arguments`, so it cannot be an arrow
path.arrowFunctionToExpression();
}
const convertedRest = convertFunctionRest(path);
const convertedParams = convertFunctionParams(
path,
ignoreFunctionLength,
);
if (convertedRest || convertedParams) {
// Manually reprocess this scope to ensure that the moved params are updated.
path.scope.crawl();
}
},
},
};
});