Add __esModule property to exports object

Fixes: #442
This commit is contained in:
Timothy Gu 2018-07-22 09:51:06 -07:00
parent c01a5d22d4
commit 6868e4aa59
2 changed files with 14 additions and 0 deletions

View File

@ -29,6 +29,19 @@ module.exports = ({ types: t }) => ({
)
)
),
t.expressionStatement(
t.callExpression(
t.memberExpression(
t.identifier('Object'), t.identifier('defineProperty')),
[
t.identifier('exports'),
t.stringLiteral('__esModule'),
t.objectExpression([
t.objectProperty(t.identifier('value'), t.booleanLiteral(true))
])
]
)
),
t.expressionStatement(
t.assignmentExpression('=',
expr.node.left, t.identifier('exports')

View File

@ -7,6 +7,7 @@ export default function tweakDefault() {
var matches = /^(exports(?:\['default']|\.default)) = (.*);$/.exec(line);
if (matches) {
lines[i] = 'module.exports = exports = ' + matches[2] + ';\n' +
'Object.defineProperty(exports, "__esModule", { value: true });\n' +
matches[1] + ' = exports;';
break;
}