forked from babel/babel
/
index.ts
34 lines (30 loc) 路 823 Bytes
/
index.ts
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
import { declare } from "@babel/helper-plugin-utils";
import { types as t } from "@babel/core";
export default declare(api => {
api.assertVersion(7);
return {
name: "transform-jscript",
visitor: {
FunctionExpression: {
exit(path) {
const { node } = path;
if (!node.id) return;
path.replaceWith(
t.callExpression(
t.functionExpression(
null,
[],
t.blockStatement([
// @ts-expect-error t.toStatement must return a FunctionDeclaration if node.id is defined
t.toStatement(node),
t.returnStatement(t.cloneNode(node.id)),
]),
),
[],
),
);
},
},
},
};
});