Split exportExtensions into exportDefault and exportNamespace plugins… (#6920)
* Split exportExtensions into two plugins in babylon * rename proposal-export-default to proposal-export-default-from * rename proposal-export-namespace to proposal-export-namespace-from
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import syntaxExportDefaultFrom from "@babel/plugin-syntax-export-default-from";
|
||||
import { types as t } from "@babel/core";
|
||||
|
||||
export default function() {
|
||||
return {
|
||||
inherits: syntaxExportDefaultFrom,
|
||||
|
||||
visitor: {
|
||||
ExportNamedDeclaration(path) {
|
||||
const { node, scope } = path;
|
||||
const { specifiers } = node;
|
||||
if (!t.isExportDefaultSpecifier(specifiers[0])) return;
|
||||
|
||||
const specifier = specifiers.shift();
|
||||
const { exported } = specifier;
|
||||
const uid = scope.generateUidIdentifier(exported.name);
|
||||
|
||||
const nodes = [
|
||||
t.importDeclaration([t.importDefaultSpecifier(uid)], node.source),
|
||||
t.exportNamedDeclaration(null, [t.exportSpecifier(uid, exported)]),
|
||||
];
|
||||
|
||||
if (specifiers.length >= 1) {
|
||||
nodes.push(node);
|
||||
}
|
||||
|
||||
path.replaceWithMultiple(nodes);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user