Skip to content

Commit

Permalink
Breaking change to follow the babel@5 behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed Nov 15, 2015
1 parent 679011d commit 88ddf7b
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,29 @@ module.exports = function () {
return
}

var code = `
module.exports = (function () {
const keys = Object.keys(exports)
return keys.length === 1 && keys[0] === 'default'
? Object.assign(exports.default, { default: exports.default })
: exports
}())
`
var hasExportDefault = false
var hasExportNamed = false
path.get('body').forEach(function (path) {
if (path.isExportDefaultDeclaration()) {
hasExportDefault = true
return
}
if (path.isExportNamedDeclaration()) {
hasExportNamed = true
return
}
})

var node = babelTemplate(code)()
if (hasExportDefault && !hasExportNamed) {
var topNodes = []
topNodes.push(babelTemplate("module.exports = exports['default']")())

path.pushContainer('body', topNodes)
}

path.pushContainer('body', [node])
path.BABEL_PLUGIN_ADD_MODULE_EXPORTS = true
}
}
}
}
}
}

0 comments on commit 88ddf7b

Please sign in to comment.