index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 _pluginSyntaxExportNamespaceFrom = require("@babel/plugin-syntax-export-namespace-from");
  8. var _core = require("@babel/core");
  9. var _default = (0, _helperPluginUtils.declare)(api => {
  10. api.assertVersion(7);
  11. return {
  12. name: "proposal-export-namespace-from",
  13. inherits: _pluginSyntaxExportNamespaceFrom.default,
  14. visitor: {
  15. ExportNamedDeclaration(path) {
  16. var _exported$name;
  17. const {
  18. node,
  19. scope
  20. } = path;
  21. const {
  22. specifiers
  23. } = node;
  24. const index = _core.types.isExportDefaultSpecifier(specifiers[0]) ? 1 : 0;
  25. if (!_core.types.isExportNamespaceSpecifier(specifiers[index])) return;
  26. const nodes = [];
  27. if (index === 1) {
  28. nodes.push(_core.types.exportNamedDeclaration(null, [specifiers.shift()], node.source));
  29. }
  30. const specifier = specifiers.shift();
  31. const {
  32. exported
  33. } = specifier;
  34. const uid = scope.generateUidIdentifier((_exported$name = exported.name) != null ? _exported$name : exported.value);
  35. nodes.push(_core.types.importDeclaration([_core.types.importNamespaceSpecifier(uid)], _core.types.cloneNode(node.source)), _core.types.exportNamedDeclaration(null, [_core.types.exportSpecifier(_core.types.cloneNode(uid), exported)]));
  36. if (node.specifiers.length >= 1) {
  37. nodes.push(node);
  38. }
  39. const [importDeclaration] = path.replaceWithMultiple(nodes);
  40. path.scope.registerDeclaration(importDeclaration);
  41. }
  42. }
  43. };
  44. });
  45. exports.default = _default;