UNPKG

1.22 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7var _helperPluginUtils = require("@babel/helper-plugin-utils");
8var _core = require("@babel/core");
9var _default = (0, _helperPluginUtils.declare)(api => {
10 api.assertVersion(7);
11 function transformStatementList(paths) {
12 for (const path of paths) {
13 if (!path.isFunctionDeclaration()) continue;
14 const func = path.node;
15 const declar = _core.types.variableDeclaration("let", [_core.types.variableDeclarator(func.id, _core.types.toExpression(func))]);
16 declar._blockHoist = 2;
17 func.id = null;
18 path.replaceWith(declar);
19 }
20 }
21 return {
22 name: "transform-block-scoped-functions",
23 visitor: {
24 BlockStatement(path) {
25 const {
26 node,
27 parent
28 } = path;
29 if (_core.types.isFunction(parent, {
30 body: node
31 }) || _core.types.isExportDeclaration(parent)) {
32 return;
33 }
34 transformStatementList(path.get("body"));
35 },
36 SwitchCase(path) {
37 transformStatementList(path.get("consequent"));
38 }
39 }
40 };
41});
42exports.default = _default;
43
44//# sourceMappingURL=index.js.map