diff --git a/src/helpers.js b/src/helpers.js index cb62211..7748cd8 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -8,7 +8,7 @@ export function commonjsRequire () { } export function unwrapExports (x) { - return x && x.__esModule ? x['default'] : x; + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; } export function createCommonjsModule(fn, module) { diff --git a/test/samples/use-own-output/from-rollup.js b/test/samples/use-own-output/from-rollup.js new file mode 100644 index 0000000..3a0bcda --- /dev/null +++ b/test/samples/use-own-output/from-rollup.js @@ -0,0 +1,2 @@ +Object.defineProperty(exports, '__esModule', { value: true }); +exports.x = 10 diff --git a/test/samples/use-own-output/main.js b/test/samples/use-own-output/main.js new file mode 100644 index 0000000..c011220 --- /dev/null +++ b/test/samples/use-own-output/main.js @@ -0,0 +1,2 @@ +import * as b from "./from-rollup"; +window.b = b; diff --git a/test/test.js b/test/test.js index 074c357..cb581f4 100644 --- a/test/test.js +++ b/test/test.js @@ -420,5 +420,17 @@ describe( 'rollup-plugin-commonjs', () => { assert.notEqual( code.indexOf( 'var validVar' ), -1 ); assert.notEqual( code.indexOf( 'var nonIndex' ), -1 ); }); + + it( 'does not misassign default when consuming rollup output', async () => { + // Issue #224 + const bundle = await rollup({ + entry: 'samples/use-own-output/main.js', + plugins: [ commonjs() ], + }); + + const window = {}; + await executeBundle( bundle, { context: { window } } ); + assert.notEqual( window.b.default, undefined ); + }); }); });