UNPKG

1.29 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4
5exports.default = function (_ref) {
6 var t = _ref.types;
7
8 function build(node, nodes, scope) {
9 var first = node.specifiers[0];
10 if (!t.isExportNamespaceSpecifier(first) && !t.isExportDefaultSpecifier(first)) return;
11
12 var specifier = node.specifiers.shift();
13 var uid = scope.generateUidIdentifier(specifier.exported.name);
14
15 var newSpecifier = void 0;
16 if (t.isExportNamespaceSpecifier(specifier)) {
17 newSpecifier = t.importNamespaceSpecifier(uid);
18 } else {
19 newSpecifier = t.importDefaultSpecifier(uid);
20 }
21
22 nodes.push(t.importDeclaration([newSpecifier], node.source));
23 nodes.push(t.exportNamedDeclaration(null, [t.exportSpecifier(uid, specifier.exported)]));
24
25 build(node, nodes, scope);
26 }
27
28 return {
29 inherits: require("babel-plugin-syntax-export-extensions"),
30
31 visitor: {
32 ExportNamedDeclaration: function ExportNamedDeclaration(path) {
33 var node = path.node,
34 scope = path.scope;
35
36 var nodes = [];
37 build(node, nodes, scope);
38 if (!nodes.length) return;
39
40 if (node.specifiers.length >= 1) {
41 nodes.push(node);
42 }
43 path.replaceWithMultiple(nodes);
44 }
45 }
46 };
47};
48
49module.exports = exports["default"];
\No newline at end of file