index.js
1.26 KB
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
'use strict';
module.exports = function (_ref) {
var types = _ref.types;
return {
visitor: {
Program: {
exit: function exit(path) {
if (path.BABEL_PLUGIN_ADD_MODULE_EXPORTS) {
return;
}
var hasExportDefault = false;
var hasExportNamed = false;
path.get('body').forEach(function (path) {
if (path.isExportDefaultDeclaration()) {
hasExportDefault = true;
return;
}
if (path.isExportNamedDeclaration()) {
if (path.node.specifiers.length === 1 && path.node.specifiers[0].exported.name === 'default') {
hasExportDefault = true;
} else {
hasExportNamed = true;
}
return;
}
});
if (hasExportDefault && !hasExportNamed) {
path.pushContainer('body', [types.expressionStatement(types.assignmentExpression('=', types.memberExpression(types.identifier('module'), types.identifier('exports')), types.memberExpression(types.identifier('exports'), types.stringLiteral('default'), true)))]);
}
path.BABEL_PLUGIN_ADD_MODULE_EXPORTS = true;
}
}
}
};
};
//# sourceMappingURL=index.js.map