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

Make unwrapExports only pick out default when it exists #226

Merged
merged 1 commit into from
Oct 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
});
});
});