Skip to content

Commit 5e3222a

Browse files
committed
chore: tweaks
1 parent 8d352f6 commit 5e3222a

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

src/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
// 1. find to ExportsModuleDeclaration(`Object.defineProperty(exports, "__esModule", {value: true});`)
2+
// 2. find to ExportsAssignmentExpression(`exports.default`, `exports.foo` etc)
3+
// 3. add `module.exports` if exists only `exports.default` assignment
4+
// The above works after executing `preset-env`(transform-es2015-modules-*) in `Plugin.post`
5+
16
module.exports = ({template, types}) => {
27
let pluginOptions
3-
const visitor = {
8+
const ExportsModuleDeclarationVisitor = {
49
CallExpression: {
510
exit (path) {
6-
// Not `Object.defineProperty`, skip
7-
if (!path.get('callee.object').node) {
8-
return
9-
}
10-
1111
if (isExportsModuleDeclaration(path)) {
1212
const finder = new ExportFinder(path)
1313

@@ -33,12 +33,17 @@ module.exports = ({template, types}) => {
3333
}
3434
},
3535
post (fileMap) {
36-
fileMap.path.traverse(visitor)
36+
fileMap.path.traverse(ExportsModuleDeclarationVisitor)
3737
}
3838
}
3939
}
4040

4141
function isExportsModuleDeclaration (path) {
42+
// Not `Object.defineProperty`, skip
43+
if (!path.get('callee.object').node) {
44+
return false
45+
}
46+
4247
const callee = `${path.get('callee.object.name').node}.${path.get('callee.property.name').node}`
4348
const args = path.get('arguments').map(path => {
4449
if (path.isStringLiteral()) {

0 commit comments

Comments
 (0)