Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Make unwrapExports only pick out default when it exists
Browse files Browse the repository at this point in the history
Issue #224
  • Loading branch information
marijnh committed Oct 7, 2017
1 parent 90e3a82 commit 4dae460
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions test/samples/use-own-output/from-rollup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Object.defineProperty(exports, '__esModule', { value: true });
exports.x = 10
2 changes: 2 additions & 0 deletions test/samples/use-own-output/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import * as b from "./from-rollup";
window.b = b;
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
});
});
});

0 comments on commit 4dae460

Please sign in to comment.