-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
/
index.ts
43 lines (35 loc) 路 1.09 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { declare } from "@babel/helper-plugin-utils";
import syntaxExportDefaultFrom from "@babel/plugin-syntax-export-default-from";
import { types as t } from "@babel/core";
export default declare(api => {
api.assertVersion(7);
return {
name: "proposal-export-default-from",
inherits: syntaxExportDefaultFrom,
visitor: {
ExportNamedDeclaration(path) {
const { node } = path;
const { specifiers, source } = node;
if (!t.isExportDefaultSpecifier(specifiers[0])) return;
const { exported } = specifiers.shift();
if (specifiers.every(s => t.isExportSpecifier(s))) {
specifiers.unshift(
t.exportSpecifier(t.identifier("default"), exported),
);
return;
}
const nodes = [
t.exportNamedDeclaration(
null,
[t.exportSpecifier(t.identifier("default"), exported)],
t.cloneNode(source),
),
];
if (specifiers.length >= 1) {
nodes.push(node);
}
path.replaceWithMultiple(nodes);
},
},
};
});