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

Commit

Permalink
Merge pull request #80 from rollup/deep-cjs
Browse files Browse the repository at this point in the history
Deconflict export and local module
  • Loading branch information
TrySound committed Jul 22, 2016
2 parents b48f7d7 + 3f0fd60 commit a7b98c3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,13 @@ export default function commonjs ( options = {} ) {

outro += Object.keys( namedExports )
.filter( key => !blacklistedExports[ key ] )
.map( x => `export var ${x} = ${name}.${x};` )
.map( x => {
if (x === name) {
return `var ${x}$$1 = ${name}.${x};\nexport { ${x}$$1 as ${x} };`;
} else {
return `export var ${x} = ${name}.${x};`;
}
})
.join( '\n' );

magicString.trim()
Expand Down
14 changes: 14 additions & 0 deletions test/samples/deconflict-export-and-local/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.someValue = undefined;

var _someValue2 = require('./someValue');

var _someValue3 = _interopRequireDefault(_someValue2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.someValue = _someValue3.default;
3 changes: 3 additions & 0 deletions test/samples/deconflict-export-and-local/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { someValue } from './index.js';

assert.equal(someValue, 10);
10 changes: 10 additions & 0 deletions test/samples/deconflict-export-and-local/someValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.someValue = undefined;

var someValue = exports.someValue = 10;

exports.default = someValue;
7 changes: 7 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,11 @@ describe( 'rollup-plugin-commonjs', () => {
.then( executeBundle)
.catch(error => assert.ok(/reexport\.js does not export named/.test(error.message)));
});

it( 'deconflict export name and local variable', () => {
return rollup({
entry: 'samples/deconflict-export-and-local/main.js',
plugins: [ commonjs() ]
}).then( executeBundle );
});
});

0 comments on commit a7b98c3

Please sign in to comment.