index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*istanbul ignore next*/"use strict";
  2. exports.__esModule = true;
  3. exports.default = function ( /*istanbul ignore next*/_ref) {
  4. /*istanbul ignore next*/var t = _ref.types;
  5. function build(node, nodes, scope) {
  6. var first = node.specifiers[0];
  7. if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return;
  8. var specifier = node.specifiers.shift();
  9. var uid = scope.generateUidIdentifier(specifier.exported.name);
  10. var newSpecifier = /*istanbul ignore next*/void 0;
  11. if (t.isExportNamespaceSpecifier(specifier)) {
  12. newSpecifier = t.importNamespaceSpecifier(uid);
  13. } else {
  14. newSpecifier = t.importDefaultSpecifier(uid);
  15. }
  16. nodes.push(t.importDeclaration([newSpecifier], node.source));
  17. nodes.push(t.exportNamedDeclaration(null, [t.exportSpecifier(uid, specifier.exported)]));
  18. build(node, nodes, scope);
  19. }
  20. return {
  21. inherits: require("babel-plugin-syntax-export-extensions"),
  22. visitor: { /*istanbul ignore next*/
  23. ExportNamedDeclaration: function ExportNamedDeclaration(path) {
  24. /*istanbul ignore next*/var node = path.node;
  25. /*istanbul ignore next*/var scope = path.scope;
  26. var nodes = [];
  27. build(node, nodes, scope);
  28. if (!nodes.length) return;
  29. if (node.specifiers.length >= 1) {
  30. nodes.push(node);
  31. }
  32. path.replaceWithMultiple(nodes);
  33. }
  34. }
  35. };
  36. };
  37. /*istanbul ignore next*/module.exports = exports["default"];