Skip to content

Commit

Permalink
chore: tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed Jul 1, 2018
1 parent 8d352f6 commit 5e3222a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// 1. find to ExportsModuleDeclaration(`Object.defineProperty(exports, "__esModule", {value: true});`)
// 2. find to ExportsAssignmentExpression(`exports.default`, `exports.foo` etc)
// 3. add `module.exports` if exists only `exports.default` assignment
// The above works after executing `preset-env`(transform-es2015-modules-*) in `Plugin.post`

module.exports = ({template, types}) => {
let pluginOptions
const visitor = {
const ExportsModuleDeclarationVisitor = {
CallExpression: {
exit (path) {
// Not `Object.defineProperty`, skip
if (!path.get('callee.object').node) {
return
}

if (isExportsModuleDeclaration(path)) {
const finder = new ExportFinder(path)

Expand All @@ -33,12 +33,17 @@ module.exports = ({template, types}) => {
}
},
post (fileMap) {
fileMap.path.traverse(visitor)
fileMap.path.traverse(ExportsModuleDeclarationVisitor)
}
}
}

function isExportsModuleDeclaration (path) {
// Not `Object.defineProperty`, skip
if (!path.get('callee.object').node) {
return false
}

const callee = `${path.get('callee.object.name').node}.${path.get('callee.property.name').node}`
const args = path.get('arguments').map(path => {
if (path.isStringLiteral()) {
Expand Down

0 comments on commit 5e3222a

Please sign in to comment.