index.js 1.3 KB

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