1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = void 0;
|
---|
7 |
|
---|
8 | var _helperPluginUtils = require("@babel/helper-plugin-utils");
|
---|
9 |
|
---|
10 | var _pluginSyntaxExportNamespaceFrom = require("@babel/plugin-syntax-export-namespace-from");
|
---|
11 |
|
---|
12 | var _core = require("@babel/core");
|
---|
13 |
|
---|
14 | var _default = (0, _helperPluginUtils.declare)(api => {
|
---|
15 | api.assertVersion(7);
|
---|
16 | return {
|
---|
17 | name: "proposal-export-namespace-from",
|
---|
18 | inherits: _pluginSyntaxExportNamespaceFrom.default,
|
---|
19 | visitor: {
|
---|
20 | ExportNamedDeclaration(path) {
|
---|
21 | var _exported$name;
|
---|
22 |
|
---|
23 | const {
|
---|
24 | node,
|
---|
25 | scope
|
---|
26 | } = path;
|
---|
27 | const {
|
---|
28 | specifiers
|
---|
29 | } = node;
|
---|
30 | const index = _core.types.isExportDefaultSpecifier(specifiers[0]) ? 1 : 0;
|
---|
31 | if (!_core.types.isExportNamespaceSpecifier(specifiers[index])) return;
|
---|
32 | const nodes = [];
|
---|
33 |
|
---|
34 | if (index === 1) {
|
---|
35 | nodes.push(_core.types.exportNamedDeclaration(null, [specifiers.shift()], node.source));
|
---|
36 | }
|
---|
37 |
|
---|
38 | const specifier = specifiers.shift();
|
---|
39 | const {
|
---|
40 | exported
|
---|
41 | } = specifier;
|
---|
42 | const uid = scope.generateUidIdentifier((_exported$name = exported.name) != null ? _exported$name : exported.value);
|
---|
43 | 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)]));
|
---|
44 |
|
---|
45 | if (node.specifiers.length >= 1) {
|
---|
46 | nodes.push(node);
|
---|
47 | }
|
---|
48 |
|
---|
49 | const [importDeclaration] = path.replaceWithMultiple(nodes);
|
---|
50 | path.scope.registerDeclaration(importDeclaration);
|
---|
51 | }
|
---|
52 |
|
---|
53 | }
|
---|
54 | };
|
---|
55 | });
|
---|
56 |
|
---|
57 | exports.default = _default; |
---|