Last change
on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 |
|
---|
8 | var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
---|
9 |
|
---|
10 | var _core = require("@babel/core");
|
---|
11 |
|
---|
12 | var _default = (0, _helperPluginUtils.declare)(api => {
|
---|
13 | api.assertVersion(7);
|
---|
14 |
|
---|
15 | function statementList(key, path) {
|
---|
16 | const paths = path.get(key);
|
---|
17 |
|
---|
18 | for (const path of paths) {
|
---|
19 | const func = path.node;
|
---|
20 | if (!path.isFunctionDeclaration()) continue;
|
---|
21 |
|
---|
22 | const declar = _core.types.variableDeclaration("let", [_core.types.variableDeclarator(func.id, _core.types.toExpression(func))]);
|
---|
23 |
|
---|
24 | declar._blockHoist = 2;
|
---|
25 | func.id = null;
|
---|
26 | path.replaceWith(declar);
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | return {
|
---|
31 | name: "transform-block-scoped-functions",
|
---|
32 | visitor: {
|
---|
33 | BlockStatement(path) {
|
---|
34 | const {
|
---|
35 | node,
|
---|
36 | parent
|
---|
37 | } = path;
|
---|
38 |
|
---|
39 | if (_core.types.isFunction(parent, {
|
---|
40 | body: node
|
---|
41 | }) || _core.types.isExportDeclaration(parent)) {
|
---|
42 | return;
|
---|
43 | }
|
---|
44 |
|
---|
45 | statementList("body", path);
|
---|
46 | },
|
---|
47 |
|
---|
48 | SwitchCase(path) {
|
---|
49 | statementList("consequent", path);
|
---|
50 | }
|
---|
51 |
|
---|
52 | }
|
---|
53 | };
|
---|
54 | });
|
---|
55 |
|
---|
56 | exports.default = _default; |
---|
Note:
See
TracBrowser
for help on using the repository browser.