1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 | var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
---|
8 | var _core = require("@babel/core");
|
---|
9 | var _default = exports.default = (0, _helperPluginUtils.declare)(api => {
|
---|
10 | api.assertVersion(7);
|
---|
11 | return {
|
---|
12 | name: "transform-export-namespace-from",
|
---|
13 | manipulateOptions: (_, parser) => parser.plugins.push("exportNamespaceFrom"),
|
---|
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 |
|
---|
46 | //# sourceMappingURL=index.js.map
|
---|