forked from babel/babel
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
33 lines (27 loc) · 1.07 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
import { declare } from "@babel/helper-plugin-utils";
import type NodePath from "@babel/traverse";
export default declare((api, options) => {
api.assertVersion(7);
const newableArrowFunctions =
api.assumption("newableArrowFunctions") ?? !options.spec;
return {
name: "transform-arrow-functions",
visitor: {
ArrowFunctionExpression(
path: NodePath<BabelNodeArrowFunctionExpression>,
) {
// In some conversion cases, it may have already been converted to a function while this callback
// was queued up.
if (!path.isArrowFunctionExpression()) return;
path.arrowFunctionToExpression({
// While other utils may be fine inserting other arrows to make more transforms possible,
// the arrow transform itself absolutely cannot insert new arrow functions.
allowInsertArrow: false,
newableArrowFunctions,
// TODO(Babel 8): This is only needed for backward compat with @babel/traverse <7.13.0
specCompliant: !newableArrowFunctions,
});
},
},
};
});