index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. return {
  11. name: "transform-export-namespace-from",
  12. manipulateOptions: (_, parser) => parser.plugins.push("exportNamespaceFrom"),
  13. visitor: {
  14. ExportNamedDeclaration(path) {
  15. var _exported$name;
  16. const {
  17. node,
  18. scope
  19. } = path;
  20. const {
  21. specifiers
  22. } = node;
  23. const index = _core.types.isExportDefaultSpecifier(specifiers[0]) ? 1 : 0;
  24. if (!_core.types.isExportNamespaceSpecifier(specifiers[index])) return;
  25. const nodes = [];
  26. if (index === 1) {
  27. nodes.push(_core.types.exportNamedDeclaration(null, [specifiers.shift()], node.source));
  28. }
  29. const specifier = specifiers.shift();
  30. const {
  31. exported
  32. } = specifier;
  33. const uid = scope.generateUidIdentifier((_exported$name = exported.name) != null ? _exported$name : exported.value);
  34. 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)]));
  35. if (node.specifiers.length >= 1) {
  36. nodes.push(node);
  37. }
  38. const [importDeclaration] = path.replaceWithMultiple(nodes);
  39. path.scope.registerDeclaration(importDeclaration);
  40. }
  41. }
  42. };
  43. });
  44. //# sourceMappingURL=index.js.map