Skip to content

Commit

Permalink
fix(commonjs): handle requiring mixed ES modules
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Jul 31, 2020
1 parent ed024de commit 3364284
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/commonjs/src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,5 +691,5 @@ export function transformCommonjs(
code = magicString.toString();
const map = sourceMap ? magicString.generateMap() : null;

return { code, map, syntheticNamedExports: '__moduleExports' };
return { code, map, syntheticNamedExports: isEsModule ? false : '__moduleExports' };
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
description: 'transforms mixed modules',
pluginOptions: {
transformMixedEsModules: true
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const other = require('./other.js');

export { other };
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { other } from './dep.js';

const dep = require('./dep.js');

t.is(other, 'other');
t.deepEqual(dep, { other: 'other' });
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'other';
19 changes: 19 additions & 0 deletions packages/commonjs/test/snapshots/function.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -4142,6 +4142,25 @@ Generated by [AVA](https://ava.li).
`,
}

## transform-mixed-modules

> Snapshot 1
{
'main.js': `'use strict';␊
var other = 'other';␊
var dep = /*#__PURE__*/Object.freeze({␊
__proto__: null,␊
other: other␊
});␊
t.is(other, 'other');␊
t.deepEqual(dep, { other: 'other' });␊
`,
}

## transpiled-esm-default

> Snapshot 1
Expand Down
Binary file modified packages/commonjs/test/snapshots/function.js.snap
Binary file not shown.

0 comments on commit 3364284

Please sign in to comment.